Prevent buffer underruns caused by functions that can return -1.
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);
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,
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)