mirror of
https://github.com/sudo-project/sudo.git
synced 2025-09-01 14:55:12 +00:00
o The parser needs sudoers to end with a newline but some editors (emacs) may
not add one. Check for a missing newline at EOF and add one if needed. o Set quiet flag during initial sudoers parse (to get options) o Move yyrestart() call and always use freopen() to open yyin after initial sudoers parse.
This commit is contained in:
25
visudo.c
25
visudo.c
@@ -231,17 +231,24 @@ main(argc, argv)
|
|||||||
Exit(-1);
|
Exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Add missing newline at EOF if needed. */
|
||||||
|
if (n > 0 && buf[n - 1] != '\n') {
|
||||||
|
buf[0] = '\n';
|
||||||
|
write(stmp_fd, buf, 1);
|
||||||
|
}
|
||||||
|
|
||||||
(void) close(stmp_fd);
|
(void) close(stmp_fd);
|
||||||
(void) touch(stmp, sudoers_sb.st_mtime);
|
(void) touch(stmp, sudoers_sb.st_mtime);
|
||||||
|
|
||||||
/* Parse sudoers to pull in editor and env_editor conf values. */
|
/* Parse sudoers to pull in editor and env_editor conf values. */
|
||||||
if ((yyin = fopen(stmp, "r"))) {
|
if ((yyin = fopen(stmp, "r"))) {
|
||||||
yyout = stdout;
|
yyout = stdout;
|
||||||
|
n = quiet;
|
||||||
|
quiet = 1;
|
||||||
init_parser();
|
init_parser();
|
||||||
yyparse();
|
yyparse();
|
||||||
parse_error = FALSE;
|
parse_error = FALSE;
|
||||||
yyrestart(yyin);
|
quiet = n;
|
||||||
fclose(yyin);
|
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
(void) close(stmp_fd);
|
(void) close(stmp_fd);
|
||||||
@@ -390,10 +397,7 @@ main(argc, argv)
|
|||||||
* for parse errors.
|
* for parse errors.
|
||||||
*/
|
*/
|
||||||
yyout = stdout;
|
yyout = stdout;
|
||||||
if (parse_error)
|
yyin = freopen(stmp, "r+", yyin);
|
||||||
yyin = freopen(stmp, "r", yyin);
|
|
||||||
else
|
|
||||||
yyin = fopen(stmp, "r");
|
|
||||||
if (yyin == NULL) {
|
if (yyin == NULL) {
|
||||||
(void) fprintf(stderr,
|
(void) fprintf(stderr,
|
||||||
"%s: Can't re-open temporary file (%s), %s unchanged.\n",
|
"%s: Can't re-open temporary file (%s), %s unchanged.\n",
|
||||||
@@ -401,12 +405,18 @@ main(argc, argv)
|
|||||||
Exit(-1);
|
Exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Add missing newline at EOF if needed. */
|
||||||
|
if (fseek(yyin, -1, SEEK_END) == 0 && (ch = fgetc(yyin)) != '\n')
|
||||||
|
fputc('\n', yyin);
|
||||||
|
rewind(yyin);
|
||||||
|
|
||||||
/* Clean slate for each parse */
|
/* Clean slate for each parse */
|
||||||
user_runas = NULL;
|
user_runas = NULL;
|
||||||
init_defaults();
|
init_defaults();
|
||||||
init_parser();
|
init_parser();
|
||||||
|
|
||||||
/* Parse the sudoers file */
|
/* Parse the sudoers temp file */
|
||||||
|
yyrestart(yyin);
|
||||||
if (yyparse() && parse_error != TRUE) {
|
if (yyparse() && parse_error != TRUE) {
|
||||||
(void) fprintf(stderr,
|
(void) fprintf(stderr,
|
||||||
"%s: Failed to parse temporary file (%s), unknown error.\n",
|
"%s: Failed to parse temporary file (%s), unknown error.\n",
|
||||||
@@ -432,7 +442,6 @@ main(argc, argv)
|
|||||||
Exit(0);
|
Exit(0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
yyrestart(yyin); /* reset lexer */
|
|
||||||
}
|
}
|
||||||
} while (parse_error == TRUE);
|
} while (parse_error == TRUE);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user