X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/3dc0fe0bcb41205700cf9229cb6d7bbfd95a3c2a..5f34de43:/sbr/escape_addresses.c?ds=sidebyside diff --git a/sbr/escape_addresses.c b/sbr/escape_addresses.c index 43bf1a29..11a4faa3 100644 --- a/sbr/escape_addresses.c +++ b/sbr/escape_addresses.c @@ -1,12 +1,11 @@ -/* - * escape_addresses.c -- Escape address components, hopefully per RFC 5322. +/* escape_addresses.c -- Escape address components, hopefully per RFC 5322. * * This code is Copyright (c) 2012, by the authors of nmh. See the * COPYRIGHT file in the root directory of the nmh distribution for * complete copyright information. */ -#include +#include #include static void @@ -43,7 +42,7 @@ escape_component (char *name, size_t namesize, char *chars_to_escape) { if (strpbrk(name, chars_to_escape)) { char *destp, *srcp; /* Maximum space requirement would be if each character had - to be escaped, plus enclosing double quotes, plus null termintor. + to be escaped, plus enclosing double quotes, plus NUL terminator. E.g., 2 characters, "", would require 7, "\"\""0, where that 0 is '\0'. */ char *tmp = mh_xmalloc (2*strlen(name) + 3); @@ -77,7 +76,7 @@ escape_component (char *name, size_t namesize, char *chars_to_escape) { if (strcmp (tmp, "\"")) { size_t len = destp - tmp; assert ((ssize_t) strlen(tmp) + 1 == destp - tmp); - strncpy (name, tmp, len <= namesize ? len : namesize); + strncpy (name, tmp, min(len, namesize)); } else { /* Handle just " as special case here instead of above. */ strncpy (name, "\"\\\"\"", namesize);