#3 Can't add a username consists of only digitals
Closed: Fixed None Opened 10 years ago by panweiping.

I found a BUG in libuser-0.56.9.
When I add a username consists of only digitals, like "1234", error happens.

Reproduce steps:
1 luseradd 1234
2 Group 1234 does not exist

But when I use "useradd 1234" command, no error happens.

I find the reason that luseradd converts "1234" from string to a long
int, and uses it as gid.
But when luseradd uses lu_group_lookup_id(ctx, gidNumber, groupEnt,
&error) to find the group,
error happens, because there is not such a group.

Regards!

Pan Weiping

--- libuser-0.56.9_bak/apps/luseradd.c 2009-02-17 14:33:31.000000000 +0800
+++ libuser-0.56.9/apps/luseradd.c 2009-02-17 16:32:47.000000000 +0800
@@ -143,8 +143,16 @@
groupEnt = lu_ent_new();
errno = 0;
imax = strtoimax(gid, &p, 10);
- if (errno == 0 && p == 0 && p != gid && (gid_t)imax == imax)
- gidNumber = imax;
+ if (errno == 0 &&
p == 0 && p != gid && (gid_t)imax == imax) {
+ if (lu_group_lookup_id(ctx, imax, groupEnt, &error))
+ gidNumber = imax;
+ else
+ gidNumber = LU_VALUE_INVALID_ID;
+
+ / lu_group_lookup_id may fail, but it doesn't matter.
+ * reset error
/
+ error = NULL;
+ }
else
/ It's not a number, so it's a group name. /
gidNumber = LU_VALUE_INVALID_ID;


Thanks for your report.

I have used a more direct patch that doesn't change the semantics of -g.

Fix released in libuser-0.56.10.

Metadata Update from @mitr:
- Issue assigned to mitr

2 years ago

Login to comment on this ticket.

Metadata