Skip to content

Commit 67b3a30

Browse files
committed
visudo: Fix fd leak on error path now that we don't exit on error
1 parent a642d98 commit 67b3a30

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

plugins/sudoers/visudo.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* SPDX-License-Identifier: ISC
33
*
4-
* Copyright (c) 1996, 1998-2005, 2007-2023
4+
* Copyright (c) 1996, 1998-2005, 2007-2023, 2025
55
* Todd C. Miller <[email protected]>
66
*
77
* Permission to use, copy, modify, and distribute this software for any
@@ -478,7 +478,7 @@ static bool
478478
edit_sudoers(struct sudoersfile *sp, char *editor, int editor_argc,
479479
char **editor_argv, int lineno)
480480
{
481-
int tfd; /* sudoers temp file descriptor */
481+
int tfd = -1; /* sudoers temp file descriptor */
482482
bool modified; /* was the file modified? */
483483
int ac; /* argument count */
484484
char linestr[64]; /* string version of lineno */
@@ -536,6 +536,7 @@ edit_sudoers(struct sudoersfile *sp, char *editor, int editor_argc,
536536
}
537537
}
538538
(void) close(tfd);
539+
tfd = -1;
539540
}
540541
times[0].tv_sec = times[1].tv_sec = orig_mtim.tv_sec;
541542
times[0].tv_nsec = times[1].tv_nsec = orig_mtim.tv_nsec;
@@ -628,6 +629,8 @@ edit_sudoers(struct sudoersfile *sp, char *editor, int editor_argc,
628629

629630
ret = true;
630631
done:
632+
if (tfd != -1)
633+
close(tfd);
631634
debug_return_bool(ret);
632635
}
633636

@@ -680,6 +683,7 @@ reparse_sudoers(struct sudoers_context *ctx, char *editor, int editor_argc,
680683
/* Clean slate for each parse */
681684
if (!init_defaults()) {
682685
sudo_warnx("%s", U_("unable to initialize sudoers default values"));
686+
fclose(fp);
683687
goto done;
684688
}
685689
init_parser(ctx, sp->opath);

0 commit comments

Comments
 (0)