summaryrefslogtreecommitdiff
path: root/libmount/src/tab_update.c
diff options
context:
space:
mode:
authorKarel Zak <kzak@redhat.com>2013-10-01 16:56:26 +0200
committerKarel Zak <kzak@redhat.com>2013-10-01 16:56:26 +0200
commita84ec176eca207eadcd2a47056ad44df082f1b02 (patch)
tree3ecfeaf7769e5cb649d11705841400f52eb2a8e8 /libmount/src/tab_update.c
parent0525768a5be893d309917fbb527b1cf0589fdaa2 (diff)
downloadutil-linux-a84ec176eca207eadcd2a47056ad44df082f1b02.tar.gz
libmount: make mnt_table_replace_file() more robust [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libmount/src/tab_update.c')
-rw-r--r--libmount/src/tab_update.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/libmount/src/tab_update.c b/libmount/src/tab_update.c
index a508b9903..13f6f6ebe 100644
--- a/libmount/src/tab_update.c
+++ b/libmount/src/tab_update.c
@@ -640,6 +640,12 @@ int mnt_table_replace_file(struct libmnt_table *tb, const char *filename)
mnt_table_write_file(tb, f);
+ if (fflush(f) != 0) {
+ rc = -errno;
+ DBG(UPDATE, mnt_debug("%s: fflush failed: %m", uq));
+ goto leave;
+ }
+
rc = fchmod(fd, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH) ? -errno : 0;
if (!rc && stat(filename, &st) == 0)
@@ -647,19 +653,25 @@ int mnt_table_replace_file(struct libmnt_table *tb, const char *filename)
rc = fchown(fd, st.st_uid, st.st_gid) ? -errno : 0;
fclose(f);
+ f = NULL;
+
if (!rc)
- rename(uq, filename);
+ rc = rename(uq, filename) ? -errno : 0;
} else {
rc = -errno;
close(fd);
}
+leave:
+ if (f)
+ fclose(f);
unlink(uq);
free(uq);
DBG(TAB, mnt_debug_h(tb, "replace done [rc=%d]", rc));
return rc;
}
+
static int add_file_entry(struct libmnt_table *tb, struct libmnt_update *upd)
{
struct libmnt_fs *fs;