From: David Vossel Date: Fri, 6 Nov 2009 15:41:41 +0000 (+0000) Subject: fixes crash in astfd.c X-Git-Tag: 1.4.27-rc3~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=15d78bc88bac9e53725caab60b7d92ce0a89ec9e;p=thirdparty%2Fasterisk.git fixes crash in astfd.c (closes issue #15981) Reported by: slavon git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.4@228338 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- diff --git a/main/astfd.c b/main/astfd.c index ca852133e0..26d95ee0f9 100644 --- a/main/astfd.c +++ b/main/astfd.c @@ -130,15 +130,16 @@ int __ast_fdleak_pipe(int *fds, const char *file, int line, const char *func) #undef socket int __ast_fdleak_socket(int domain, int type, int protocol, const char *file, int line, const char *func) { - char sdomain[20], stype[20], *sproto; + char sdomain[20], stype[20], *sproto = NULL; struct protoent *pe; int res = socket(domain, type, protocol); if (res < 0 || res > 1023) { return res; } - pe = getprotobynumber(protocol); - sproto = pe->p_name; + if ((pe = getprotobynumber(protocol))) { + sproto = pe->p_name; + } if (domain == PF_UNIX) { ast_copy_string(sdomain, "PF_UNIX", sizeof(sdomain)); @@ -162,7 +163,11 @@ int __ast_fdleak_socket(int domain, int type, int protocol, const char *file, in snprintf(stype, sizeof(stype), "%d", type); } - STORE_COMMON(res, "socket", "%s,%s,\"%s\"", sdomain, stype, sproto); + if (sproto) { + STORE_COMMON(res, "socket", "%s,%s,\"%s\"", sdomain, stype, sproto); + } else { + STORE_COMMON(res, "socket", "%s,%s,\"%d\"", sdomain, stype, protocol); + } return res; }