]> granicus.if.org Git - sudo/commitdiff
Don't try to fflush(export_fp) or ferror(export_fp) if export_fp
authorTodd C. Miller <Todd.Miller@courtesan.com>
Mon, 16 May 2016 20:16:08 +0000 (14:16 -0600)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Mon, 16 May 2016 20:16:08 +0000 (14:16 -0600)
is NULL, which can happen on the error path.

plugins/sudoers/visudo_json.c

index ad34aa5333ff1086d04ad69383c23fc3a2ab59a6..3f8118602a4039bdd96f1395d91e19c627ba8039 100644 (file)
@@ -1062,10 +1062,12 @@ export_sudoers(const char *sudoers_path, const char *export_path,
     fputs("\n}\n", export_fp);
 
 done:
-    (void)fflush(export_fp);
-    if (ferror(export_fp))
-       rval = false;
-    if (export_fp != stdout && export_fp != NULL)
-       fclose(export_fp);
+    if (export_fp != NULL) {
+       (void)fflush(export_fp);
+       if (ferror(export_fp))
+           rval = false;
+       if (export_fp != stdout)
+           fclose(export_fp);
+    }
     debug_return_bool(rval);
 }