From: Richard Russon Date: Wed, 5 Apr 2017 14:34:28 +0000 (+0100) Subject: coverity: check for buffer underruns X-Git-Tag: neomutt-20170414~10^2~2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a6dc2846300a025c5c2ab30591a69ccf7de9bf8f;p=neomutt coverity: check for buffer underruns Prevent buffer underruns caused by functions that can return -1. --- diff --git a/bcache.c b/bcache.c index a61cc8b88..d9937f09a 100644 --- a/bcache.c +++ b/bcache.c @@ -65,9 +65,13 @@ static int bcache_path(ACCOUNT *account, const char *mailbox, mutt_encode_path (path, sizeof (path), NONULL (mailbox)); + int plen = mutt_strlen(path); + if (plen == 0) + return -1; + len = snprintf (dst, dstlen-1, "%s/%s%s%s", MessageCachedir, host, path, - (*path && path[mutt_strlen (path) - 1] == '/') ? "" : "/"); + (*path && path[plen - 1] == '/') ? "" : "/"); mutt_debug (3, "bcache_path: rc: %d, path: '%s'\n", len, dst); diff --git a/copy.c b/copy.c index e8cf4960d..8f01e8c01 100644 --- a/copy.c +++ b/copy.c @@ -553,12 +553,16 @@ _mutt_copy_message (FILE *fpout, FILE *fpin, HEADER *hdr, BODY *body, char date[SHORT_STRING]; mutt_make_date (date, sizeof (date)); - date[5] = date[mutt_strlen (date) - 1] = '\"'; + int dlen = mutt_strlen(date); + if (dlen == 0) + return -1; + + date[5] = '\"'; + date[dlen - 1] = '\"'; /* Count the number of lines and bytes to be deleted */ fseeko (fpin, body->offset, SEEK_SET); - new_lines = hdr->lines - - count_delete_lines (fpin, body, &new_length, mutt_strlen (date)); + new_lines = hdr->lines - count_delete_lines(fpin, body, &new_length, dlen); /* Copy the headers */ if (mutt_copy_header (fpin, hdr, fpout, diff --git a/init.c b/init.c index 7bcca0545..83a61adf1 100644 --- a/init.c +++ b/init.c @@ -3287,7 +3287,11 @@ int mutt_var_value_complete (char *buffer, size_t len, int pos) strfcpy (var, pt, sizeof (var)); /* ignore the trailing '=' when comparing */ - var[mutt_strlen (var) - 1] = 0; + int vlen = mutt_strlen(var); + if (vlen == 0) + return 0; + + var[vlen - 1] = 0; if ((idx = mutt_option_index (var)) == -1) { if ((myvarval = myvar_get(var)) != NULL)