diff options
| author | sin | 2017-08-22 11:31:49 +0100 |
|---|---|---|
| committer | sin | 2017-08-22 11:38:36 +0100 |
| commit | 9730e9d297068f7555621891072360c58095efc8 (patch) | |
| tree | 8f7f8e4aeb8d1e5b4ef143f463f04516945dfb34 /include/wchar.h | |
| parent | 2bc423c355a992fea2f95724235898218575c95e (diff) | |
Don't trap if an encoding error occurs in wcrtomb()
The POSIX definition of wcrtomb
(http://pubs.opengroup.org/onlinepubs/9699919799/functions/wcrtomb.html)
states:
"When wc is not a valid wide character, an encoding error shall occur.
In this case, the function shall store the value of the macro [EILSEQ]
in errno and shall return (size_t)-1; the conversion state shall be
undefined."
The fortify-headers implementation of wcrtomb interprets the result -1
as 18446744073709551615 bytes. Since this is the highest 64-bit number
possible, it is pretty safe to say this will always be larger than any
buffer provided to wcrtomb. Therefore, it traps.
Fixes bug https://bugs.alpinelinux.org/issues/7681.
Patch by A. Wilcox <AWilcox@Wilcox-Tech.com>
Diffstat (limited to 'include/wchar.h')
| -rw-r--r-- | include/wchar.h | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/include/wchar.h b/include/wchar.h index 08a817b..7394598 100644 --- a/include/wchar.h +++ b/include/wchar.h | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * Copyright (C) 2015-2016 Dimitris Papastamos <sin@2f30.org> | 2 | * Copyright (C) 2015-2017 Dimitris Papastamos <sin@2f30.org> |
| 3 | * | 3 | * |
| 4 | * Permission to use, copy, modify, and/or distribute this software for any | 4 | * Permission to use, copy, modify, and/or distribute this software for any |
| 5 | * purpose with or without fee is hereby granted. | 5 | * purpose with or without fee is hereby granted. |
| @@ -109,6 +109,8 @@ _FORTIFY_FN(wcrtomb) size_t wcrtomb(char *__s, wchar_t __w, mbstate_t *__st) | |||
| 109 | 109 | ||
| 110 | if (__s) { | 110 | if (__s) { |
| 111 | __r = __orig_wcrtomb(__buf, __w, __st); | 111 | __r = __orig_wcrtomb(__buf, __w, __st); |
| 112 | if (__r == (size_t)-1) | ||
| 113 | return __r; | ||
| 112 | if (__r > __b) | 114 | if (__r > __b) |
| 113 | __builtin_trap(); | 115 | __builtin_trap(); |
| 114 | memcpy(__s, __buf, __r); | 116 | memcpy(__s, __buf, __r); |
