From: Mark Spencer Date: Sat, 12 Mar 2005 06:56:22 +0000 (+0000) Subject: Fix TXTCIDName app (bug #3681) X-Git-Tag: 1.2.0-beta1~1087 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2dae49b723bfbae7f95bd1218090e873883e9df3;p=thirdparty%2Fasterisk.git Fix TXTCIDName app (bug #3681) git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@5175 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- diff --git a/enum.c b/enum.c index 5d9b4c6fa0..8ebc2a4419 100755 --- a/enum.c +++ b/enum.c @@ -268,9 +268,25 @@ static int txt_callback(void *context, u_char *answer, int len, u_char *fullansw c->txtlen = 0; return 0; } - strncpy(c->txt, answer, sizeof(c->txt) - 1); - c->txt[sizeof(c->txt) - 1] = 0; /* Make sure the string is terminated */ - c->txtlen = strlen(c->txt); + + /* skip over first byte, as for some reason it's a vertical tab character */ + answer += 1; + len -= 1; + + /* answer is not null-terminated, but should be */ + /* this is safe to do, as answer has extra bytes on the end we can + safely overwrite with a null */ + answer[len] = (u_char)"\0"; + /* now increment len so that len includes the null, so that we can + compare apples to apples */ + len +=1; + + /* finally, copy the answer into c->txt */ + strncpy(c->txt, answer, len < c->txtlen ? len-1 : (c->txtlen)-1); + + /* just to be safe, let's make sure c->txt is null terminated */ + c->txt[(c->txtlen)-1] = (char)"\0"; + return 1; }