Skip to content

Commit 9e8bcf8

Browse files
authored
Merge pull request #2 from twose/patch-1
Another way
2 parents 0b32baf + d081a74 commit 9e8bcf8

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

ext/standard/url.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,11 @@ PHPAPI php_url *php_url_parse_ex(char const *str, size_t length)
194194

195195
if (pp - p > 0 && pp - p < 6 && (pp == ue || *pp == '/')) {
196196
zend_long port;
197+
char *end;
197198
memcpy(port_buf, p, (pp - p));
198199
port_buf[pp - p] = '\0';
199-
port = ZEND_STRTOL(port_buf, NULL, 10);
200-
if (port > 0 && port <= 65535) {
200+
port = ZEND_STRTOL(port_buf, &end, 10);
201+
if (port >= 0 && port <= 65535 && end != port_buf) {
201202
ret->port = (unsigned short) port;
202203
if (s + 1 < ue && *s == '/' && *(s + 1) == '/') { /* relative-scheme URL */
203204
s += 2;
@@ -258,10 +259,11 @@ PHPAPI php_url *php_url_parse_ex(char const *str, size_t length)
258259
return NULL;
259260
} else if (e - p > 0) {
260261
zend_long port;
262+
char *end;
261263
memcpy(port_buf, p, (e - p));
262264
port_buf[e - p] = '\0';
263-
port = ZEND_STRTOL(port_buf, NULL, 10);
264-
if ((port > 0 && port <= 65535) || (port == 0 && *port_buf == '0' && e - p == 1)) {
265+
port = ZEND_STRTOL(port_buf, &end, 10);
266+
if (port >= 0 && port <= 65535 && end != port_buf) {
265267
ret->port = (unsigned short)port;
266268
} else {
267269
php_url_free(ret);

0 commit comments

Comments
 (0)