* [PATCH 1/2] putgrent: Stop writing output on first failure
@ 2013-11-05 7:34 Michael Forney
2013-11-05 7:34 ` [PATCH 2/2] putgrent: Add missing newline Michael Forney
0 siblings, 1 reply; 2+ messages in thread
From: Michael Forney @ 2013-11-05 7:34 UTC (permalink / raw)
To: musl
This way, if an fprintf fails, we get an incomplete group entry rather
than a corrupted one.
---
src/passwd/putgrent.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/src/passwd/putgrent.c b/src/passwd/putgrent.c
index d7847b1..b34f325 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;
}
--
1.8.4.2
^ permalink raw reply [flat|nested] 2+ messages in thread
* [PATCH 2/2] putgrent: Add missing newline
2013-11-05 7:34 [PATCH 1/2] putgrent: Stop writing output on first failure Michael Forney
@ 2013-11-05 7:34 ` Michael Forney
0 siblings, 0 replies; 2+ messages in thread
From: Michael Forney @ 2013-11-05 7:34 UTC (permalink / raw)
To: musl
---
src/passwd/putgrent.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/passwd/putgrent.c b/src/passwd/putgrent.c
index b34f325..6f26c05 100644
--- a/src/passwd/putgrent.c
+++ b/src/passwd/putgrent.c
@@ -9,6 +9,7 @@ int putgrent(const struct group *gr, FILE *f)
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 ((r = fprintf(f, "%s%s", i?",":"", gr->gr_mem[i]))<0) goto done;
+ r = fputc('\n', f);
done:
funlockfile(f);
return r<0 ? -1 : 0;
--
1.8.4.2
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-11-05 7:34 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-05 7:34 [PATCH 1/2] putgrent: Stop writing output on first failure Michael Forney
2013-11-05 7:34 ` [PATCH 2/2] putgrent: Add missing newline Michael Forney
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).