# HG changeset patch
# Parent  4e0af3ef53d71d1e0d1ee5894a0c078020ab391a
Add sudoedit flag checks in plugin that are consistent with front-end.
Don't assume the sudo front-end is sending reasonable mode flags.
These checks need to be kept consistent between the sudo front-end
and the sudoers plugin.

--- a/plugins/sudoers/policy.c
+++ b/plugins/sudoers/policy.c
@@ -87,10 +87,11 @@ parse_bool(const char *line, int varlen,
 int
 sudoers_policy_deserialize_info(void *v, char **runas_user, char **runas_group)
 {
+    const int edit_mask = MODE_EDIT|MODE_IGNORE_TICKET|MODE_NONINTERACTIVE;
     struct sudoers_open_info *info = v;
-    char * const *cur;
     const char *p, *errstr, *groups = NULL;
     const char *remhost = NULL;
+    char * const *cur;
     int flags = 0;
     debug_decl(sudoers_policy_deserialize_info, SUDOERS_DEBUG_PLUGIN);
 
@@ -319,6 +320,12 @@ sudoers_policy_deserialize_info(void *v,
 #endif
     }
 
+    /* Sudo front-end should restrict mode flags for sudoedit. */
+    if (ISSET(flags, MODE_EDIT) && (flags & edit_mask) != flags) {
+	sudo_warnx(U_("invalid mode flags from sudo front end: 0x%x"), flags);
+	goto bad;
+    }
+
     user_gid = (gid_t)-1;
     user_sid = (pid_t)-1;
     user_uid = (gid_t)-1;
