diff options
author | Karel Zak <kzak@redhat.com> | 2016-03-29 13:23:32 +0200 |
---|---|---|
committer | Karel Zak <kzak@redhat.com> | 2016-03-29 13:23:32 +0200 |
commit | 76839e9794e2841bce6a6c3a5a91e02f4918e646 (patch) | |
tree | 95e9227289504527d8c76a09041d2a3c78b75636 | |
parent | 50359e979428c2d244193a50ea7a58f77b5c94b1 (diff) | |
download | util-linux-76839e9794e2841bce6a6c3a5a91e02f4918e646.tar.gz |
vipw: make tmp_file usage more robust [clang analyze]
Signed-off-by: Karel Zak <kzak@redhat.com>
-rw-r--r-- | login-utils/vipw.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/login-utils/vipw.c b/login-utils/vipw.c index 043865682..2e343b6ea 100644 --- a/login-utils/vipw.c +++ b/login-utils/vipw.c @@ -181,6 +181,7 @@ static void pw_write(void) } unlink(tmp_file); free(tmp_file); + tmp_file = NULL; } static void pw_edit(void) @@ -233,7 +234,9 @@ pw_error(char *name, int err, int eval) warn(NULL); } warnx(_("%s unchanged"), orig_file); - unlink(tmp_file); + + if (tmp_file) + unlink(tmp_file); ulckpwdf(); exit(eval); } @@ -269,7 +272,7 @@ static void edit_file(int is_shadow) if (close_stream(tmp_fd) != 0) err(EXIT_FAILURE, _("write error")); tmp_fd = fopen(tmp_file, "r"); - if (!tmp_file) + if (!tmp_fd) err(EXIT_FAILURE, _("cannot open %s"), tmp_file); if (fstat(fileno(tmp_fd), &end)) pw_error(tmp_file, 1, 1); |