#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
+#include <assert.h>
#include "putty.h"
#include "storage.h"
char *read_setting_s(void *handle, const char *key)
{
- DWORD type, size;
+ DWORD type, allocsize, size;
char *ret;
if (!handle)
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;
}
return 0; /* key matched OK in registry */
}
+int have_ssh_host_key(const char *hostname, int port,
+ const char *keytype)
+{
+ /*
+ * If we have a host key, verify_host_key will return 0 or 2.
+ * If we don't have one, it'll return 1.
+ */
+ return verify_host_key(hostname, port, keytype, "") != 1;
+}
+
void store_host_key(const char *hostname, int port,
const char *keytype, const char *key)
{
int ret;
HKEY pjumplist_key, psettings_tmp;
DWORD type;
- int value_length;
+ DWORD value_length;
char *old_value, *new_value;
char *piterator_old, *piterator_new, *piterator_tmp;
/*
* Either return or free the result.
*/
- if (out)
+ if (out && ret == ERROR_SUCCESS)
*out = old_value;
else
sfree(old_value);
{
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';