On Wednesday 18 February 2015 17:11:33 tito wrote:
> Hi,
> while experimenting with a modified version of deluser.c
> I've hit a bug in libpwdgrp. The attached drop in replacement
> for deluser.c triggers the bug if compiled with bb's libpwdgrp
> and instead works correctly with glibc.
> 
> To reproduce:
> adduser prova
> addgroup test1
> addgroup test2
> addgroup prova test1
> addgroup prova test2
> grep prova /etc/passwd /etc/group
> /etc/passwd:prova:x:1004:1005:,,,:/home/prova:/bin/bash
> /etc/group:test1:x:1008:prova
> /etc/group:test2:x:1009:prova
> /etc/group:prova:x:1005:
> 
> with glibc:
>  ./busybox deluser prova
> groups[2]=1009
> groups[2] gr->gr_name=test2
> groups[1]=1008
> groups[1] gr->gr_name=test1
> grep prova /etc/passwd /etc/group
> 
> with bb's pwdgrp
> 
> ./busybox deluser prova
> groups[2]=1009
> groups[2] gr->gr_name=test2
> groups[1]=1008
> getgrgid failed errno=0
> 
> grep prova /etc/passwd /etc/group
> /etc/group:test1:x:1008:prova
> /etc/group:prova:x:1005:
> 
> seems to me that subsequent calls
> to getgrgid and getgrnam fail
> 
> Ciao,
> Tito
> 
Hi Denys,
the attached patch fixes the bug. Looks like a copy paste error to me.
Could you please double check as this db_and_field_pos stuff is a little
like black magic to me.

Ciao,
Tito

--- libpwdgrp/pwd_grp.c.original        2015-02-19 21:01:52.742313374 +0100
+++ libpwdgrp/pwd_grp.c 2015-02-19 21:02:35.547212303 +0100
@@ -450,15 +450,7 @@
        char *buf;
        struct passdb *db = &get_S()->db[db_and_field_pos >> 2];
 
-       if (!db->fp) {
-               db->fp = fopen_for_read(db->filename);
-               if (!db->fp) {
-                       return NULL;
-               }
-               close_on_exec_on(fileno(db->fp));
-       }
-
-       buf = parse_common(db->fp, db, name, db_and_field_pos & 3);
+       buf = parse_file(db, name, db_and_field_pos & 3);
        return massage_data_for_non_r_func(db, buf);
 }
 
Fix copy/paste error.

Signed-off-by: Tito Ragusa <farmat...@tiscali.it>

--- libpwdgrp/pwd_grp.c.original	2015-02-19 21:01:52.742313374 +0100
+++ libpwdgrp/pwd_grp.c	2015-02-19 21:02:35.547212303 +0100
@@ -450,15 +450,7 @@
 	char *buf;
 	struct passdb *db = &get_S()->db[db_and_field_pos >> 2];
 
-	if (!db->fp) {
-		db->fp = fopen_for_read(db->filename);
-		if (!db->fp) {
-			return NULL;
-		}
-		close_on_exec_on(fileno(db->fp));
-	}
-
-	buf = parse_common(db->fp, db, name, db_and_field_pos & 3);
+	buf = parse_file(db, name, db_and_field_pos & 3);
 	return massage_data_for_non_r_func(db, buf);
 }
 
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to