summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorDonald Sharp <sharpd@cumulusnetworks.com>2017-03-07 17:29:44 +0100
committerGitHub <noreply@github.com>2017-03-07 17:29:44 +0100
commit1a664f5e3685139651270263a6d65c868108264d (patch)
tree0e8e2d3edbb1a58c2112f350a4271946dc5afb43 /lib
parentMerge branch 'frr/pull/250' ("bgpd, zebra: Add ifindex to NEXTHOP_TYPE_IPV4") (diff)
parentbgpd: Only send data if we have something to send (diff)
downloadfrr-1a664f5e3685139651270263a6d65c868108264d.tar.xz
frr-1a664f5e3685139651270263a6d65c868108264d.zip
Merge pull request #254 from donaldsharp/shutdown3
Shutdown take 3
Diffstat (limited to 'lib')
-rw-r--r--lib/log.c30
-rw-r--r--lib/log.h1
2 files changed, 31 insertions, 0 deletions
diff --git a/lib/log.c b/lib/log.c
index baf7bdbca..f40029043 100644
--- a/lib/log.c
+++ b/lib/log.c
@@ -1151,3 +1151,33 @@ zlog_hexdump (const void *mem, unsigned int len) {
}
zlog_debug("\n%s", buf);
}
+
+const char *
+zlog_sanitize (char *buf, size_t bufsz, const void *in, size_t inlen)
+{
+ const char *inbuf = in;
+ char *pos = buf, *end = buf + bufsz;
+ const char *iend = inbuf + inlen;
+
+ memset (buf, 0, bufsz);
+ for (; inbuf < iend; inbuf++)
+ {
+ /* don't write partial escape sequence */
+ if (end - pos < 5)
+ break;
+
+ if (*inbuf == '\n')
+ snprintf (pos, end - pos, "\\n");
+ else if (*inbuf == '\r')
+ snprintf (pos, end - pos, "\\r");
+ else if (*inbuf == '\t')
+ snprintf (pos, end - pos, "\\t");
+ else if (*inbuf < ' ' || *inbuf == '"' || *inbuf >= 127)
+ snprintf (pos, end - pos, "\\x%02hhx", *inbuf);
+ else
+ *pos = *inbuf;
+
+ pos += strlen (pos);
+ }
+ return buf;
+}
diff --git a/lib/log.h b/lib/log.h
index 3413cae5a..43fc0130d 100644
--- a/lib/log.h
+++ b/lib/log.h
@@ -188,6 +188,7 @@ extern size_t quagga_timestamp(int timestamp_precision /* # subsecond digits */,
char *buf, size_t buflen);
extern void zlog_hexdump(const void *mem, unsigned int len);
+extern const char *zlog_sanitize(char *buf, size_t bufsz, const void *in, size_t inlen);
extern int