From d443933d9874260e1034a9405b5065ca852f93a0 Mon Sep 17 00:00:00 2001 From: serassio <> Date: Sun, 23 Jan 2005 21:55:45 +0000 Subject: [PATCH] Bug #1197: DNS related memory leak on certain malformed DNS responses --- lib/rfc1035.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/rfc1035.c b/lib/rfc1035.c index f0c9417cad..05db4762fa 100644 --- a/lib/rfc1035.c +++ b/lib/rfc1035.c @@ -1,6 +1,6 @@ /* - * $Id: rfc1035.c,v 1.33 2005/01/23 14:53:23 serassio Exp $ + * $Id: rfc1035.c,v 1.34 2005/01/23 14:55:45 serassio Exp $ * * Low level DNS protocol routines * AUTHOR: Duane Wessels @@ -554,11 +554,10 @@ rfc1035AnswersUnpack(const char *buf, return -rfc1035_unpack_error; } } - i = (int) hdr.ancount; - if (i == 0) + if (hdr.ancount == 0) return 0; - recs = calloc(i, sizeof(*recs)); - while (i--) { + recs = calloc((int)hdr.ancount, sizeof(*recs)); + for (i = 0; i < (int)hdr.ancount; i++) { if (off >= sz) { /* corrupt packet */ RFC1035_UNPACK_DEBUG; break; -- 2.47.3