]> granicus.if.org Git - sudo/commitdiff
sudo_edit() must return a wait status but if there is an error, or
authorTodd C. Miller <Todd.Miller@courtesan.com>
Mon, 5 Jun 2017 13:11:09 +0000 (07:11 -0600)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Mon, 5 Jun 2017 13:11:09 +0000 (07:11 -0600)
even if no changes were made to the file, it was returning 1 instead
which would be interpreted as the command having received SIGHUP.
Use the W_EXITCODE() to construct a proper wait status in the error
case too.

src/sudo_edit.c

index 449f05dcd02c43706226c0b5bee30e3a6bb9775e..fb7ec759056f29e1ad6411cb4ff8413391e07c96 100644 (file)
@@ -932,7 +932,8 @@ selinux_edit_copy_tfiles(struct command_details *command_details,
 
 /*
  * Wrapper to allow users to edit privileged files with their own uid.
- * Returns 0 on success and 1 on failure.
+ * Returns the wait status of the command on success and a wait status
+ * of 1 on failure.
  */
 int
 sudo_edit(struct command_details *command_details)
@@ -1046,12 +1047,14 @@ sudo_edit(struct command_details *command_details)
     else
 #endif
        errors = sudo_edit_copy_tfiles(command_details, tf, nfiles, times);
+    if (errors)
+       goto cleanup;
 
     for (i = 0; i < nfiles; i++)
        free(tf[i].tfile);
     free(tf);
     free(nargv);
-    debug_return_int(errors ? 1 : rc);
+    debug_return_int(rc);
 
 cleanup:
     /* Clean up temp files and return. */
@@ -1063,7 +1066,7 @@ cleanup:
     }
     free(tf);
     free(nargv);
-    debug_return_int(1);
+    debug_return_int(W_EXITCODE(1, 0));
 }
 
 #else /* HAVE_SETRESUID || HAVE_SETREUID || HAVE_SETEUID */
@@ -1075,7 +1078,7 @@ int
 sudo_edit(struct command_details *command_details)
 {
     debug_decl(sudo_edit, SUDO_DEBUG_EDIT)
-    debug_return_int(1);
+    debug_return_int(W_EXITCODE(1, 0));
 }
 
 #endif /* HAVE_SETRESUID || HAVE_SETREUID || HAVE_SETEUID */