1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-03-21 22:50:08 +03:00

Check for integer overflow in xmlXPathFormatNumber

Check for overflow before casting double to int.

Found with afl-fuzz and UBSan.
This commit is contained in:
Nick Wellnhofer 2017-06-01 22:00:19 +02:00
parent 863b57925a
commit 7482f41f61
5 changed files with 22 additions and 1 deletions

View File

@ -242,3 +242,11 @@ Object is a number : -1
========================
Expression: 8 mod 3 = 2
Object is a Boolean : true
========================
Expression: 12345678901234567890
Object is a number : 1.23457e+19
========================
Expression: -12345678901234567890
Object is a number : -1.23457e+19

View File

@ -19,6 +19,14 @@ Object is a string : true
Expression: string(false())
Object is a string : false
========================
Expression: string(12345678901234567890)
Object is a string : 1.23456789012346e+19
========================
Expression: string(-12345678901234567890)
Object is a string : -1.23456789012346e+19
========================
Expression: concat("titi","toto")
Object is a string : tititoto

View File

@ -59,3 +59,5 @@ number('f') div 1
-5 mod 2
-5 mod -2
8 mod 3 = 2
12345678901234567890
-12345678901234567890

View File

@ -3,6 +3,8 @@ string(0.5)
string(-0.5)
string(true())
string(false())
string(12345678901234567890)
string(-12345678901234567890)
concat("titi","toto")
concat("titi","toto","tata")
concat("titi",'toto')

View File

@ -3106,7 +3106,8 @@ xmlXPathFormatNumber(double number, char buffer[], int buffersize)
snprintf(buffer, buffersize, "NaN");
} else if (number == 0 && xmlXPathGetSign(number) != 0) {
snprintf(buffer, buffersize, "0");
} else if (number == ((int) number)) {
} else if ((number > INT_MIN) && (number < INT_MAX) &&
(number == (int) number)) {
char work[30];
char *ptr, *cur;
int value = (int) number;