|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79570 ZTS build of PHP 7.3.17 doesn't handle ERANGE for posix_getgrgid and others
Submitted: 2020-05-06 06:53 UTC Modified: 2020-05-06 07:10 UTC
From: zboszor at pr dot hu Assigned:
Status: Closed Package: POSIX related
PHP Version: 7.3.17 OS: Linux
Private report: No CVE-ID: None
 [2020-05-06 06:53 UTC] zboszor at pr dot hu
ZTS build of PHP uses getgrnam_r, getgrgid_r, getpwnam_r and getpwuid_r
behind their respective posix_* functions. These functions may return ERANGE
if the buffer supplied by the caller is too small.
sysconf() returns 1024 for _SC_GETGR_R_SIZE_MAX and _SC_GETPW_R_SIZE_MAX.
Only posix_getgrnam calling getgrnam_r handles ERANGE properly by
retrying with a larger buffer.
This was noticed on a system with a group containing many users, so
the respective line in /etc/group exceeded 2KB.

Test script:
  $i = 200; /* a GID that has a very long line in /etc/group */
  $data = posix_getgrgid($i);
  $error_num = posix_get_last_error();
  if ($error_num > 0) {
    echo "\nERROR NUM = $error_num\n";
    echo "ERROR MES = " . posix_strerror($error_num) . "\n\n";
  } else {
    printf("%s\n", $data["name"]);

Expected result:
The group name should be printed.

Actual result:
Error number 34 (ERANGE) is printed.


php-7.3-fix-posix-fns-with-zts.patch (last revision 2020-05-06 06:53 UTC by zboszor at pr dot hu)

Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2020-05-06 07:10 UTC]
-Status: Open +Status: Verified
 [2020-05-06 07:10 UTC]
Thanks for reporting!  This has been missed when fixing bug
 [2020-06-17 17:59 UTC]
Can you submit the attached patch as a pull request to php-src in GitHub? Perhaps it may get more attention there. If you do not want to do this, I could also submit it on your behalf and credit you in the commit message.
 [2020-06-19 15:33 UTC]
Automatic comment on behalf of
Log: Fixed bug #79570
 [2020-06-19 15:33 UTC]
-Status: Verified +Status: Closed
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Apr 22 07:01:29 2024 UTC