diff --git a/plugins/sudoers/Makefile.in b/plugins/sudoers/Makefile.in index 662567dd7..e96c78db2 100644 --- a/plugins/sudoers/Makefile.in +++ b/plugins/sudoers/Makefile.in @@ -657,6 +657,7 @@ check: $(TEST_PROGS) visudo testsudoers cvtsudoers check-fuzzer ./check_digest > regress/parser/check_digest.out; \ diff regress/parser/check_digest.out $(srcdir)/regress/parser/check_digest.out.ok || rval=`expr $$rval + $$?`; \ fi; \ + ./check_editor || rval=`expr $$rval + $$?`; \ ./check_env_pattern $(srcdir)/regress/env_match/data || rval=`expr $$rval + $$?`; \ ./check_exptilde || rval=`expr $$rval + $$?`; \ ./check_fill || rval=`expr $$rval + $$?`; \ diff --git a/plugins/sudoers/editor.c b/plugins/sudoers/editor.c index 70b8cdf64..f2d6a3cc2 100644 --- a/plugins/sudoers/editor.c +++ b/plugins/sudoers/editor.c @@ -63,10 +63,16 @@ wordsplit(const char *str, const char *endstr, const char **last) /* If word is quoted, skip to end quote and return. */ if (*str == '"' || *str == '\'') { - const char *endquote = memchr(str + 1, *str, endstr - str); - if (endquote != NULL) { - *last = endquote; - debug_return_const_ptr(str + 1); + const char *endquote; + for (cp = str + 1; cp < endstr; cp = endquote + 1) { + endquote = memchr(cp, *str, endstr - cp); + if (endquote == NULL) + break; + /* ignore escaped quotes */ + if (endquote[-1] != '\\') { + *last = endquote; + debug_return_const_ptr(str + 1); + } } } diff --git a/plugins/sudoers/regress/editor/check_editor.c b/plugins/sudoers/regress/editor/check_editor.c index 7653c94eb..76ab663c0 100644 --- a/plugins/sudoers/regress/editor/check_editor.c +++ b/plugins/sudoers/regress/editor/check_editor.c @@ -45,6 +45,15 @@ struct test_data { 5, { "sh", "-c", "vi $1", "--", "/etc/motd", NULL } }, + { + /* Try connecting to the emacs server, falling back on plain emacs. */ + "VISUAL=sh -c \"emacsclient -a emacs -n \\\"\\$@\\\" || emacs \\\"\\$@\\\"\"", + 1, + { "/etc/motd", NULL }, + "/usr/bin/sh", + 5, + { "sh", "-c", "emacsclient -a emacs -n \"$@\" || emacs \"$@\"", "--", "/etc/motd", NULL } + }, { /* GitHub issue #99 */ "EDITOR=/usr/bin/vi\\",