(header_readline): Always nul-terminate the buffer.
Showing
1 changed file
with
3 additions
and
1 deletions
... | @@ -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; | ... | ... |
-
Please register or sign in to post a comment