Skip to content

Commit 6374366

Browse files
committed
fix possible null dereference
1 parent 82988d3 commit 6374366

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

win32/codepage.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -498,16 +498,18 @@ PW32CP const struct php_win32_cp *php_win32_cp_cli_do_setup(DWORD id)
498498

499499
PW32CP const struct php_win32_cp *php_win32_cp_cli_do_restore(DWORD id)
500500
{/*{{{*/
501-
if (!id && orig_cp) {
502-
id = orig_cp->id;
501+
BOOL cli_io_restored = TRUE;
502+
503+
if (orig_in_cp) {
504+
cli_io_restored = cli_io_restored && SetConsoleCP(orig_in_cp->id);
503505
}
504506

505-
if (SetConsoleCP(orig_in_cp->id) && SetConsoleOutputCP(orig_out_cp->id)) {
506-
if (orig_cp) {
507-
return orig_cp;
508-
} else {
509-
return php_win32_cp_set_by_id(id);
510-
}
507+
if (orig_out_cp) {
508+
cli_io_restored = cli_io_restored && SetConsoleOutputCP(orig_out_cp->id);
509+
}
510+
511+
if (cli_io_restored && id) {
512+
return php_win32_cp_set_by_id(id);
511513
}
512514

513515
return NULL;

0 commit comments

Comments
 (0)