Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

bugfix: ngx.log() would truncate the log messages with a null charact…

…er (\0) in it. thanks Wang Xi for reporting this issue.
  • Loading branch information...
commit 8d92e6c670b65ae4c21d4dbb75a2175ec98ad455 1 parent 7c0948a
@agentzh agentzh authored
Showing with 24 additions and 7 deletions.
  1. +4 −6 src/ngx_http_lua_log.c
  2. +20 −1 t/009-log.t
View
10 src/ngx_http_lua_log.c
@@ -181,7 +181,7 @@ log_wrapper(ngx_log_t *log, const char *ident, ngx_uint_t level,
}
}
- buf = lua_newuserdata(L, size + 1);
+ buf = lua_newuserdata(L, size);
p = ngx_copy(buf, name.data, name.len);
@@ -245,14 +245,12 @@ log_wrapper(ngx_log_t *log, const char *ident, ngx_uint_t level,
}
}
- *p++ = '\0';
-
- if (p - buf > (off_t) (size + 1)) {
+ if (p - buf > (off_t) size) {
return luaL_error(L, "buffer error: %d > %d", (int) (p - buf),
- (int) (size + 1));
+ (int) size);
}
- ngx_log_error(level, log, 0, "%s%s", ident, buf);
+ ngx_log_error(level, log, 0, "%s%*s", ident, (size_t) (p - buf), buf);
return 0;
}
View
21 t/009-log.t
@@ -8,7 +8,7 @@ log_level('debug'); # to ensure any log-level can be outputed
repeat_each(2);
-plan tests => repeat_each() * (blocks() * 3 + 3);
+plan tests => repeat_each() * (blocks() * 3 + 4);
#no_diff();
#no_long_string();
@@ -435,3 +435,22 @@ GET /log
--- error_log
bad log level: 9
+
+
+=== TEST 22: \0 in the log message
+--- config
+ location = /t {
+ content_by_lua '
+ ngx.log(ngx.WARN, "hello\\0world")
+ ngx.say("ok")
+ ';
+ }
+--- request
+GET /t
+--- response_body
+ok
+--- no_error_log
+[error]
+--- error_log eval
+"2: hello\0world, client: "
+
Please sign in to comment.
Something went wrong with that request. Please try again.