Clear sudoers_errstr after it is used.

This way we avoid printing the same error message more than once
if there are multiple ERROR tokens returned from the lexer.
This commit is contained in:
Todd C. Miller
2022-02-10 16:09:44 -07:00
parent 3c1ce4bf72
commit c8bf591042
2 changed files with 14 additions and 8 deletions

View File

@@ -3344,10 +3344,7 @@ sudoerserrorf(const char *fmt, ...)
sudoers_setlocale(SUDOERS_LOCALE_USER, &oldlocale);
va_start(ap, fmt);
if (sudoerschar == ERROR) {
/* Use error string from lexer. */
s = _(sudoers_errstr);
} else if (strcmp(fmt, "%s") == 0) {
if (strcmp(fmt, "%s") == 0) {
/* Optimize common case, a single string. */
s = _(va_arg(ap, char *));
} else {
@@ -3389,6 +3386,12 @@ sudoerserrorf(const char *fmt, ...)
void
sudoerserror(const char *s)
{
if (sudoerschar == ERROR) {
/* Use error string from lexer. */
s = sudoers_errstr;
sudoers_errstr = NULL;
}
// -V:sudoerserror:575, 618
if (s == NULL)
sudoerserrorf(NULL);

View File

@@ -1188,10 +1188,7 @@ sudoerserrorf(const char *fmt, ...)
sudoers_setlocale(SUDOERS_LOCALE_USER, &oldlocale);
va_start(ap, fmt);
if (sudoerschar == ERROR) {
/* Use error string from lexer. */
s = _(sudoers_errstr);
} else if (strcmp(fmt, "%s") == 0) {
if (strcmp(fmt, "%s") == 0) {
/* Optimize common case, a single string. */
s = _(va_arg(ap, char *));
} else {
@@ -1233,6 +1230,12 @@ sudoerserrorf(const char *fmt, ...)
void
sudoerserror(const char *s)
{
if (sudoerschar == ERROR) {
/* Use error string from lexer. */
s = sudoers_errstr;
sudoers_errstr = NULL;
}
// -V:sudoerserror:575, 618
if (s == NULL)
sudoerserrorf(NULL);