diff options
author | Michael Forney <mforney@mforney.org> | 2013-11-04 23:34:20 -0800 |
---|---|---|
committer | Rich Felker <dalias@aerifal.cx> | 2013-11-23 16:20:51 -0500 |
commit | a3b98a11a9b51801109ad46df2a44ee2ee03e37e (patch) | |
tree | 1a9e168069050f2cfea7d89c09e9f2b09df9007e /src/passwd | |
parent | b300d5b7bd74070982da50d996773a2dd8156a01 (diff) | |
download | musl-a3b98a11a9b51801109ad46df2a44ee2ee03e37e.tar.gz musl-a3b98a11a9b51801109ad46df2a44ee2ee03e37e.tar.xz musl-a3b98a11a9b51801109ad46df2a44ee2ee03e37e.zip |
putgrent: Stop writing output on first failure
This way, if an fprintf fails, we get an incomplete group entry rather than a corrupted one.
Diffstat (limited to 'src/passwd')
-rw-r--r-- | src/passwd/putgrent.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/src/passwd/putgrent.c b/src/passwd/putgrent.c index d7847b15..b34f3254 100644 --- a/src/passwd/putgrent.c +++ b/src/passwd/putgrent.c @@ -6,9 +6,10 @@ int putgrent(const struct group *gr, FILE *f) int r; size_t i; flockfile(f); - r = fprintf(f, "%s:%s:%d:", gr->gr_name, gr->gr_passwd, gr->gr_gid); + if ((r = fprintf(f, "%s:%s:%d:", gr->gr_name, gr->gr_passwd, gr->gr_gid))<0) goto done; if (gr->gr_mem) for (i=0; gr->gr_mem[i]; i++) - if (fprintf(f, "%s%s", i?",":"", gr->gr_mem[i])<0) r = -1; + if ((r = fprintf(f, "%s%s", i?",":"", gr->gr_mem[i]))<0) goto done; +done: funlockfile(f); return r<0 ? -1 : 0; } |