From 08d44987794fd798f1f68f59a5cd93591dabba44 Mon Sep 17 00:00:00 2001 From: Wilfried Goesgens Date: Fri, 25 May 2012 12:22:57 +0200 Subject: [PATCH] fix possible nullpointer dereferenciation; tnx to the clang static analyzer --- citadel/locate_host.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/citadel/locate_host.c b/citadel/locate_host.c index fa8cfad2f..39309e943 100644 --- a/citadel/locate_host.c +++ b/citadel/locate_host.c @@ -146,7 +146,7 @@ int rblcheck_backend(char *domain, char *txtbuf, int txtbufsize) { if( len == -1 ) { if (txtbuf != NULL) { snprintf(txtbuf, txtbufsize, - "Message rejected due to known spammer source IP address"); + "Message rejected due to known spammer source IP address"); } if (need_to_free_answer) free(answer); return(1); @@ -184,7 +184,7 @@ int rblcheck_backend(char *domain, char *txtbuf, int txtbufsize) { { if (txtbuf != NULL) { snprintf(txtbuf, txtbufsize, - "Message rejected due to known spammer source IP address"); + "Message rejected due to known spammer source IP address"); } if (need_to_free_answer) free(answer); free(result); @@ -235,11 +235,17 @@ int rblcheck_backend(char *domain, char *txtbuf, int txtbufsize) { } *rp = '\0'; if (txtbuf != NULL) { - snprintf(txtbuf, txtbufsize, "%s", result); - } - /* Remove nonprintable characters */ - for (p=txtbuf; *p; ++p) { - if (!isprint(*p)) strcpy(p, p+1); + long len; + len = snprintf(txtbuf, txtbufsize, "%s", result); + + /* Remove nonprintable characters */ + for (p = txtbuf; *p != '\0'; p++) { + if (!isprint(*p)) { + memmove (p, + p + 1, + len - (p - txtbuf) - 1); + } + } } if (need_to_free_answer) free(answer); free(result); -- 2.30.2