]> asedeno.scripts.mit.edu Git - PuTTY.git/commitdiff
When checking for an existing log, store the FILE * in a local variable.
authorBen Harris <bjh21@bjh21.me.uk>
Sat, 17 Oct 2015 11:12:23 +0000 (12:12 +0100)
committerBen Harris <bjh21@bjh21.me.uk>
Sat, 24 Oct 2015 21:45:48 +0000 (22:45 +0100)
It's not used outside logfopen, and leaving an infalid file pointer
lying around in the log context caused a segfault if the user
cancelled logging.

Bug found by afl-fuzz before it had even started fuzzing.

logging.c

index 954721b922912d22f764fc1e16a77e9c101c5849..a40d32a6e28fdb82d9387e6216014840624df98c 100644 (file)
--- a/logging.c
+++ b/logging.c
@@ -164,6 +164,7 @@ void logfopen(void *handle)
 {
     struct LogContext *ctx = (struct LogContext *)handle;
     struct tm tm;
+    FILE *fp;
     int mode;
 
     /* Prevent repeat calls */
@@ -183,10 +184,10 @@ void logfopen(void *handle)
                    conf_get_str(ctx->conf, CONF_host),
                    conf_get_int(ctx->conf, CONF_port), &tm);
 
-    ctx->lgfp = f_open(ctx->currlogfilename, "r", FALSE);  /* file already present? */
-    if (ctx->lgfp) {
+    fp = f_open(ctx->currlogfilename, "r", FALSE);  /* file already present? */
+    if (fp) {
        int logxfovr = conf_get_int(ctx->conf, CONF_logxfovr);
-       fclose(ctx->lgfp);
+       fclose(fp);
        if (logxfovr != LGXF_ASK) {
            mode = ((logxfovr == LGXF_OVR) ? 2 : 1);
        } else