apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n..@apache.org
Subject svn commit: r1836519 - /apr/apr/trunk/strings/apr_strings.c
Date Mon, 23 Jul 2018 22:28:23 GMT
Author: niq
Date: Mon Jul 23 22:28:23 2018
New Revision: 1836519

URL: http://svn.apache.org/viewvc?rev=1836519&view=rev
Log:
PR 62555: fix edge-case int overflow in apr_itoa

Modified:
    apr/apr/trunk/strings/apr_strings.c

Modified: apr/apr/trunk/strings/apr_strings.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/strings/apr_strings.c?rev=1836519&r1=1836518&r2=1836519&view=diff
==============================================================================
--- apr/apr/trunk/strings/apr_strings.c (original)
+++ apr/apr/trunk/strings/apr_strings.c Mon Jul 23 22:28:23 2018
@@ -362,19 +362,21 @@ APR_DECLARE(char *) apr_itoa(apr_pool_t
     const int BUFFER_SIZE = sizeof(int) * 3 + 2;
     char *buf = apr_palloc(p, BUFFER_SIZE);
     char *start = buf + BUFFER_SIZE - 1;
+    unsigned int un;
     int negative;
     if (n < 0) {
 	negative = 1;
-	n = -n;
+	un = -n;
     }
     else {
 	negative = 0;
+        un = n;
     }
     *start = 0;
     do {
-	*--start = '0' + (n % 10);
-	n /= 10;
-    } while (n);
+	*--start = '0' + (un % 10);
+	un /= 10;
+    } while (un);
     if (negative) {
 	*--start = '-';
     }
@@ -387,18 +389,20 @@ APR_DECLARE(char *) apr_ltoa(apr_pool_t
     char *buf = apr_palloc(p, BUFFER_SIZE);
     char *start = buf + BUFFER_SIZE - 1;
     int negative;
+    unsigned int un;
     if (n < 0) {
 	negative = 1;
-	n = -n;
+	un = -n;
     }
     else {
 	negative = 0;
+        un = n;
     }
     *start = 0;
     do {
-	*--start = (char)('0' + (n % 10));
-	n /= 10;
-    } while (n);
+	*--start = (char)('0' + (un % 10));
+	un /= 10;
+    } while (un);
     if (negative) {
 	*--start = '-';
     }



Mime
View raw message