]> granicus.if.org Git - strace/commitdiff
netlink: print unrecognized attribute data in hex
authorJingPiao Chen <chenjingpiao@gmail.com>
Tue, 4 Jul 2017 06:21:18 +0000 (14:21 +0800)
committerDmitry V. Levin <ldv@altlinux.org>
Fri, 7 Jul 2017 16:43:41 +0000 (16:43 +0000)
* nlattr.c (decode_nlattr_with_data): Replace printstrn
with printstr_ex and set QUOTE_FORCE_HEX flag.
* tests/tests.h (print_quoted_hex): New prototype.
* tests/print_quoted_string.c (print_quoted_hex): New function.
* tests/test_nlattr.h (TEST_NLATTR_OBJECT, TEST_NLATTR_ARRAY): Use it
for updated expected output.  Change the type of "plen" variable
to unsigned int.
* tests/nlattr.c (test_nlattr): Update expected output.

nlattr.c
tests/nlattr.c
tests/print_quoted_string.c
tests/test_nlattr.h
tests/tests.h

index ef3d7622656e879699b8b1a7e7cd44669c5a0295..00f8924ea7a484e62618988813154500bad1964b 100644 (file)
--- a/nlattr.c
+++ b/nlattr.c
@@ -86,7 +86,8 @@ decode_nlattr_with_data(struct tcb *const tcp,
                    || !decoders[nla->nla_type](tcp, addr + NLA_HDRLEN,
                                                nla_len - NLA_HDRLEN,
                                                opaque_data))
-                       printstrn(tcp, addr + NLA_HDRLEN, len - NLA_HDRLEN);
+                       printstr_ex(tcp, addr + NLA_HDRLEN,
+                                   len - NLA_HDRLEN, QUOTE_FORCE_HEX);
                tprints("}");
        }
 }
index 7361eced0213e47ec007a3567a3c56fea21e3f84..ae3ad4dc4b5c818bb5a2cb6790b4dec5ea2ff39c 100644 (file)
@@ -133,7 +133,8 @@ test_nlattr(const int fd)
               ", flags=NLM_F_DUMP, seq=0, pid=0}, {udiag_family=AF_UNIX"
               ", udiag_type=SOCK_STREAM, udiag_state=TCP_FIN_WAIT1"
               ", udiag_ino=0, udiag_cookie=[0, 0]}, {{nla_len=%u"
-              ", nla_type=%#x /* UNIX_DIAG_??? */}, \"1234\"}}"
+              ", nla_type=%#x /* UNIX_DIAG_??? */}"
+              ", \"\\x31\\x32\\x33\\x34\"}}"
               ", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
               fd, msg_len, nla->nla_len, UNIX_DIAG_SHUTDOWN + 1,
               msg_len, sprintrc(rc));
index ea87d11712df8b4f14eefc706d12a4a22728163b..9103eed62a3380b3c39455987286904f94509610 100644 (file)
@@ -75,3 +75,14 @@ print_quoted_memory(const char *instr, const size_t len)
 
        putchar('"');
 }
+
+void
+print_quoted_hex(const char *str, const size_t len)
+{
+       size_t i;
+
+       printf("\"");
+       for (i = 0; i < len; i++)
+               printf("\\x%02x", str[i]);
+       printf("\"");
+}
index 8cbb2115c28f13574fc2cd0af289007d2a3c4d52..24aeb607f06f605e6a24e208d714a7c9f0b7bb5f 100644 (file)
@@ -99,7 +99,8 @@ print_nlattr(const unsigned int nla_len, const char *const nla_type)
                           init_msg_, print_msg_,                       \
                           nla_type_, pattern_, obj_, ...)              \
        do {                                                            \
-               const int plen = sizeof(obj_) - 1 > DEFAULT_STRLEN      \
+               const unsigned int plen =                               \
+                       sizeof(obj_) - 1 > DEFAULT_STRLEN               \
                        ? DEFAULT_STRLEN : (int) sizeof(obj_) - 1;      \
                /* len < sizeof(obj_) */                                \
                TEST_NLATTR_((fd_), (nlh0_), (hdrlen_),                 \
@@ -107,7 +108,7 @@ print_nlattr(const unsigned int nla_len, const char *const nla_type)
                        (nla_type_), #nla_type_,                        \
                        sizeof(obj_) - 1,                               \
                        (pattern_), sizeof(obj_) - 1,                   \
-                       printf("\"%.*s\"", plen, (pattern_)));          \
+                       print_quoted_hex((pattern_), plen));            \
                /* short read of sizeof(obj_) */                        \
                TEST_NLATTR_((fd_), (nlh0_), (hdrlen_),                 \
                        (init_msg_), (print_msg_),                      \
@@ -129,7 +130,7 @@ print_nlattr(const unsigned int nla_len, const char *const nla_type)
                          init_msg_, print_msg_,                        \
                          nla_type_, pattern_, obj_, print_elem_)       \
        do {                                                            \
-               const int plen =                                        \
+               const unsigned int plen =                               \
                        sizeof((obj_)[0]) - 1 > DEFAULT_STRLEN          \
                        ? DEFAULT_STRLEN : (int) sizeof((obj_)[0]) - 1; \
                /* len < sizeof((obj_)[0]) */                           \
@@ -138,7 +139,7 @@ print_nlattr(const unsigned int nla_len, const char *const nla_type)
                        (nla_type_), #nla_type_,                        \
                        sizeof((obj_)[0]) - 1,                          \
                        (pattern_), sizeof((obj_)[0]) - 1,              \
-                       printf("\"%.*s\"", plen, (pattern_)));          \
+                       print_quoted_hex((pattern_), plen));            \
                /* sizeof((obj_)[0]) < len < sizeof(obj_) */            \
                TEST_NLATTR_((fd_), (nlh0_), (hdrlen_),                 \
                        (init_msg_), (print_msg_),                      \
index 094f365088c49b48ebe2c8efe69559c6f4c42450..bc7dc9880cd50d8a233c54c6214097d566a8237d 100644 (file)
@@ -137,6 +137,9 @@ void print_quoted_string(const char *);
 /* Print memory in a quoted form. */
 void print_quoted_memory(const char *, size_t);
 
+/* Print memory in a hexquoted form. */
+void print_quoted_hex(const char *, size_t);
+
 /* Print time_t and nanoseconds in symbolic format. */
 void print_time_t_nsec(time_t, unsigned long long, int);