]> git.ipfire.org Git - thirdparty/krb5.git/commitdiff
Fix errno hygiene in kadmind write_pid_file
authorGreg Hudson <ghudson@mit.edu>
Fri, 29 Mar 2013 06:22:12 +0000 (02:22 -0400)
committerGreg Hudson <ghudson@mit.edu>
Fri, 29 Mar 2013 06:22:12 +0000 (02:22 -0400)
fclose() might overwrite the errno value from fprintf, causing us to
return success when we shouldn't.  Record the errno value at the time
of the fprintf failure.

src/kadmin/server/ovsec_kadmd.c

index a1fee7e3aad6b6fc26939f060c092acc3e3826fd..dad7248696a071e84a805734ddb9592c5f851e6f 100644 (file)
@@ -194,9 +194,9 @@ write_pid_file(const char *pid_file)
     if (file == NULL)
         return errno;
     pid = (unsigned long) getpid();
-    st1 = fprintf(file, "%ld\n", pid);
-    st2 = fclose(file);
-    return (st1 < 0 || st2 == EOF) ? errno : 0;
+    st1 = (fprintf(file, "%ld\n", pid) < 0) ? errno : 0;
+    st2 = (fclose(file) == EOF) ? errno : 0;
+    return st1 ? st1 : st2;
 }
 
 /* XXX yuck.  the signal handlers need this */