VeraCrypt
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMounir IDRASSI <mounir.idrassi@idrix.fr>2014-07-14 17:20:32 +0200
committerMounir IDRASSI <mounir.idrassi@idrix.fr>2014-11-08 23:21:16 +0100
commitba733dd032a44eb38653abe922fc6905413bcac4 (patch)
treef7173f5b947eb656c7bf1dee22c3ee291968fece
parent016edc150b034d7401a1652bd3482d613ff4b9d4 (diff)
downloadVeraCrypt-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.
-rw-r--r--src/Common/Registry.c33
-rw-r--r--src/Common/Registry.h3
2 files changed, 31 insertions, 5 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 @@
8 8
9#include "Tcdefs.h" 9#include "Tcdefs.h"
10#include "Registry.h" 10#include "Registry.h"
11#include <Strsafe.h>
11 12
12BOOL ReadLocalMachineRegistryDword (char *subKey, char *name, DWORD *value) 13BOOL ReadLocalMachineRegistryDword (char *subKey, char *name, DWORD *value)
13{ 14{
@@ -105,13 +106,13 @@ char *ReadRegistryString (char *subKey, char *name, char *defaultValue, char *st
105 DWORD size = sizeof (value); 106 DWORD size = sizeof (value);
106 107
107 str[maxLen-1] = 0; 108 str[maxLen-1] = 0;
108 strncpy (str, defaultValue, maxLen-1); 109 StringCbCopyA (str, maxLen, defaultValue);
109 110
110 ZeroMemory (value, sizeof value); 111 ZeroMemory (value, sizeof value);
111 if (RegOpenKeyEx (HKEY_CURRENT_USER, subKey, 112 if (RegOpenKeyEx (HKEY_CURRENT_USER, subKey,
112 0, KEY_READ, &hkey) == ERROR_SUCCESS) 113 0, KEY_READ, &hkey) == ERROR_SUCCESS)
113 if (RegQueryValueEx (hkey, name, 0, 0, (LPBYTE) value, &size) == ERROR_SUCCESS) 114 if (RegQueryValueEx (hkey, name, 0, 0, (LPBYTE) value, &size) == ERROR_SUCCESS)
114 strncpy (str, value, maxLen-1); 115 StringCbCopyA (str, maxLen,value);
115 116
116 RegCloseKey (hkey); 117 RegCloseKey (hkey);
117 return str; 118 return str;
@@ -169,6 +170,30 @@ BOOL WriteLocalMachineRegistryDword (char *subKey, char *name, DWORD value)
169 return TRUE; 170 return TRUE;
170} 171}
171 172
173BOOL WriteLocalMachineRegistryDwordW (WCHAR *subKey, WCHAR *name, DWORD value)
174{
175 HKEY hkey = 0;
176 DWORD disp;
177 LONG status;
178
179 if ((status = RegCreateKeyExW (HKEY_LOCAL_MACHINE, subKey,
180 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &disp)) != ERROR_SUCCESS)
181 {
182 SetLastError (status);
183 return FALSE;
184 }
185
186 if ((status = RegSetValueExW (hkey, name, 0, REG_DWORD, (BYTE *) &value, sizeof value)) != ERROR_SUCCESS)
187 {
188 RegCloseKey (hkey);
189 SetLastError (status);
190 return FALSE;
191 }
192
193 RegCloseKey (hkey);
194 return TRUE;
195}
196
172BOOL WriteLocalMachineRegistryMultiString (char *subKey, char *name, char *multiString, DWORD size) 197BOOL WriteLocalMachineRegistryMultiString (char *subKey, char *name, char *multiString, DWORD size)
173{ 198{
174 HKEY hkey = 0; 199 HKEY hkey = 0;
@@ -279,9 +304,9 @@ void DeleteRegistryValue (char *subKey, char *name)
279} 304}
280 305
281 306
282void GetStartupRegKeyName (char *regk) 307void GetStartupRegKeyName (char *regk, size_t cbRegk)
283{ 308{
284 // The string is split in order to prevent some antivirus packages from falsely reporting 309 // The string is split in order to prevent some antivirus packages from falsely reporting
285 // TrueCrypt.exe to contain a possible Trojan horse because of this string (heuristic scan). 310 // TrueCrypt.exe to contain a possible Trojan horse because of this string (heuristic scan).
286 sprintf (regk, "%s%s", "Software\\Microsoft\\Windows\\Curren", "tVersion\\Run"); 311 StringCbPrintfA (regk, cbRegk,"%s%s", "Software\\Microsoft\\Windows\\Curren", "tVersion\\Run");
287} 312}
diff --git a/src/Common/Registry.h b/src/Common/Registry.h
index a0e2e732..693ddc0e 100644
--- a/src/Common/Registry.h
+++ b/src/Common/Registry.h
@@ -19,13 +19,14 @@ char *ReadRegistryString (char *subKey, char *name, char *defaultValue, char *st
19DWORD ReadRegistryBytes (char *path, char *name, char *value, int maxLen); 19DWORD ReadRegistryBytes (char *path, char *name, char *value, int maxLen);
20void WriteRegistryInt (char *subKey, char *name, int value); 20void WriteRegistryInt (char *subKey, char *name, int value);
21BOOL WriteLocalMachineRegistryDword (char *subKey, char *name, DWORD value); 21BOOL WriteLocalMachineRegistryDword (char *subKey, char *name, DWORD value);
22BOOL WriteLocalMachineRegistryDwordW (WCHAR *subKey, WCHAR *name, DWORD value);
22BOOL WriteLocalMachineRegistryMultiString (char *subKey, char *name, char *multiString, DWORD size); 23BOOL WriteLocalMachineRegistryMultiString (char *subKey, char *name, char *multiString, DWORD size);
23BOOL WriteLocalMachineRegistryString (char *subKey, char *name, char *str, BOOL expandable); 24BOOL WriteLocalMachineRegistryString (char *subKey, char *name, char *str, BOOL expandable);
24void WriteRegistryString (char *subKey, char *name, char *str); 25void WriteRegistryString (char *subKey, char *name, char *str);
25BOOL WriteRegistryBytes (char *path, char *name, char *str, DWORD size); 26BOOL WriteRegistryBytes (char *path, char *name, char *str, DWORD size);
26BOOL DeleteLocalMachineRegistryKey (char *parentKey, char *subKeyToDelete); 27BOOL DeleteLocalMachineRegistryKey (char *parentKey, char *subKeyToDelete);
27void DeleteRegistryValue (char *subKey, char *name); 28void DeleteRegistryValue (char *subKey, char *name);
28void GetStartupRegKeyName (char *regk); 29void GetStartupRegKeyName (char *regk, size_t cbRegk);
29 30
30#ifdef __cplusplus 31#ifdef __cplusplus
31} 32}