X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=blobdiff_plain;f=windows%2Fwinstore.c;h=b1058832e99a11da3e48d44216a555da809aca07;hb=a063e522970946bf7d5dc052079d7773c0dee76d;hp=47fef678cdc126fe77abaca6c3cca2e9ddd6e722;hpb=b99bec3b02d79c6902f50cfa616eebaee43536f6;p=PuTTY.git diff --git a/windows/winstore.c b/windows/winstore.c index 47fef678..b1058832 100644 --- a/windows/winstore.c +++ b/windows/winstore.c @@ -6,6 +6,7 @@ #include #include #include +#include #include "putty.h" #include "storage.h" @@ -152,7 +153,7 @@ void *open_settings_r(const char *sessionname) char *read_setting_s(void *handle, const char *key) { - DWORD type, size; + DWORD type, allocsize, size; char *ret; if (!handle) @@ -164,13 +165,17 @@ char *read_setting_s(void *handle, const char *key) type != REG_SZ) return NULL; - ret = snewn(size+1, char); + allocsize = size+1; /* allow for an extra NUL if needed */ + ret = snewn(allocsize, char); if (RegQueryValueEx((HKEY) handle, key, 0, &type, ret, &size) != ERROR_SUCCESS || type != REG_SZ) { sfree(ret); return NULL; } + assert(size < allocsize); + ret[size] = '\0'; /* add an extra NUL in case RegQueryValueEx + * didn't supply one */ return ret; } @@ -749,7 +754,7 @@ static int transform_jumplist_registry /* * Either return or free the result. */ - if (out) + if (out && ret == ERROR_SUCCESS) *out = old_value; else sfree(old_value); @@ -782,7 +787,7 @@ char *get_jumplist_registry_entries (void) { char *list_value; - if (transform_jumplist_registry(NULL,NULL,&list_value) != ERROR_SUCCESS) { + if (transform_jumplist_registry(NULL,NULL,&list_value) != JUMPLISTREG_OK) { list_value = snewn(2, char); *list_value = '\0'; *(list_value + 1) = '\0';