Remove use of setjmp/longjmp in the sudoers plugin. We no longer
authorTodd C. Miller <Todd.Miller@courtesan.com>
Thu, 26 Jun 2014 21:51:15 +0000 (15:51 -0600)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Thu, 26 Jun 2014 21:51:15 +0000 (15:51 -0600)
call fatal() except in the malloc wrappers and due to libsudo_util
there is now a single copy of fatal/fatalx.

include/fatal.h
lib/util/fatal.c
lib/util/util.exp
plugins/sudoers/iolog.c
plugins/sudoers/policy.c
plugins/sudoers/sudoers.c

index ac7a9d380955c62a708d5a39d69725706ecc2db8..f51da499b7ee7ef877488e9f7970ccac0cfebd73 100644 (file)
@@ -18,7 +18,6 @@
 #define        _SUDO_FATAL_H_
 
 #include <stdarg.h>
-#include <setjmp.h>
 
 /*
  * We wrap fatal/fatalx and warning/warningx so that the same output can
 } while (0)
 #endif /* SUDO_ERROR_WRAP */
 
-#define fatal_setjmp()         (fatal_enable_setjmp(), sigsetjmp(fatal_jmp, 1))
-#define fatal_longjmp(val)     siglongjmp(fatal_jmp, val)
-
 extern int (*sudo_printf)(int msg_type, const char *fmt, ...);
-extern sigjmp_buf fatal_jmp;
 
 __dso_public int  fatal_callback_deregister(void (*func)(void));
 __dso_public int  fatal_callback_register(void (*func)(void));
 __dso_public char *warning_gettext(const char *msgid) __format_arg(1);
-__dso_public void fatal_disable_setjmp(void);
-__dso_public void fatal_enable_setjmp(void);
 __dso_public void fatal_nodebug(const char *, ...) __printf0like(1, 2) __attribute__((__noreturn__));
 __dso_public void fatalx_nodebug(const char *, ...) __printflike(1, 2) __attribute__((__noreturn__));
 __dso_public void vfatal_nodebug(const char *, va_list ap) __printf0like(1, 0) __attribute__((__noreturn__));
index 8da8b21566fb8dfd27b3bdbf823d40d480130ffd..1d355e74993103ce93f1050a62d0bcd960db0bb2 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2004-2005, 2010-2013 Todd C. Miller <Todd.Miller@courtesan.com>
+ * Copyright (c) 2004-2005, 2010-2014 Todd C. Miller <Todd.Miller@courtesan.com>
  *
  * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
@@ -43,8 +43,6 @@ struct sudo_fatal_callback {
 };
 SLIST_HEAD(sudo_fatal_callback_list, sudo_fatal_callback);
 
-__dso_public sigjmp_buf fatal_jmp;
-static bool setjmp_enabled = false;
 static struct sudo_fatal_callback_list callbacks;
 
 static void _warning(int, const char *, va_list);
@@ -71,10 +69,7 @@ fatal_nodebug(const char *fmt, ...)
     _warning(1, fmt, ap);
     va_end(ap);
     do_cleanup();
-    if (setjmp_enabled)
-       siglongjmp(fatal_jmp, 1);
-    else
-       exit(EXIT_FAILURE);
+    exit(EXIT_FAILURE);
 }
 
 void
@@ -86,10 +81,7 @@ fatalx_nodebug(const char *fmt, ...)
     _warning(0, fmt, ap);
     va_end(ap);
     do_cleanup();
-    if (setjmp_enabled)
-       siglongjmp(fatal_jmp, 1);
-    else
-       exit(EXIT_FAILURE);
+    exit(EXIT_FAILURE);
 }
 
 void
@@ -97,10 +89,7 @@ vfatal_nodebug(const char *fmt, va_list ap)
 {
     _warning(1, fmt, ap);
     do_cleanup();
-    if (setjmp_enabled)
-       siglongjmp(fatal_jmp, 1);
-    else
-       exit(EXIT_FAILURE);
+    exit(EXIT_FAILURE);
 }
 
 void
@@ -108,10 +97,7 @@ vfatalx_nodebug(const char *fmt, va_list ap)
 {
     _warning(0, fmt, ap);
     do_cleanup();
-    if (setjmp_enabled)
-       siglongjmp(fatal_jmp, 1);
-    else
-       exit(EXIT_FAILURE);
+    exit(EXIT_FAILURE);
 }
 
 void
@@ -214,15 +200,3 @@ fatal_callback_deregister(void (*func)(void))
 
     return -1;
 }
-
-void
-fatal_disable_setjmp(void)
-{
-    setjmp_enabled = false;
-}
-
-void
-fatal_enable_setjmp(void)
-{
-    setjmp_enabled = true;
-}
index 7f0786f00b37beea67fef13f3cbb11f20e41a324..981e5d84858fc37f3ffd43681777616f4170b6ed 100644 (file)
@@ -38,9 +38,6 @@ estrndup
 evasprintf
 fatal_callback_deregister
 fatal_callback_register
-fatal_disable_setjmp
-fatal_enable_setjmp
-fatal_jmp
 fatal_nodebug
 fatalx_nodebug
 fmt_string
index 50370644feeb6c2cb305e5ba54b277ffa42f4e9b..18200d96cfe85e75edbb5d48c0a4a51c0af461a0 100644 (file)
@@ -584,12 +584,6 @@ sudoers_io_open(unsigned int version, sudo_conv_t conversation,
 
     memset(&details, 0, sizeof(details));
 
-    if (fatal_setjmp() != 0) {
-       /* called via fatal() or fatalx() */
-       rval = -1;
-       goto done;
-    }
-
     bindtextdomain("sudoers", LOCALEDIR);
 
     sudo_setpwent();
@@ -663,7 +657,6 @@ sudoers_io_open(unsigned int version, sudo_conv_t conversation,
     rval = true;
 
 done:
-    fatal_disable_setjmp();
     efree(tofree);
     if (details.runas_pw)
        sudo_pw_delref(details.runas_pw);
@@ -681,12 +674,6 @@ sudoers_io_close(int exit_status, int error)
     int i;
     debug_decl(sudoers_io_close, SUDO_DEBUG_PLUGIN)
 
-    if (fatal_setjmp() != 0) {
-       /* called via fatal() or fatalx() */
-       fatal_disable_setjmp();
-       debug_return;
-    }
-
     for (i = 0; i < IOFD_MAX; i++) {
        if (io_log_files[i].fd.v == NULL)
            continue;
@@ -705,12 +692,6 @@ sudoers_io_version(int verbose)
 {
     debug_decl(sudoers_io_version, SUDO_DEBUG_PLUGIN)
 
-    if (fatal_setjmp() != 0) {
-       /* called via fatal() or fatalx() */
-       fatal_disable_setjmp();
-       debug_return_bool(-1);
-    }
-
     sudo_printf(SUDO_CONV_INFO_MSG, "Sudoers I/O plugin version %s\n",
        PACKAGE_VERSION);
 
@@ -728,12 +709,6 @@ sudoers_io_log(const char *buf, unsigned int len, int idx)
 
     gettimeofday(&now, NULL);
 
-    if (fatal_setjmp() != 0) {
-       /* called via fatal() or fatalx() */
-       fatal_disable_setjmp();
-       debug_return_bool(-1);
-    }
-
 #ifdef HAVE_ZLIB_H
     if (iolog_compress)
        ignore_result(gzwrite(io_log_files[idx].fd.g, (const voidp)buf, len));
index 73f7fa50eed834423335acb979a5564afd081bf2..a9aed9e91487575a43a63acb726f637acfc199ce 100644 (file)
@@ -541,13 +541,6 @@ sudoers_policy_open(unsigned int version, sudo_conv_t conversation,
     if (sudo_version < SUDO_API_MKVERSION(1, 2))
        args = NULL;
 
-    if (fatal_setjmp() != 0) {
-       /* called via fatal() or fatalx() */
-       (void) rewind_perms();
-       fatal_disable_setjmp();
-       debug_return_bool(-1);
-    }
-
     /* Call the sudoers init function. */
     info.settings = settings;
     info.user_info = user_info;
@@ -560,12 +553,6 @@ sudoers_policy_close(int exit_status, int error_code)
 {
     debug_decl(sudoers_policy_close, SUDO_DEBUG_PLUGIN)
 
-    if (fatal_setjmp() != 0) {
-       /* called via fatal() or fatalx() */
-       fatal_disable_setjmp();
-       debug_return;
-    }
-
     /* We do not currently log the exit status. */
     if (error_code) {
        errno = error_code;
@@ -613,12 +600,6 @@ sudoers_policy_init_session(struct passwd *pwd, char **user_env[])
     if (sudo_version < SUDO_API_MKVERSION(1, 2))
        user_env = NULL;
 
-    if (fatal_setjmp() != 0) {
-       /* called via fatal() or fatalx() */
-       fatal_disable_setjmp();
-       debug_return_bool(-1);
-    }
-
     debug_return_bool(sudo_auth_begin_session(pwd, user_env));
 }
 
@@ -664,11 +645,8 @@ sudoers_policy_invalidate(int remove)
     debug_decl(sudoers_policy_invalidate, SUDO_DEBUG_PLUGIN)
 
     user_cmnd = "kill";
-    if (fatal_setjmp() == 0) {
-       remove_timestamp(remove);
-       sudoers_cleanup();
-    }
-    fatal_disable_setjmp();
+    remove_timestamp(remove);
+    sudoers_cleanup();
 
     debug_return;
 }
@@ -708,12 +686,6 @@ sudoers_policy_version(int verbose)
 {
     debug_decl(sudoers_policy_version, SUDO_DEBUG_PLUGIN)
 
-    if (fatal_setjmp() != 0) {
-       /* error recovery via fatal() or fatalx() */
-       fatal_disable_setjmp();
-       debug_return_bool(-1);
-    }
-
     sudo_printf(SUDO_CONV_INFO_MSG, _("Sudoers policy plugin version %s\n"),
        PACKAGE_VERSION);
     sudo_printf(SUDO_CONV_INFO_MSG, _("Sudoers file grammar version %d\n"),
index 94f74ee21f72a48df6ef8a481b5da1fd5cbbe900..f2086824cfb67522135bc41ee6a6e4a6f5904b33 100644 (file)
@@ -228,13 +228,6 @@ sudoers_policy_main(int argc, char * const argv[], int pwflag, char *env_add[],
     volatile int rval = true;
     debug_decl(sudoers_policy_main, SUDO_DEBUG_PLUGIN)
 
-    /* XXX - would like to move this to policy.c but need the cleanup. */
-    if (fatal_setjmp() != 0) {
-       /* error recovery via fatal() or fatalx() */
-       rval = -1;
-       goto done;
-    }
-
     /* Is root even allowed to run sudo? */
     if (user_uid == 0 && !def_root_sudo) {
        /* Not an audit event. */
@@ -548,7 +541,6 @@ bad:
     rval = false;
 
 done:
-    fatal_disable_setjmp();
     if (!rewind_perms())
        rval = -1;