Bug 487575

Summary: useradd: does not clear errno prior to checking fn returns
Product: Red Hat Enterprise Linux 5 Reporter: Doug Farley <Douglas_Farley>
Component: shadow-utilsAssignee: Peter Vrabec <pvrabec>
Status: CLOSED ERRATA QA Contact: BaseOS QE <qe-baseos-auto>
Severity: low Docs Contact:
Priority: low    
Version: 5.3CC: Douglas_Farley, mmalik, sgrubb, tao, tmraz
Target Milestone: rc   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2010-03-30 08:13:44 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
useradd errno clear patch
none
upstream shadow-util patch updated for RHEL5 none

Description Doug Farley 2009-02-26 19:10:35 UTC
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.

Comment 1 Peter Vrabec 2009-03-23 16:46:42 UTC
thnx. Doug, I have also reported it to upstream.

Comment 2 RHEL Program Management 2009-03-26 16:49:03 UTC
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 "?".

Comment 3 Robin R. Price II 2009-10-27 21:10:07 UTC
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

Comment 6 Peter Vrabec 2009-11-25 16:20:47 UTC
Doug, can you give me a hint. I don't know how I can reproduce it. :(

Comment 9 Doug Farley 2010-01-07 15:23:03 UTC
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.

Comment 11 errata-xmlrpc 2010-03-30 08:13:44 UTC
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