This is the mail archive of the
glibc-bugs@sourceware.org
mailing list for the glibc project.
[Bug nss/24696] New: endgrent() clobbers errno=ERRNO for 'group: db files' entry in /etc/nsswitch.conf
- From: "slyfox at inbox dot ru" <sourceware-bugzilla at sourceware dot org>
- To: glibc-bugs at sourceware dot org
- Date: Mon, 17 Jun 2019 21:26:10 +0000
- Subject: [Bug nss/24696] New: endgrent() clobbers errno=ERRNO for 'group: db files' entry in /etc/nsswitch.conf
- Auto-submitted: auto-generated
https://sourceware.org/bugzilla/show_bug.cgi?id=24696
Bug ID: 24696
Summary: endgrent() clobbers errno=ERRNO for 'group: db files'
entry in /etc/nsswitch.conf
Product: glibc
Version: 2.29
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: nss
Assignee: unassigned at sourceware dot org
Reporter: slyfox at inbox dot ru
Target Milestone: ---
The bug is originally reported by Guillermo D. H. at
https://bugs.gentoo.org/688246.
Here is the reproducer:
$ cat /etc/nsswitch.conf
passwd: files
#group: files
#https://bugs.gentoo.org/688246
group: db files
initgroups: files
shadow: files
gshadow: files
hosts: files dns
networks: files dns
protocols: db files
services: db files
ethers: db files
rpc: db files
netgroup: db files
$ cat a.c
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <grp.h>
int main() {
int saved_errno;
for (;;) {
errno = 0;
struct group *gr = getgrent();
saved_errno = errno;
if (!gr)
break;
}
printf("(errno = %s)\n", strerror(saved_errno));
printf("errno before endgrent() = %s\n", strerror(errno));
endgrent();
printf("errno after endgrent() = %s\n", strerror(errno));
}
$ gcc a.c -o a
$ ./a
(errno = Success)
errno before endgrent() = Success
errno after endgrent() = Invalid argument <- the bug
The following workaround seems to be enough:
--- a/nss/nss_db/db-open.c
+++ b/nss/nss_db/db-open.c
@@ -63,5 +63,9 @@ internal_setent (const char *file, struct nss_db_map
*mapping)
void
internal_endent (struct nss_db_map *mapping)
{
- munmap (mapping->header, mapping->len);
+ /* Avoid clobbering errno if 'header' was never allocated. */
+ if (mapping->header != NULL)
+ {
+ munmap (mapping->header, mapping->len);
+ }
}
--
You are receiving this mail because:
You are on the CC list for the bug.