Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date: Mon,  4 Nov 2013 23:34:20 -0800
From: Michael Forney <>
Subject: [PATCH 1/2] putgrent: Stop writing output on first failure

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;
-	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;
 	return r<0 ? -1 : 0;

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.