From 9072bab11b70abd9e33dc8c029d25cd796542bf4 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Sun, 7 Oct 2018 14:04:26 +0100 Subject: [PATCH] Unix: fix segfault if ~/.putty/sessions doesn't exist. Looks as if I introduced this in commit 733fcca2c, where the pointer returned from enum_settings_start() stopped being the same thing as the underlying 'DIR *' - I needed to retain a check for the outer containing structure not being NULL but the DIR * being NULL inside it. --- unix/uxstore.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/unix/uxstore.c b/unix/uxstore.c index 84d8d4d6..de1680f4 100644 --- a/unix/uxstore.c +++ b/unix/uxstore.c @@ -562,6 +562,9 @@ char *enum_settings_next(settings_e *handle, char *buffer, int buflen) int maxlen, thislen, len; char *unmunged; + if (!handle->dp) + return NULL; + fullpath = make_filename(INDEX_SESSIONDIR, NULL); maxlen = len = strlen(fullpath); @@ -592,7 +595,8 @@ char *enum_settings_next(settings_e *handle, char *buffer, int buflen) void enum_settings_finish(settings_e *handle) { - closedir(handle->dp); + if (handle->dp) + closedir(handle->dp); sfree(handle); }