diff options
author | Mounir IDRASSI <mounir.idrassi@idrix.fr> | 2014-07-14 17:20:32 +0200 |
---|---|---|
committer | Mounir IDRASSI <mounir.idrassi@idrix.fr> | 2014-11-08 23:21:16 +0100 |
commit | ba733dd032a44eb38653abe922fc6905413bcac4 (patch) | |
tree | f7173f5b947eb656c7bf1dee22c3ee291968fece /src/Common/Registry.c | |
parent | 016edc150b034d7401a1652bd3482d613ff4b9d4 (diff) | |
download | VeraCrypt-ba733dd032a44eb38653abe922fc6905413bcac4.tar.gz VeraCrypt-ba733dd032a44eb38653abe922fc6905413bcac4.zip |
Use Safe String functions in Registry.c and add a unicode version of WriteLocalMachineRegistryDword function to avoid doing conversions when used.
Diffstat (limited to 'src/Common/Registry.c')
-rw-r--r-- | src/Common/Registry.c | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/src/Common/Registry.c b/src/Common/Registry.c index c7496471..a68e5f18 100644 --- a/src/Common/Registry.c +++ b/src/Common/Registry.c @@ -8,6 +8,7 @@ #include "Tcdefs.h"
#include "Registry.h"
+#include <Strsafe.h>
BOOL ReadLocalMachineRegistryDword (char *subKey, char *name, DWORD *value)
{
@@ -105,13 +106,13 @@ char *ReadRegistryString (char *subKey, char *name, char *defaultValue, char *st DWORD size = sizeof (value);
str[maxLen-1] = 0;
- strncpy (str, defaultValue, maxLen-1);
+ StringCbCopyA (str, maxLen, defaultValue);
ZeroMemory (value, sizeof value);
if (RegOpenKeyEx (HKEY_CURRENT_USER, subKey,
0, KEY_READ, &hkey) == ERROR_SUCCESS)
if (RegQueryValueEx (hkey, name, 0, 0, (LPBYTE) value, &size) == ERROR_SUCCESS)
- strncpy (str, value, maxLen-1);
+ StringCbCopyA (str, maxLen,value);
RegCloseKey (hkey);
return str;
@@ -169,6 +170,30 @@ BOOL WriteLocalMachineRegistryDword (char *subKey, char *name, DWORD value) return TRUE;
}
+BOOL WriteLocalMachineRegistryDwordW (WCHAR *subKey, WCHAR *name, DWORD value)
+{
+ HKEY hkey = 0;
+ DWORD disp;
+ LONG status;
+
+ if ((status = RegCreateKeyExW (HKEY_LOCAL_MACHINE, subKey,
+ 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &disp)) != ERROR_SUCCESS)
+ {
+ SetLastError (status);
+ return FALSE;
+ }
+
+ if ((status = RegSetValueExW (hkey, name, 0, REG_DWORD, (BYTE *) &value, sizeof value)) != ERROR_SUCCESS)
+ {
+ RegCloseKey (hkey);
+ SetLastError (status);
+ return FALSE;
+ }
+
+ RegCloseKey (hkey);
+ return TRUE;
+}
+
BOOL WriteLocalMachineRegistryMultiString (char *subKey, char *name, char *multiString, DWORD size)
{
HKEY hkey = 0;
@@ -279,9 +304,9 @@ void DeleteRegistryValue (char *subKey, char *name) }
-void GetStartupRegKeyName (char *regk)
+void GetStartupRegKeyName (char *regk, size_t cbRegk)
{
// The string is split in order to prevent some antivirus packages from falsely reporting
// TrueCrypt.exe to contain a possible Trojan horse because of this string (heuristic scan).
- sprintf (regk, "%s%s", "Software\\Microsoft\\Windows\\Curren", "tVersion\\Run");
+ StringCbPrintfA (regk, cbRegk,"%s%s", "Software\\Microsoft\\Windows\\Curren", "tVersion\\Run");
}
|