Created attachment 333372 [details] useradd errno clear patch Description of problem: Noticed a problem where useradd would fail on a system with 'invalid numeric argument' in get_uid() when you supply a UID on the cmdline. After some liberal printf's I found the message came because errno still retains a previous ERANGE value (34) after a call in get_defaults() from a getgrgid that is never tested on or subsequently cleared. Before test conditions relying on errno are thrown, errno should be set to 0 since libs are not supposed to set/change the value unless they encounter an error. ------------------------------------------------------------------------ Version-Release number of selected component (if applicable): Tested on shadow-utils-4.0.17-14.el5 & shadow-utils-4.1.2-9 ------------------------------------------------------------------------ Results from debug: ----- From orig line Printf in get_uid(): 256 : Modified to: val = strtol (uidstr, &errptr, 10); if (*errptr || errno == ERANGE || val < 0) { fprintf (stderr, _("%s: invalid numeric argument '%s', val: '%li' < 0, errno = '%i', ptr = '%c' @addr:%p\n"), Prog, uidstr, val, errno,*errptr,*errptr); exit (E_BAD_ARG); } ---- From orig line Printf get_defaults(): 311 def_group = val; /* local, no need for xgetgrgid */ if ((grp = getgrgid (def_group))) { if (errno != 0 ) { fprintf (stderr, _("get_def:primgroup_if1: Previous Errno value of '%i' present. Buf is '%s', str is '%s'; DEFsize '%i'; GrpSize '%i'; GrName '%s', GrPass '%s', GrID '%u', GrMem '%s'.\n"),errno,buf,cp,sizeof(def_group),sizeof(getgrgid (def_group)),grp->gr_name,grp->gr_passwd,grp->gr_gid,grp->gr_mem); } ===== ./useradd -u 123456 -G test -c"TEST_USER" TEST_USER get_def:primgroup_if1: Previous Errno value of '34' present. Buf is 'GROUP=100', str is '100'; DEFsize '4'; GrpSize '8'; GrName 'users', GrPass 'x', GrID '100', GrMem '=�'. useradd: invalid numeric argument '123456', val: '123456' < 0, errno = '34', ptr = '' @addr:(nil) ------------------------------------------------------------------------ Additional info: I've yet to RC the orig error for ERANGE, but future tests on value of errno after stdlib calls should honestly clear it first to reduce false failures. If ERANGE errors or others are important from earlier calls, I don't believe its good practice to waterfall them through till later sections. With that I'll continue to debug the reason for the ERANGE, for that reason I've submitted a patch (attached) to clear errno before current tests.
thnx. Doug, I have also reported it to upstream.
This request was evaluated by Red Hat Product Management for inclusion, but this component is not scheduled to be updated in the current Red Hat Enterprise Linux release. If you would like this request to be reviewed for the next minor release, ask your support representative to set the next rhel-x.y flag to "?".
Created attachment 366348 [details] upstream shadow-util patch updated for RHEL5 This patch was made to help apply to RHEL5 shadow-utils since the upstream patch does not apply cleanly. (ie, drop into SOURCES and update the .spec) -- Robin
Doug, can you give me a hint. I don't know how I can reproduce it. :(
Sorry Peter, never saw a notice until today about your comment. I origionally saw this with just issuing: ./useradd -u 123456 -G test -c"TEST_USER" TEST_USER On a freshly installed 5.3 system, I'll see if I can find or build a new 5.3 system with that version of shadow_utils to repro.
An advisory has been issued which should help the problem described in this bug report. This report is therefore being closed with a resolution of ERRATA. For more information on therefore solution and/or where to find the updated files, please follow the link below. You may reopen this bug report if the solution does not work for you. http://rhn.redhat.com/errata/RHBA-2010-0209.html