Bug 89052 - getpwuid_r on RH-9 may return 0 when in fact there was an error
Summary: getpwuid_r on RH-9 may return 0 when in fact there was an error
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: glibc
Version: 9
Hardware: All
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2003-04-16 22:33 UTC by Hui Huang
Modified: 2016-11-24 15:02 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2004-09-27 17:03:06 UTC
Embargoed:


Attachments (Terms of Use)

Description Hui Huang 2003-04-16 22:33:39 UTC
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 17:03:06 UTC
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.