|
1 | 1 | /* |
2 | 2 | * SPDX-License-Identifier: ISC |
3 | 3 | * |
4 | | - * Copyright (c) 1996, 1998-2005, 2007-2023 |
| 4 | + * Copyright (c) 1996, 1998-2005, 2007-2023, 2025 |
5 | 5 | * Todd C. Miller <[email protected]> |
6 | 6 | * |
7 | 7 | * Permission to use, copy, modify, and distribute this software for any |
@@ -478,7 +478,7 @@ static bool |
478 | 478 | edit_sudoers(struct sudoersfile *sp, char *editor, int editor_argc, |
479 | 479 | char **editor_argv, int lineno) |
480 | 480 | { |
481 | | - int tfd; /* sudoers temp file descriptor */ |
| 481 | + int tfd = -1; /* sudoers temp file descriptor */ |
482 | 482 | bool modified; /* was the file modified? */ |
483 | 483 | int ac; /* argument count */ |
484 | 484 | char linestr[64]; /* string version of lineno */ |
@@ -536,6 +536,7 @@ edit_sudoers(struct sudoersfile *sp, char *editor, int editor_argc, |
536 | 536 | } |
537 | 537 | } |
538 | 538 | (void) close(tfd); |
| 539 | + tfd = -1; |
539 | 540 | } |
540 | 541 | times[0].tv_sec = times[1].tv_sec = orig_mtim.tv_sec; |
541 | 542 | 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, |
628 | 629 |
|
629 | 630 | ret = true; |
630 | 631 | done: |
| 632 | + if (tfd != -1) |
| 633 | + close(tfd); |
631 | 634 | debug_return_bool(ret); |
632 | 635 | } |
633 | 636 |
|
@@ -680,6 +683,7 @@ reparse_sudoers(struct sudoers_context *ctx, char *editor, int editor_argc, |
680 | 683 | /* Clean slate for each parse */ |
681 | 684 | if (!init_defaults()) { |
682 | 685 | sudo_warnx("%s", U_("unable to initialize sudoers default values")); |
| 686 | + fclose(fp); |
683 | 687 | goto done; |
684 | 688 | } |
685 | 689 | init_parser(ctx, sp->opath); |
|
0 commit comments