Skip to content

Commit 2721bbf

Browse files
committed
- fix possible leak and error while fetching PHPRC
1 parent 42fea46 commit 2721bbf

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

main/php_ini.c

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,13 +396,35 @@ int php_init_config(TSRMLS_D)
396396
static const char paths_separator[] = { ZEND_PATHS_SEPARATOR, 0 };
397397
#ifdef PHP_WIN32
398398
char *reg_location;
399+
char phprc_path[MAXPATHLEN];
399400
#endif
400401

401402
env_location = getenv("PHPRC");
403+
404+
#ifdef PHP_WIN32
402405
if (!env_location) {
403-
env_location = "";
406+
char dummybuf;
407+
int size;
408+
409+
SetLastError(0);
410+
411+
/*If the given bugger is not large enough to hold the data, the return value is
412+
the buffer size, in characters, required to hold the string and its terminating
413+
null character. We use this return value to alloc the final buffer. */
414+
size = GetEnvironmentVariableA("PHPRC", &dummybuf, 0);
415+
if (GetLastError() == ERROR_ENVVAR_NOT_FOUND) {
416+
/* The environment variable doesn't exist. */
417+
env_location = "";
418+
} else {
419+
if (size == 0) {
420+
env_location = "";
421+
} else {
422+
size = GetEnvironmentVariableA("PHPRC", phprc_path, size);
423+
env_location = phprc_path;
424+
}
425+
}
404426
}
405-
427+
#endif
406428
/*
407429
* Prepare search path
408430
*/

0 commit comments

Comments
 (0)