Fix a memory leak on error when including a file or directory.

This commit is contained in:
Todd C. Miller
2020-05-19 10:09:34 -06:00
parent 5a69831dd4
commit a41d7b545a
2 changed files with 8 additions and 0 deletions

View File

@@ -4572,6 +4572,7 @@ push_include_int(char *path, bool isdir)
if (idepth > MAX_SUDOERS_DEPTH) {
sudoerserror(N_("too many levels of includes"));
rcstr_delref(path);
debug_return_bool(false);
}
istacksize += SUDOERS_STACK_INCREMENT;
@@ -4579,6 +4580,7 @@ push_include_int(char *path, bool isdir)
if (new_istack == NULL) {
sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
sudoerserror(NULL);
rcstr_delref(path);
debug_return_bool(false);
}
istack = new_istack;
@@ -4614,6 +4616,7 @@ push_include_int(char *path, bool isdir)
}
}
/* A missing or insecure include dir is not a fatal error. */
rcstr_delref(path);
debug_return_bool(true);
}
count = switch_dir(&istack[idepth], path);
@@ -4638,6 +4641,7 @@ push_include_int(char *path, bool isdir)
if ((fp = open_sudoers(path, true, &keepopen)) == NULL) {
/* The error was already printed by open_sudoers() */
sudoerserror(NULL);
rcstr_delref(path);
debug_return_bool(false);
}
}

View File

@@ -933,6 +933,7 @@ push_include_int(char *path, bool isdir)
if (idepth > MAX_SUDOERS_DEPTH) {
sudoerserror(N_("too many levels of includes"));
rcstr_delref(path);
debug_return_bool(false);
}
istacksize += SUDOERS_STACK_INCREMENT;
@@ -940,6 +941,7 @@ push_include_int(char *path, bool isdir)
if (new_istack == NULL) {
sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
sudoerserror(NULL);
rcstr_delref(path);
debug_return_bool(false);
}
istack = new_istack;
@@ -975,6 +977,7 @@ push_include_int(char *path, bool isdir)
}
}
/* A missing or insecure include dir is not a fatal error. */
rcstr_delref(path);
debug_return_bool(true);
}
count = switch_dir(&istack[idepth], path);
@@ -999,6 +1002,7 @@ push_include_int(char *path, bool isdir)
if ((fp = open_sudoers(path, true, &keepopen)) == NULL) {
/* The error was already printed by open_sudoers() */
sudoerserror(NULL);
rcstr_delref(path);
debug_return_bool(false);
}
}