Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix a bug of memory overflow

  • Loading branch information...
commit fb2799a99ee5da3cdf946da939195df80a8d5f28 1 parent 4ee6103
@yaoweibin authored
Showing with 17 additions and 24 deletions.
  1. +17 −24 syslog_0.8.50.patch → syslog_0.8.54.patch
View
41 syslog_0.8.50.patch → syslog_0.8.54.patch
@@ -1,5 +1,5 @@
diff --git a/src/core/ngx_log.c b/src/core/ngx_log.c
-index c0485c6..619fe48 100644
+index c0485c6..97a4913 100644
--- a/src/core/ngx_log.c
+++ b/src/core/ngx_log.c
@@ -6,9 +6,22 @@
@@ -114,7 +114,7 @@ index c0485c6..619fe48 100644
p = ngx_slprintf(p, last, " [%V] ", &err_levels[level]);
/* pid#tid */
-@@ -139,11 +194,21 @@ ngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
+@@ -139,11 +194,19 @@ ngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
ngx_linefeed(p);
@@ -123,12 +123,10 @@ index c0485c6..619fe48 100644
+ (void) ngx_write_fd(log->file->fd, errstr, p - errstr);
+ }
+
-+ errstr[p - errstr] = '\0';
-+
+ /* Don't send the debug info to syslog */
+ if (log->syslog_on && level < NGX_LOG_DEBUG) {
+ /* write to syslog */
-+ syslog(log->priority, "%s", errstr_syslog);
++ syslog(log->priority, "%.*s", p - errstr, errstr_syslog);
+ }
if (!ngx_use_stderr
@@ -138,7 +136,7 @@ index c0485c6..619fe48 100644
{
return;
}
-@@ -363,6 +428,48 @@ ngx_log_create(ngx_cycle_t *cycle, ngx_str_t *name)
+@@ -363,6 +426,48 @@ ngx_log_create(ngx_cycle_t *cycle, ngx_str_t *name)
}
@@ -187,7 +185,7 @@ index c0485c6..619fe48 100644
char *
ngx_log_set_levels(ngx_conf_t *cf, ngx_log_t *log)
{
-@@ -420,7 +527,8 @@ ngx_log_set_levels(ngx_conf_t *cf, ngx_log_t *log)
+@@ -420,7 +525,8 @@ ngx_log_set_levels(ngx_conf_t *cf, ngx_log_t *log)
static char *
ngx_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
@@ -197,7 +195,7 @@ index c0485c6..619fe48 100644
if (cf->cycle->new_log.file) {
return "is duplicate";
-@@ -428,7 +536,38 @@ ngx_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
+@@ -428,7 +534,38 @@ ngx_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
value = cf->args->elts;
@@ -237,7 +235,7 @@ index c0485c6..619fe48 100644
ngx_str_null(&name);
} else {
-@@ -449,3 +588,60 @@ ngx_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
+@@ -449,3 +586,60 @@ ngx_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
return ngx_log_set_levels(cf, &cf->cycle->new_log);
}
@@ -323,7 +321,7 @@ index 1054836..8353074 100644
void ngx_cdecl ngx_log_abort(ngx_err_t err, const char *fmt, ...);
void ngx_cdecl ngx_log_stderr(ngx_err_t err, const char *fmt, ...);
diff --git a/src/http/modules/ngx_http_log_module.c b/src/http/modules/ngx_http_log_module.c
-index 5f356c3..3ae0876 100644
+index 5f356c3..a1eaa98 100644
--- a/src/http/modules/ngx_http_log_module.c
+++ b/src/http/modules/ngx_http_log_module.c
@@ -8,6 +8,9 @@
@@ -346,24 +344,19 @@ index 5f356c3..3ae0876 100644
} ngx_http_log_t;
-@@ -312,13 +318,27 @@ ngx_http_log_write(ngx_http_request_t *r, ngx_http_log_t *log, u_char *buf,
+@@ -312,13 +318,22 @@ ngx_http_log_write(ngx_http_request_t *r, ngx_http_log_t *log, u_char *buf,
{
u_char *name;
time_t now;
- ssize_t n;
+ ssize_t n = 0;
ngx_err_t err;
-+ u_char temp;
+ ngx_http_log_loc_conf_t *lcf;
+ lcf = ngx_http_get_module_loc_conf(r, ngx_http_log_module);
+
+ if (log->syslog_on) {
-+ temp = buf[len];
-+ buf[len] = '\0';
-+ syslog(log->priority, "%s", buf);
-+ buf[len] = temp;
-+ n = len;
++ syslog(log->priority, "%.*s", len, buf);
+ }
+
if (log->script == NULL) {
@@ -377,7 +370,7 @@ index 5f356c3..3ae0876 100644
} else {
name = NULL;
n = ngx_http_log_script_write(r, log->script, &name, buf, len);
-@@ -843,14 +863,16 @@ ngx_http_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
+@@ -843,14 +858,16 @@ ngx_http_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
ngx_http_log_loc_conf_t *llcf = conf;
@@ -396,7 +389,7 @@ index 5f356c3..3ae0876 100644
value = cf->args->elts;
if (ngx_strcmp(value[1].data, "off") == 0) {
-@@ -863,6 +885,36 @@ ngx_http_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
+@@ -863,6 +880,36 @@ ngx_http_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
"invalid parameter \"%V\"", &value[2]);
return NGX_CONF_ERROR;
}
@@ -433,7 +426,7 @@ index 5f356c3..3ae0876 100644
if (llcf->logs == NULL) {
llcf->logs = ngx_array_create(cf->pool, 2, sizeof(ngx_http_log_t));
-@@ -880,35 +932,48 @@ ngx_http_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
+@@ -880,35 +927,48 @@ ngx_http_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
ngx_memzero(log, sizeof(ngx_http_log_t));
@@ -508,10 +501,10 @@ index 5f356c3..3ae0876 100644
}
}
diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c
-index d29d208..68b607f 100644
+index 488688a..4c5f5e5 100644
--- a/src/http/ngx_http_core_module.c
+++ b/src/http/ngx_http_core_module.c
-@@ -1400,6 +1400,7 @@ ngx_http_update_location_config(ngx_http_request_t *r)
+@@ -1404,6 +1404,7 @@ ngx_http_update_location_config(ngx_http_request_t *r)
if (r == r->main) {
r->connection->log->file = clcf->error_log->file;
@@ -519,7 +512,7 @@ index d29d208..68b607f 100644
if (!(r->connection->log->log_level & NGX_LOG_DEBUG_CONNECTION)) {
r->connection->log->log_level = clcf->error_log->log_level;
-@@ -4244,6 +4245,9 @@ ngx_http_core_open_file_cache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
+@@ -4255,6 +4256,9 @@ ngx_http_core_open_file_cache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
static char *
ngx_http_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
@@ -529,7 +522,7 @@ index d29d208..68b607f 100644
ngx_http_core_loc_conf_t *clcf = conf;
ngx_str_t *value;
-@@ -4252,18 +4256,60 @@ ngx_http_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
+@@ -4263,18 +4267,60 @@ ngx_http_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
return "is duplicate";
}
Please sign in to comment.
Something went wrong with that request. Please try again.