com php-src: fix int overflow preserving the old behavior: ext/standard/strnatcmp.c
| From: | Anatol Belski | Date: | Sun, 14 Sep 2014 14:39:25 +0000 |
| Subject: | com php-src: fix int overflow preserving the old behavior: ext/standard/strnatcmp.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-81610@lists.php.net to get a copy of this message | ||
Commit: 29f8b21cd71bc4af1ead7b8a93cfe09338d2eff5
Author: Anatol Belski <ab@php.net> Sun, 14 Sep 2014 16:37:38 +0200
Parents: eda5ba1f8fa935b8d1b8bae9d189c6afbe833287
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=29f8b21cd71bc4af1ead7b8a93cfe09338d2eff5
Log:
fix int overflow preserving the old behavior
Changed paths:
M ext/standard/strnatcmp.c
Diff:
diff --git a/ext/standard/strnatcmp.c b/ext/standard/strnatcmp.c
index face191...7b3826b 100644
--- a/ext/standard/strnatcmp.c
+++ b/ext/standard/strnatcmp.c
@@ -108,8 +108,25 @@ PHPAPI int strnatcmp_ex(char const *a, size_t a_len, char const *b, size_t
b_len
int fractional, result;
short leading = 1;
- if (a_len == 0 || b_len == 0)
- return a_len - b_len;
+ if (a_len == 0 || b_len == 0) {
+ result = 0;
+
+ if (a_len > b_len) {
+ if (a_len - b_len <= INT_MAX) {
+ result = (int)(a_len - b_len);
+ } else {
+ result = 1;
+ }
+ } else {
+ if (b_len - a_len <= (size_t)(-INT_MIN)) {
+ result = -(int)(b_len - a_len);
+ } else {
+ result = -1;
+ }
+ }
+
+ return result;
+ }
ap = a;
bp = b;