Bug 89052 - getpwuid_r on RH-9 may return 0 when in fact there was an error
getpwuid_r on RH-9 may return 0 when in fact there was an error
Status: CLOSED CURRENTRELEASE
Product: Red Hat Linux
Classification: Retired
Component: glibc (Show other bugs)
9
All Linux
medium Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2003-04-16 18:33 EDT by Hui Huang
Modified: 2016-11-24 10:02 EST (History)
1 user (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2004-09-27 13:03:06 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Hui Huang 2003-04-16 18:33:39 EDT
Description of problem:

getpwuid_r() on RH-9 can return zero, indicating success, when in fact 
there was an error.

Version-Release number of selected component (if applicable):

stock RH-9, glibc-2.3.2-11.9

How reproducible:

always

Steps to Reproduce:
1. Compile and run this program, make sure limit on file descriptors
   is less than 1024 (so getpwuid_r should fail with EMFILE):

#include <stdio.h>
#include <pwd.h>
#include <unistd.h>
#include <sys/types.h>
#include <errno.h>
#include <string.h>
 
int main(void) {
  FILE *fd[1024];
  int i;
                                                                                
  for(i = 0; i < 1024; i++) {
    char buf[256];
    sprintf(buf, "/tmp/f%d", i);
    fd[i] = fopen(buf, "w");
  }
 
  int uid = geteuid();
 
  struct passwd pwent;
  struct passwd* p;
  char pwbuf[1024];
 
  errno = 0;
  int result = getpwuid_r(uid, &pwent, pwbuf, sizeof(pwbuf), &p);
 
  if (result == 0 && p == NULL)
    printf("getpwuid_r returns %d, but p is %p and errno = %d\n", result, p, errno);
  if (result != 0) { printf("getpwuid_r: %s\n", strerror(result)); }
 
  return 0;
}
    
Actual results:

on RH-9:

fez:~> g++ tstgetpwuid_r.cpp
fez:~> ./a.out
getpwuid_r returns 0, but p is (nil) and errno = 24

Expected results:

getpwuid_r should return non-zero value to indicate failure, for example,
on RH-7.3:

screen:~> ./a.out
getpwuid_r: Too many open files

Additional info:
Comment 1 Ulrich Drepper 2004-09-27 13:03:06 EDT
With the current glibc the expected result is seen.  Closing the bug now.

Note You need to log in before you can comment on or make changes to this bug.