Skip to content

Commit 8c8fba0

Browse files
author
Ilia Alshanetsky
committed
Fixed bug #30475 (curl_getinfo() may crash in some situations).
1 parent e865bc2 commit 8c8fba0

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

ext/curl/interface.c

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,10 +1336,13 @@ PHP_FUNCTION(curl_getinfo)
13361336
switch (option) {
13371337
case CURLINFO_EFFECTIVE_URL:
13381338
case CURLINFO_CONTENT_TYPE: {
1339-
char *s_code;
1339+
char *s_code = NULL;
13401340

1341-
curl_easy_getinfo(ch->cp, option, &s_code);
1342-
RETURN_STRING(s_code, 1);
1341+
if (curl_easy_getinfo(ch->cp, option, &s_code) == CURLE_OK && s_code) {
1342+
RETURN_STRING(s_code, 1);
1343+
} else {
1344+
RETURN_FALSE;
1345+
}
13431346
break;
13441347
}
13451348
case CURLINFO_HTTP_CODE:
@@ -1348,10 +1351,13 @@ PHP_FUNCTION(curl_getinfo)
13481351
case CURLINFO_FILETIME:
13491352
case CURLINFO_SSL_VERIFYRESULT:
13501353
case CURLINFO_REDIRECT_COUNT: {
1351-
long code;
1354+
long code = 0;
13521355

1353-
curl_easy_getinfo(ch->cp, option, &code);
1354-
RETURN_LONG(code);
1356+
if (curl_easy_getinfo(ch->cp, option, &code) == CURLE_OK) {
1357+
RETURN_LONG(code);
1358+
} else {
1359+
RETURN_FALSE;
1360+
}
13551361
break;
13561362
}
13571363
case CURLINFO_TOTAL_TIME:
@@ -1366,10 +1372,13 @@ PHP_FUNCTION(curl_getinfo)
13661372
case CURLINFO_CONTENT_LENGTH_UPLOAD:
13671373
case CURLINFO_STARTTRANSFER_TIME:
13681374
case CURLINFO_REDIRECT_TIME: {
1369-
double code;
1375+
double code = 0.0;
13701376

1371-
curl_easy_getinfo(ch->cp, option, &code);
1372-
RETURN_DOUBLE(code);
1377+
if (curl_easy_getinfo(ch->cp, option, &code) == CURLE_OK) {
1378+
RETURN_DOUBLE(code);
1379+
} else {
1380+
RETURN_FALSE;
1381+
}
13731382
break;
13741383
}
13751384
}

0 commit comments

Comments
 (0)