Patch for incorrect use of strlcat
authorKrista Grothoff <krista@pep-project.org>
Wed, 27 Jul 2016 23:22:48 +0200
changeset 9359fb6e8fc131f
parent 934 6ec71cdedec1
child 936 c3f114016a81
child 941 0bb60c4a805b
Patch for incorrect use of strlcat
src/message_api.c
     1.1 --- a/src/message_api.c	Wed Jul 27 16:20:31 2016 +0200
     1.2 +++ b/src/message_api.c	Wed Jul 27 23:22:48 2016 +0200
     1.3 @@ -102,21 +102,20 @@
     1.4      if (longmsg == NULL)
     1.5          longmsg = "";
     1.6  
     1.7 -    size_t bufsize = strlen(shortmsg) + strlen(longmsg) + 12;
     1.8 +    const char * const subject = "Subject: ";
     1.9 +    const size_t SUBJ_LEN = 9;
    1.10 +    const char * const newlines = "\n\n";
    1.11 +    const size_t NL_LEN = 2;
    1.12 +
    1.13 +    size_t bufsize = SUBJ_LEN + strlen(shortmsg) + NL_LEN + strlen(longmsg) + 1;
    1.14      ptext = calloc(1, bufsize);
    1.15      assert(ptext);
    1.16      if (ptext == NULL)
    1.17          return NULL;
    1.18  
    1.19 -    strlcpy(ptext, "Subject: ", bufsize);
    1.20 -    bufsize -= 9;
    1.21 -    
    1.22 +    strlcpy(ptext, subject, bufsize);
    1.23      strlcat(ptext, shortmsg, bufsize);
    1.24 -    bufsize -= strlen(shortmsg);
    1.25 -    
    1.26 -    strlcat(ptext, "\n\n", bufsize);
    1.27 -    bufsize -= 2;
    1.28 -    
    1.29 +    strlcat(ptext, newlines, bufsize);
    1.30      strlcat(ptext, longmsg, bufsize);
    1.31  
    1.32      return ptext;