From: Jaakko Heinonen Date: Thu, 25 Mar 2004 18:19:38 +0000 (+0000) Subject: fixed string truncation in mutt inport filter X-Git-Tag: upstream/0.6.1~2^2~214 X-Git-Url: https://git.deb.at/?a=commitdiff_plain;h=de8a5dd0af5a5834843ede7be64b55446afde572;p=pkg%2Fabook.git fixed string truncation in mutt inport filter --- diff --git a/filter.c b/filter.c index 9f57ee9..a12ddc7 100644 --- a/filter.c +++ b/filter.c @@ -618,6 +618,7 @@ static int mutt_read_line(FILE *in, char **alias, char **rest) { char *line, *ptr, *tmp; + size_t alias_len; if( !(line = ptr = getaline(in)) ) return 1; /* error / EOF */ @@ -640,13 +641,16 @@ mutt_read_line(FILE *in, char **alias, char **rest) while( ! ISSPACE(*ptr) ) ptr++; - if( (*alias = (char *)malloc(ptr - tmp)) == NULL) { + /* includes also the trailing zero */ + alias_len = (size_t)(ptr - tmp + 1); + + if( (*alias = (char *)malloc(alias_len)) == NULL) { free(line); return 1; } - strncpy(*alias, tmp, ptr - tmp - 1); - *(*alias + (ptr - tmp - 1)) = 0; + strncpy(*alias, tmp, alias_len - 1); + *(*alias + alias_len - 1) = 0; while(ISSPACE(*ptr)) ptr++;