From c1f5f956448a2bd052e71ee1a57f48d9327f2741 Mon Sep 17 00:00:00 2001 From: simon Date: Tue, 9 Feb 1999 15:39:08 +0000 Subject: [PATCH] Fix various segfaults and heap trashes. Thanks to Andrew Mobbs. git-svn-id: svn://svn.tartarus.org/sgt/putty@29 cda61777-01e9-0310-a592-d414129be87e --- noise.c | 4 ++-- ssh.c | 4 ++-- windlg.c | 2 -- window.c | 3 ++- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/noise.c b/noise.c index cf9bba57..3ff00be6 100644 --- a/noise.c +++ b/noise.c @@ -73,7 +73,7 @@ void noise_get_heavy(void (*func) (void *, int)) { FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); - if (seedf) { + if (seedf != INVALID_HANDLE_VALUE) { while (1) { char buf[1024]; DWORD len; @@ -96,7 +96,7 @@ void random_save_seed(void) { seedf = CreateFile(seedpath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); - if (seedf) { + if (seedf != INVALID_HANDLE_VALUE) { int len; DWORD lenwritten; void *data; diff --git a/ssh.c b/ssh.c index 3fae152e..633453d6 100644 --- a/ssh.c +++ b/ssh.c @@ -174,8 +174,8 @@ static void s_wrpkt_start(int type, int len) { pktout.length = len-5; if (pktout.maxlen < biglen) { pktout.maxlen = biglen; - pktout.data = (pktout.data == NULL ? malloc(biglen) : - realloc(pktout.data, biglen)); + pktout.data = (pktout.data == NULL ? malloc(biglen+4) : + realloc(pktout.data, biglen+4)); if (!pktout.data) fatalbox("Out of memory"); } diff --git a/windlg.c b/windlg.c index 6fe11bb5..d15ebb24 100644 --- a/windlg.c +++ b/windlg.c @@ -116,7 +116,6 @@ static void save_settings (char *section, int do_host) { if (RegCreateKey(HKEY_CURRENT_USER, puttystr, &subkey1)!=ERROR_SUCCESS || RegCreateKey(subkey1, p, &sesskey) != ERROR_SUCCESS) { - free(p); sesskey = NULL; } @@ -221,7 +220,6 @@ static void load_settings (char *section, int do_host) { if (RegOpenKey(HKEY_CURRENT_USER, puttystr, &subkey1) != ERROR_SUCCESS || RegOpenKey(subkey1, p, &sesskey) != ERROR_SUCCESS) { - free(p); sesskey = NULL; } diff --git a/window.c b/window.c index 3cd719ae..456f1ef5 100644 --- a/window.c +++ b/window.c @@ -1347,7 +1347,8 @@ void set_sbar (int total, int start, int page) { si.nMax = total - 1; si.nPage = page; si.nPos = start; - SetScrollInfo (hwnd, SB_VERT, &si, TRUE); + if (hwnd) + SetScrollInfo (hwnd, SB_VERT, &si, TRUE); } Context get_ctx() { -- 2.11.0