Skip to content

Commit 246cb03

Browse files
committed
Fix event log handling in startup phase
The log header can be saved in the globals on startup. At the same time, the log header can be changed per request. In case that happened, wrong pointer will be free'd on shutdown. It can happen at any point when zend_error() or similar is called at startup, like for example in the case of the ini deprecation warnings. Thus, ZMM cannot be used here.
1 parent 3847a6f commit 246cb03

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

win32/wsyslog.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ void closelog(void)
6666
PW32G(log_source) = INVALID_HANDLE_VALUE;
6767
}
6868
if (PW32G(log_header)) {
69-
efree(PW32G(log_header));
69+
free(PW32G(log_header));
7070
PW32G(log_header) = NULL;
7171
}
7272
}
@@ -112,7 +112,6 @@ void syslog(int priority, const char *message, ...)
112112
efree(tmp);
113113
}
114114

115-
116115
/* Emulator for BSD openlog() routine
117116
* Accepts: identity
118117
* options
@@ -121,11 +120,14 @@ void syslog(int priority, const char *message, ...)
121120

122121
void openlog(const char *ident, int logopt, int facility)
123122
{
123+
size_t header_len;
124124

125125
closelog();
126126

127127
PW32G(log_source) = RegisterEventSource(NULL, "PHP-" PHP_VERSION);
128-
spprintf(&PW32G(log_header), 0, (logopt & LOG_PID) ? "%s[%d]" : "%s", ident, getpid());
128+
header_len = strlen(ident) + 2 + 11;
129+
PW32G(log_header) = malloc(header_len*sizeof(char));
130+
sprintf_s(PW32G(log_header), header_len, (logopt & LOG_PID) ? "%s[%d]" : "%s", ident, getpid());
129131
}
130132

131133
/*

0 commit comments

Comments
 (0)