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;