summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorRenato Botelho <renato@netgate.com>2016-03-02 14:40:42 -0300
committerRenato Botelho <renato@netgate.com>2016-03-02 14:40:42 -0300
commit728813a02a03cdab41bffc21d729fb394aef805c (patch)
treed27d88db3097dbd5f8c27961ed4d99f675fb3731 /lib
parent065e672a01ab2d9ebfed1dccb588be99bd5bc73a (diff)
downloadFreeBSD-src-728813a02a03cdab41bffc21d729fb394aef805c.zip
FreeBSD-src-728813a02a03cdab41bffc21d729fb394aef805c.tar.gz
Import review D5409
Diffstat (limited to 'lib')
-rw-r--r--lib/libutil/gr_util.c6
-rw-r--r--lib/libutil/pw_util.c13
2 files changed, 14 insertions, 5 deletions
diff --git a/lib/libutil/gr_util.c b/lib/libutil/gr_util.c
index 80d9ee6..1acbadb 100644
--- a/lib/libutil/gr_util.c
+++ b/lib/libutil/gr_util.c
@@ -141,13 +141,13 @@ gr_tmp(int mfd)
errno = ENAMETOOLONG;
return (-1);
}
- if ((tfd = mkostemp(tempname, O_SYNC)) == -1)
+ if ((tfd = mkstemp(tempname)) == -1)
return (-1);
if (mfd != -1) {
while ((nr = read(mfd, buf, sizeof(buf))) > 0)
if (write(tfd, buf, (size_t)nr) != nr)
break;
- if (nr != 0) {
+ if (nr != 0 || fsync(tfd) != 0) {
unlink(tempname);
*tempname = '\0';
close(tfd);
@@ -305,6 +305,8 @@ gr_copy(int ffd, int tfd, const struct group *gr, struct group *old_gr)
done:
if (line != NULL)
free(line);
+ if (fsync(tfd) != 0)
+ goto err;
return (0);
err:
if (line != NULL)
diff --git a/lib/libutil/pw_util.c b/lib/libutil/pw_util.c
index af749d5..b369035 100644
--- a/lib/libutil/pw_util.c
+++ b/lib/libutil/pw_util.c
@@ -226,13 +226,13 @@ pw_tmp(int mfd)
errno = ENAMETOOLONG;
return (-1);
}
- if ((tfd = mkostemp(tempname, O_SYNC)) == -1)
+ if ((tfd = mkstemp(tempname)) == -1)
return (-1);
if (mfd != -1) {
while ((nr = read(mfd, buf, sizeof(buf))) > 0)
if (write(tfd, buf, (size_t)nr) != nr)
break;
- if (nr != 0) {
+ if (nr != 0 || fsync(tfd) != 0) {
unlink(tempname);
*tempname = '\0';
close(tfd);
@@ -289,7 +289,7 @@ pw_edit(int notsetuid)
sigset_t oldsigset, nsigset;
struct stat st1, st2;
const char *editor;
- int pstat;
+ int pstat, fd;
if ((editor = getenv("EDITOR")) == NULL)
editor = _PATH_VI;
@@ -344,6 +344,11 @@ pw_edit(int notsetuid)
sigprocmask(SIG_SETMASK, &oldsigset, NULL);
if (stat(tempname, &st2) == -1)
return (-1);
+ if ((fd = open(tempname, O_RDONLY)) == -1 || fsync(fd) == -1) {
+ close(fd);
+ return (-1);
+ }
+ close(fd);
return (st1.st_mtim.tv_sec != st2.st_mtim.tv_sec ||
st1.st_mtim.tv_nsec != st2.st_mtim.tv_nsec);
}
@@ -570,6 +575,8 @@ pw_copy(int ffd, int tfd, const struct passwd *pw, struct passwd *old_pw)
done:
if (line != NULL)
free(line);
+ if (fsync(tfd) != 0)
+ goto err;
return (0);
err:
if (line != NULL)
OpenPOWER on IntegriCloud