diff options
author | Karl Williamson <khw@cpan.org> | 2016-07-13 22:06:30 -0600 |
---|---|---|
committer | Karl Williamson <khw@cpan.org> | 2016-07-14 16:10:10 -0600 |
commit | e1c30f0c87de26774c1fbe11ab7536e439285070 (patch) | |
tree | 48f6d84c6cb60393306324db4398f98bc2be8e88 /locale.c | |
parent | 7a0be72ee91841d7e4109296e11dc081097afbfe (diff) | |
download | perl-e1c30f0c87de26774c1fbe11ab7536e439285070.tar.gz |
PATCH: [perl #128628] divide by 0 in locale.c
It turned out to be possible to divide by 0 in Win32 when trying to find
the strxfrm() of an empty string. On other platforms, the result of
this is consistent with other strings, but on Windows, it is longer than
expected, and the code was trying to adapt to this, dividing by the
input length without checking its validity. This commit just skips the
adapting on a 0-length input.
Diffstat (limited to 'locale.c')
-rw-r--r-- | locale.c | 7 |
1 files changed, 6 insertions, 1 deletions
@@ -1779,7 +1779,12 @@ Perl__mem_collxfrm(pTHX_ const char *input_string, STRLEN needed = *xlen + 1; /* +1 For trailing NUL */ STRLEN computed_guess = PL_collxfrm_base + (PL_collxfrm_mult * length_in_chars); - const STRLEN new_m = needed / length_in_chars; + + /* On zero-length input, just keep current slope instead of + * dividing by 0 */ + const STRLEN new_m = (length_in_chars != 0) + ? needed / length_in_chars + : PL_collxfrm_mult; DEBUG_Lv(PerlIO_printf(Perl_debug_log, "%s: %d: initial size of %"UVuf" bytes for a length " |