summaryrefslogtreecommitdiff
path: root/pith/charconv
diff options
context:
space:
mode:
authorEduardo Chappa <chappa@washington.edu>2019-03-29 09:49:05 -0600
committerEduardo Chappa <chappa@washington.edu>2019-03-29 09:49:05 -0600
commit3443fe5fcfcb33d3a2510111855e619632de57df (patch)
treec7fafde85d5d23e3e51a04f5cbc41a38297c2f6a /pith/charconv
parent0707eb6d0053079b4f91849bba2f8b6fc97391e8 (diff)
downloadalpine-3443fe5fcfcb33d3a2510111855e619632de57df.tar.xz
* Patches from Michał Dardas and Mateusz Kocielski from LogicalTrust
that fix the following startup crashes: * Crash when Alpine started with empty url fragment; * Crash when Alpine started with option last-time-prune-questioned in wrong format; * Crash when Alpine started with printf formatting characters from command line; and * Crash when Alpine started with an extremely long command line option. * Crash when Alpine is started with the wrong piped input when opening a folder from the command line. Reported by Mateusz Kocielski from LogicalTrust.
Diffstat (limited to 'pith/charconv')
-rw-r--r--pith/charconv/utf8.c18
1 files changed, 8 insertions, 10 deletions
diff --git a/pith/charconv/utf8.c b/pith/charconv/utf8.c
index 6613f4db..ef20e428 100644
--- a/pith/charconv/utf8.c
+++ b/pith/charconv/utf8.c
@@ -310,9 +310,10 @@ char *
convert_to_locale(char *utf8str)
{
#define CHNK 500
- char *inp, *retp, *ret = NULL;
+ char *inp, *ret = NULL;
CBUF_S cb;
- int r, alloced;
+ int alloced;
+ size_t i = 0;
if(native_utf8 || !utf8str || !utf8str[0])
return(NULL);
@@ -323,7 +324,6 @@ convert_to_locale(char *utf8str)
alloced = CHNK;
ret = (char *) fs_get(alloced * sizeof(char));
- retp = ret;
/*
* There's gotta be a better way to do this but utf8_to_locale was
@@ -337,20 +337,18 @@ convert_to_locale(char *utf8str)
* enough room for the next wide characters worth of output chars
* and allocate more space if not.
*/
- if((alloced - (retp-ret)) < MAX(MB_LEN_MAX,32)){
+ if((alloced - i) < MAX(MB_LEN_MAX,32)){
alloced += CHNK;
fs_resize((void **) &ret, alloced * sizeof(char));
}
- r = utf8_to_locale((int) *inp++, &cb,
- (unsigned char *) retp, alloced-(retp-ret));
-
- retp += r;
+ i += utf8_to_locale((int) *inp++, &cb,
+ (unsigned char *) &ret[i], alloced - i);
}
- *retp = '\0';
+ fs_resize((void **) &ret, i + 1);
- fs_resize((void **) &ret, strlen(ret)+1);
+ ret[i] = '\0';
return(ret);
}