From d6cb75e1d24bea83ccd68ad4d9499a9c78004800 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Tue, 30 Nov 2004 00:14:06 +0000 Subject: [PATCH] fix possible segfault in sigar_group_name_get --- ChangeLog | 4 ++++ src/sigar.c | 12 +++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index b494e710..e946ef40 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2004-11-29 Doug MacEachern + + * fix possible segfault in sigar_group_name_get if gid == -1 + 2004-11-22 Doug MacEachern * fix bug in RegistryKey.openSubKey under WebSphere 4.0 jdk diff --git a/src/sigar.c b/src/sigar.c index 26228714..39215059 100644 --- a/src/sigar.c +++ b/src/sigar.c @@ -263,7 +263,17 @@ int sigar_group_name_get(sigar_t *sigar, int gid, char *buf, int buflen) } # endif - strncpy(buf, gr->gr_name, buflen); + if (gr && gr->gr_name) { + strncpy(buf, gr->gr_name, buflen); + } + else { + /* seen on linux.. apache httpd.conf has: + * Group #-1 + * results in uid == -1 and gr == NULL. + * wtf getgrgid_r doesnt fail instead? + */ + sprintf(buf, "%d", gid); + } buf[buflen-1] = '\0'; return SIGAR_OK;