Skip to content

Commit 085999c

Browse files
committed
Merge branch 'PHP-7.2'
* PHP-7.2: Update NEWS Fixed bug #76143 (Memory corruption: arbitrary NUL overwrite)
2 parents 14de058 + 22a8ea2 commit 085999c

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

sapi/phpdbg/phpdbg_io.c

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ PHPDBG_API int phpdbg_create_listenable_socket(const char *addr, unsigned short
290290
}
291291
}
292292

293-
snprintf(port_buf, 7, "%u", port);
293+
snprintf(port_buf, sizeof(port_buf), "%u", port);
294294
if (!any_addr) {
295295
rc = getaddrinfo(addr, port_buf, &hints, &res);
296296
} else {
@@ -301,20 +301,18 @@ PHPDBG_API int phpdbg_create_listenable_socket(const char *addr, unsigned short
301301
#ifndef PHP_WIN32
302302
if (rc == EAI_SYSTEM) {
303303
char buf[128];
304-
int wrote;
305304

306-
wrote = snprintf(buf, 128, "Could not translate address '%s'", addr);
307-
buf[wrote] = '\0';
305+
snprintf(buf, sizeof(buf), "Could not translate address '%s'", addr);
306+
308307
zend_quiet_write(PHPDBG_G(io)[PHPDBG_STDERR].fd, buf, strlen(buf));
309308

310309
return sock;
311310
} else {
312311
#endif
313312
char buf[256];
314-
int wrote;
315313

316-
wrote = snprintf(buf, 256, "Host '%s' not found. %s", addr, estrdup(gai_strerror(rc)));
317-
buf[wrote] = '\0';
314+
snprintf(buf, sizeof(buf), "Host '%s' not found. %s", addr, estrdup(gai_strerror(rc)));
315+
318316
zend_quiet_write(PHPDBG_G(io)[PHPDBG_STDERR].fd, buf, strlen(buf));
319317

320318
return sock;
@@ -324,13 +322,10 @@ PHPDBG_API int phpdbg_create_listenable_socket(const char *addr, unsigned short
324322
return sock;
325323
}
326324

327-
if((sock = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) == -1) {
328-
char buf[128];
329-
int wrote;
325+
if ((sock = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) == -1) {
326+
const char *msg = "Unable to create socket";
330327

331-
wrote = sprintf(buf, "Unable to create socket");
332-
buf[wrote] = '\0';
333-
zend_quiet_write(PHPDBG_G(io)[PHPDBG_STDERR].fd, buf, strlen(buf));
328+
zend_quiet_write(PHPDBG_G(io)[PHPDBG_STDERR].fd, msg, strlen(msg));
334329

335330
return sock;
336331
}

0 commit comments

Comments
 (0)