Skip to content

Commit 82b6ccb

Browse files
committed
fix memory leak and possible invalid reads
1 parent 8068342 commit 82b6ccb

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

sapi/isapi/php5isapi.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,14 +279,18 @@ static int sapi_isapi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC)
279279
break;
280280
default: {
281281
const char *sline = SG(sapi_headers).http_status_line;
282-
283-
status_buf = emalloc(MAX_STATUS_LENGTH + 1);
282+
int sline_len;
284283

285284
/* httpd requires that r->status_line is set to the first digit of
286285
* the status-code: */
287-
if (sline && strlen(sline) > 12 && strncmp(sline, "HTTP/1.", 7) == 0 && sline[8] == ' ') {
288-
status_buf = estrndup(sline + 9, MAX_STATUS_LENGTH);
286+
if (sline && ((sline_len = strlen(sline)) > 12) && strncmp(sline, "HTTP/1.", 7) == 0 && sline[8] == ' ') {
287+
if ((sline_len - 9) > MAX_STATUS_LENGTH) {
288+
status_buf = estrndup(sline + 9, MAX_STATUS_LENGTH);
289+
} else {
290+
status_buf = estrndup(sline + 9, sline_len - 9);
291+
}
289292
} else {
293+
status_buf = emalloc(MAX_STATUS_LENGTH + 1);
290294
snprintf(status_buf, MAX_STATUS_LENGTH, "%d Undescribed", SG(sapi_headers).http_response_code);
291295
}
292296
header_info.pszStatus = status_buf;

0 commit comments

Comments
 (0)