| |

VerySource

 Forgot password?
 Register
Search
View: 1114|Reply: 7

Oh my god, how big a loophole is in my program, just changing the position changes the value. How far do I need to go to

[Copy link]

2

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-7 17:40:01
| Show all posts |Read mode
void CDlgReportPreview :: GetPrinterPara (TCHAR * szDevice, TCHAR szDriver, TCHAR * szOutput)
{
HKEY hOpenKey1, hOpenKey2;
long lResult = 0;
DWORD dwKeyValueType = 0;
DWORD dwKeyValueLength = 0;
Ranch
LPCTSTR keyName2 = L "Printers\\Ports";
// Changed the position of keyName2 used below, its value is not Printersuo1Ports
CString str;
str.Format (_T ("Driver"));
LPCWSTR lpSubKey = TEXT ("Printers");

LPCTSTR dwKeyName2 = TEXT ("Port5");

CString keyName1 (L "Printers\\");
// LPTSTR keyName1 = L "Printers\\"; if so, the second time it is passed in, it will add the value of szDevice;
TCHAR strKeyValue [500];
Ranch
CComboBox * pCmbReg = (CComboBox *) GetDlgItem (IDC_COMBO_PRINTER);
UpdateData (TRUE);
CString strText;
LPCTSTR lpctText;
pCmbReg-> GetWindowText (strText);
lpctText = (LPCTSTR) strText;
wsprintf (szDevice, lpctText);
Ranch
keyName1 + = lpctText;
// wcscat (keyName1, lpctText);
lResult = RegOpenKeyEx (HKEY_LOCAL_MACHINE, keyName1,0,0,&hOpenKey1);
ASSERT (lResult == ERROR_SUCCESS);

// read szDevice, szDriver and szOutput value
ZeroMemory (strKeyValue, sizeof (TCHAR) * 50);
dwKeyValueLength = sizeof (TCHAR) * 50;

lResult = RegQueryValueEx (hOpenKey1, str, 0,&dwKeyValueType,
(BYTE *) strKeyValue,&dwKeyValueLength);
ASSERT (lResult == ERROR_SUCCESS);

wsprintf (szDriver, strKeyValue);
RegCloseKey (hOpenKey1);

// LPCTSTR keyName2 = L "Printers\\Ports"; The value it returns is not what I want.
lResult = RegOpenKeyEx (HKEY_LOCAL_MACHINE, keyName2,0,0,&hOpenKey2);
ASSERT (lResult == ERROR_SUCCESS);


ZeroMemory (strKeyValue, sizeof (TCHAR) * 500);
lResult = RegQueryValueEx (hOpenKey2, dwKeyName2,0,&dwKeyValueType,
(BYTE *) strKeyValue,&dwKeyValueLength);
ASSERT (lResult == ERROR_SUCCESS);

wsprintf (szOutput, strKeyValue);
RegCloseKey (hOpenKey2);
}
Reply

Use magic Report

0

Threads

4

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-1-7 23:27:01
| Show all posts
Did not understand the meaning of the landlord
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-30 17:15:01
| Show all posts
Did not understand
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-30 17:30:01
| Show all posts
CString keyName1(L "Printers\\");
// LPTSTR keyName1 = L "Printers\\"; If so, the value of szDevice will be added when it is passed in the second time;
This is because there is a problem with the conversion between ASCII and UNICODE.
It seems that CString still does not support UNICODE, the keyName1(L "Printers\\"); you wrote should be invalid.
Reply

Use magic Report

0

Threads

5

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-8-30 17:45:01
| Show all posts
Character problem?
Reply

Use magic Report

0

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-8-30 18:00:01
| Show all posts
If variables are accidentally modified, most of the problem is memory overflow, such as whether your wsprintf will cause overflow. In addition, the use of your string is very confusing, obviously you have not understood the meaning of various types.
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-30 18:15:01
| Show all posts
Memory usage may be problematic
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-8-30 18:30:01
| Show all posts
Up.....
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list