summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_sprintf.c
diff options
context:
space:
mode:
authorAndrei Zeliankou <zelenkov@nginx.com>2022-06-01 16:40:34 +0100
committerAndrei Zeliankou <zelenkov@nginx.com>2022-06-01 16:40:34 +0100
commitcaa05887ff70bbd6338b129959a234ef56f1a287 (patch)
tree92631fc0fa632848106f8d3672a0d9dcc206fd06 /src/nxt_sprintf.c
parent161230b955ba8a6a22888c21f1b067de61af78dd (diff)
downloadunit-caa05887ff70bbd6338b129959a234ef56f1a287.tar.gz
unit-caa05887ff70bbd6338b129959a234ef56f1a287.tar.bz2
Logging a NULL pointer instead of passing it in the memcpy().
Diffstat (limited to 'src/nxt_sprintf.c')
-rw-r--r--src/nxt_sprintf.c28
1 files changed, 19 insertions, 9 deletions
diff --git a/src/nxt_sprintf.c b/src/nxt_sprintf.c
index 90d74335..9c8e27ed 100644
--- a/src/nxt_sprintf.c
+++ b/src/nxt_sprintf.c
@@ -115,6 +115,7 @@ nxt_vsprintf(u_char *buf, u_char *end, const char *fmt, va_list args)
static const u_char hexadecimal[16] = "0123456789abcdef";
static const u_char HEXADECIMAL[16] = "0123456789ABCDEF";
static const u_char nan[] = "[nan]";
+ static const u_char null[] = "[null]";
static const u_char infinity[] = "[infinity]";
spf.end = end;
@@ -150,15 +151,18 @@ nxt_vsprintf(u_char *buf, u_char *end, const char *fmt, va_list args)
continue;
case 's':
+ fmt++;
+
p = va_arg(args, const u_char *);
- if (nxt_fast_path(p != NULL)) {
- while (*p != '\0' && buf < end) {
- *buf++ = *p++;
- }
+ if (nxt_slow_path(p == NULL)) {
+ goto copy;
+ }
+
+ while (*p != '\0' && buf < end) {
+ *buf++ = *p++;
}
- fmt++;
continue;
case '*':
@@ -170,9 +174,7 @@ nxt_vsprintf(u_char *buf, u_char *end, const char *fmt, va_list args)
fmt++;
p = va_arg(args, const u_char *);
- if (nxt_fast_path(p != NULL)) {
- goto copy;
- }
+ goto copy;
}
continue;
@@ -554,7 +556,15 @@ nxt_vsprintf(u_char *buf, u_char *end, const char *fmt, va_list args)
copy:
- buf = nxt_cpymem(buf, p, nxt_min((size_t) (end - buf), length));
+ if (nxt_slow_path(p == NULL)) {
+ p = null;
+ length = nxt_length(null);
+
+ } else {
+ length = nxt_min((size_t) (end - buf), length);
+ }
+
+ buf = nxt_cpymem(buf, p, length);
continue;
}