summaryrefslogtreecommitdiff
path: root/Zend/zend_strtod.c
diff options
context:
space:
mode:
authorAntony Dovgal <tony2001@php.net>2007-04-22 21:33:10 +0000
committerAntony Dovgal <tony2001@php.net>2007-04-22 21:33:10 +0000
commitf6cef916bc36e60c3c92e09e9264a0a28d24a30d (patch)
treea0db47034fe37b3b652ba0171803c6f580822310 /Zend/zend_strtod.c
parente910699347be2deeaa1fada69b183bdace1d962a (diff)
downloadphp-git-f6cef916bc36e60c3c92e09e9264a0a28d24a30d.tar.gz
MFH: fix #41118 (PHP does not handle overflow of octal integers)
Diffstat (limited to 'Zend/zend_strtod.c')
-rw-r--r--Zend/zend_strtod.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/Zend/zend_strtod.c b/Zend/zend_strtod.c
index 94d1383aa2..49b591da14 100644
--- a/Zend/zend_strtod.c
+++ b/Zend/zend_strtod.c
@@ -2604,6 +2604,34 @@ ZEND_API double zend_hex_strtod(const char *str, char **endptr)
return value;
}
+ZEND_API double zend_oct_strtod(const char *str, char **endptr)
+{
+ const char *s = str;
+ char c;
+ double value = 0;
+ int any = 0;
+
+ /* skip leading zero */
+ s++;
+
+ while ((c = *s++)) {
+ if (c > '7') {
+ /* break and return the current value if the number is not well-formed
+ * that's what Linux strtol() does
+ */
+ break;
+ }
+ value = value * 8 + c - '0';
+ any = 1;
+ }
+
+ if (endptr != NULL) {
+ *endptr = (char *)(any ? s - 1 : str);
+ }
+
+ return value;
+}
+
/*
* Local variables:
* tab-width: 4