Merged in ENGINE-207 fixes
authorKrista Bennett <krista@pep-project.org>
Mon, 08 May 2017 15:53:41 +0200
changeset 1758328b0c920ec4
parent 1750 33b2fa2368e6
parent 1756 f46ce946ede9
child 1763 8428975706d9
Merged in ENGINE-207 fixes
     1.1 --- a/src/message_api.c	Thu May 04 16:57:23 2017 +0200
     1.2 +++ b/src/message_api.c	Mon May 08 15:53:41 2017 +0200
     1.3 @@ -1458,8 +1458,8 @@
     1.4  
     1.5      char* curr_line = signpost;
     1.6  //    const char* end_text = ptext + psize;
     1.7 -    const char* boundary_key = "boundary=\"";
     1.8 -    const size_t BOUNDARY_KEY_SIZE = 10;
     1.9 +    const char* boundary_key = "boundary=";
    1.10 +    const size_t BOUNDARY_KEY_SIZE = 9;
    1.11  
    1.12      char* start_boundary = strstr(curr_line, boundary_key);
    1.13      if (!start_boundary)
    1.14 @@ -1467,11 +1467,17 @@
    1.15  
    1.16      start_boundary += BOUNDARY_KEY_SIZE;
    1.17  
    1.18 -    char* end_boundary = strstr(start_boundary, "\"");
    1.19 +    bool quoted = (*start_boundary == '"');
    1.20 +
    1.21 +    if (quoted)
    1.22 +        start_boundary++;
    1.23 +        
    1.24 +    char* end_boundary = (quoted ? strstr(start_boundary, "\"") : strstr(start_boundary, ";")); // FIXME: third possiblity is CRLF, or?
    1.25  
    1.26      if (!end_boundary)
    1.27          return PEP_UNKNOWN_ERROR;
    1.28  
    1.29 +    // Add space for the "--"
    1.30      size_t boundary_strlen = (end_boundary - start_boundary) + 2;
    1.31  
    1.32      signed_boundary = calloc(1, boundary_strlen + 1);
    1.33 @@ -1485,7 +1491,11 @@
    1.34  
    1.35      start_boundary += boundary_strlen;
    1.36  
    1.37 -    while (*start_boundary == '\n')
    1.38 +    if (*start_boundary == '\r') {
    1.39 +        if (*(start_boundary + 1) == '\n')
    1.40 +            start_boundary += 2;
    1.41 +    }
    1.42 +    else if (*start_boundary == '\n')
    1.43          start_boundary++;
    1.44  
    1.45      end_boundary = strstr(start_boundary + boundary_strlen, signed_boundary);
    1.46 @@ -1493,7 +1503,7 @@
    1.47      if (!end_boundary)
    1.48          return PEP_UNKNOWN_ERROR;
    1.49  
    1.50 -    end_boundary--; // See RFC3156 section 5...
    1.51 +    end_boundary--; // See RFC3156 section 5... FIXME: could be 2? CRLF?
    1.52  
    1.53      *ssize = end_boundary - start_boundary;
    1.54      *stext = start_boundary;