ENGINE-857: Fixed charconv error. Release_2.1 Release_2.1.8
authorKrista 'DarthMama' Bennett <krista@pep.foundation>
Mon, 23 Nov 2020 18:32:40 +0100
branchRelease_2.1
changeset 5203409acbc8b230
parent 5201 bc6ccf6c3194
child 5204 d2eb4277849a
ENGINE-857: Fixed charconv error.
src/etpan_mime.c
     1.1 --- a/src/etpan_mime.c	Thu Nov 19 12:57:56 2020 +0100
     1.2 +++ b/src/etpan_mime.c	Mon Nov 23 18:32:40 2020 +0100
     1.3 @@ -2494,9 +2494,10 @@
     1.4  
     1.5      if (part->mm_content_type) {
     1.6          if (_get_content_type(part->mm_content_type, &type, &charset) == 0) {
     1.7 -            if (charset && strncasecmp(charset, "utf-8", 5) != 0) {
     1.8 +            if (charset && (strlen(charset) < 5 || strncasecmp(charset, "utf-8", 5) != 0)) {
     1.9                  char * _text;
    1.10 -                int r = charconv("utf-8", charset, _longmsg, _size, &_text);
    1.11 +                size_t new_size;
    1.12 +                int r = charconv_buffer("utf-8", charset, _longmsg, _size, &_text, &new_size);
    1.13                  switch (r) {
    1.14                      case MAILIMF_NO_ERROR:
    1.15                          break;
    1.16 @@ -2506,13 +2507,16 @@
    1.17                          return PEP_ILLEGAL_VALUE;
    1.18                  }
    1.19                  free(_longmsg);
    1.20 -                _longmsg = _text;
    1.21 +                _longmsg = (char*)(malloc(new_size));
    1.22 +                if (!_longmsg || !memcpy(_longmsg, _text, new_size))
    1.23 +                    return PEP_OUT_OF_MEMORY;
    1.24 +                charconv_buffer_free(_text);
    1.25 +                _size = new_size;
    1.26              }
    1.27          }
    1.28      }
    1.29      // FIXME: KG - we now have the text we want.
    1.30      // Now we need to strip sigs and process them if they are there..
    1.31 -    
    1.32  
    1.33      *longmsg = _longmsg;
    1.34      if (size)