mirror of
https://github.com/sudo-project/sudo.git
synced 2025-08-31 06:15:37 +00:00
Add garbage collection to resolve_editor().
Fixes a leak when evaluating the policy multiple times if sudoedit is set.
This commit is contained in:
@@ -101,6 +101,7 @@ copy_arg(const char *src, size_t len)
|
||||
debug_decl(copy_arg, SUDOERS_DEBUG_UTIL);
|
||||
|
||||
if ((copy = malloc(len + 1)) != NULL) {
|
||||
sudoers_gc_add(GC_PTR, copy);
|
||||
for (dst = copy; src < src_end; ) {
|
||||
if (src[0] == '\\' && src[1] != '\0') {
|
||||
src++;
|
||||
@@ -163,6 +164,7 @@ resolve_editor(const char *ed, size_t edlen, int nfiles, char **files,
|
||||
nargv = reallocarray(NULL, nargc + 1, sizeof(char *));
|
||||
if (nargv == NULL)
|
||||
goto oom;
|
||||
sudoers_gc_add(GC_PTR, nargv);
|
||||
|
||||
/* Fill in editor argv (assumes files[] is NULL-terminated). */
|
||||
nargv[0] = editor;
|
||||
@@ -188,8 +190,11 @@ oom:
|
||||
free(editor);
|
||||
free(editor_path);
|
||||
if (nargv != NULL) {
|
||||
while (nargc--)
|
||||
while (nargc--) {
|
||||
sudoers_gc_remove(GC_PTR, nargv[nargc]);
|
||||
free(nargv[nargc]);
|
||||
}
|
||||
sudoers_gc_remove(GC_PTR, nargv);
|
||||
free(nargv);
|
||||
}
|
||||
debug_return_str(NULL);
|
||||
|
Reference in New Issue
Block a user