[Cpu-users] [patch] segfault on records with no gecos
Brought to you by:
matheny
|
From: Johannes E. <joh...@er...> - 2002-05-26 23:12:45
|
I just recently grabbed CPU and after fighting to get it to build, it
segfaulted on "cpu cat". It turns out that the code makes quite a few
assumptions that aren't always true.
In this case, if the gecos field isn't part of the user's entry, the
random value from memory is derefernced and an oops will most likely
occur.
I've attached a patch to fix this. It simply zero's out the memory that
was allocated. It results in "(null)" being printed, but it's better
than segfault atleast.
It looks like much of the code is kinda sloppy. You can see from my
patch that simple things like checking if malloc succeeded or not is
ignored and that's not the only place I see that.
JE
Index: src/ldap.c
===================================================================
RCS file: /cvsroot/cpu/cpu-1.3/src/ldap.c,v
retrieving revision 1.12
diff -u -r1.12 ldap.c
--- src/ldap.c 7 May 2002 21:10:26 -0000 1.12
+++ src/ldap.c 26 May 2002 22:56:50 -0000
@@ -1409,6 +1409,8 @@
ldap_memfree(dn);
passentry = malloc(sizeof (struct passerd));
+ memset(passentry, 0, sizeof(*passentry));
+
for (a = ldap_first_attribute(ld, e, &ber); a != NULL;
a = ldap_next_attribute(ld, e, ber)) {
if ((vals = ldap_get_values(ld, e, a)) != NULL) {
|