From 0adfceef87e86d43b8a9c6722f46a94d2581b840 Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Tue, 19 Aug 2014 21:52:38 +0200 Subject: [PATCH] Fix strtol("0xz", &s, 16) handling. Found by musl's libc-test. --- libc/stdlib/strtol.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libc/stdlib/strtol.cpp b/libc/stdlib/strtol.cpp index d20655fe..49b8c3b6 100644 --- a/libc/stdlib/strtol.cpp +++ b/libc/stdlib/strtol.cpp @@ -164,7 +164,8 @@ STRTOL_INT STRTOL(const STRTOL_CHAR* restrict str, // Skip the leading '0x' prefix in base 16 for hexadecimal integers. if ( origbase == 16 && str[0] == STRTOL_L('0') && - (str[1] == STRTOL_L('x') || str[1] == STRTOL_L('X')) ) + (str[1] == STRTOL_L('x') || str[1] == STRTOL_L('X')) && + (0 <= debase(str[2]) && debase(str[2]) < 16) ) str += 2; // Determine what value will be returned on overflow/underflow.