Commit 21fb9ca7 21fb9ca7326589a8ad8d0f2b5247e7a73ad62622 by Sergey Poznyakoff

(header_readline): Always nul-terminate the buffer.

1 parent 7aa6a66b
...@@ -985,7 +985,7 @@ header_readline (mu_stream_t is, char *buffer, size_t buflen, ...@@ -985,7 +985,7 @@ header_readline (mu_stream_t is, char *buffer, size_t buflen,
985 int status; 985 int status;
986 size_t strsize; 986 size_t strsize;
987 987
988 if (is == NULL) 988 if (is == NULL || buflen == 0)
989 return EINVAL; 989 return EINVAL;
990 990
991 header = mu_stream_get_owner (is); 991 header = mu_stream_get_owner (is);
...@@ -1001,10 +1001,12 @@ header_readline (mu_stream_t is, char *buffer, size_t buflen, ...@@ -1001,10 +1001,12 @@ header_readline (mu_stream_t is, char *buffer, size_t buflen,
1001 } 1001 }
1002 1002
1003 strsize = MU_STR_SIZE (ent->nlen, ent->vlen) - ent_off; 1003 strsize = MU_STR_SIZE (ent->nlen, ent->vlen) - ent_off;
1004 buflen--; /* Account for the terminating nul */
1004 if (buflen > strsize) 1005 if (buflen > strsize)
1005 buflen = strsize; 1006 buflen = strsize;
1006 mu_hdrent_fixup (header, ent); 1007 mu_hdrent_fixup (header, ent);
1007 memcpy (buffer, MU_HDRENT_NAME (header, ent) + ent_off, buflen); 1008 memcpy (buffer, MU_HDRENT_NAME (header, ent) + ent_off, buflen);
1009 buffer[buflen] = 0;
1008 mu_hdrent_unroll_fixup (header, ent); 1010 mu_hdrent_unroll_fixup (header, ent);
1009 if (pnread) 1011 if (pnread)
1010 *pnread = buflen; 1012 *pnread = buflen;
......