]> granicus.if.org Git - strace/commitdiff
nlattr: fix printing of unrecognized attribute data
authorDmitry V. Levin <ldv@altlinux.org>
Wed, 16 Aug 2017 02:24:29 +0000 (02:24 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Wed, 16 Aug 2017 02:24:29 +0000 (02:24 +0000)
Do not print more than "nlattr.nla_len - NLA_HDRLEN" bytes
of unrecognized attribute data.

* nlattr.c (decode_nlattr_with_data): Specify "nla_len - NLA_HDRLEN"
instead of "len - NLA_HDRLEN" as the size of unrecognized attribute
data.
* tests/nlattr.c (test_nlattr): Check it.

nlattr.c
tests/nlattr.c

index a17b3473716cb80fefae7f7972893623e8866fa6..b0786df3f92fae49aaa3d68e3f819df07f22e6b3 100644 (file)
--- a/nlattr.c
+++ b/nlattr.c
@@ -88,7 +88,7 @@ decode_nlattr_with_data(struct tcb *const tcp,
                                                nla_len - NLA_HDRLEN,
                                                opaque_data))
                        printstr_ex(tcp, addr + NLA_HDRLEN,
-                                   len - NLA_HDRLEN, QUOTE_FORCE_HEX);
+                                   nla_len - NLA_HDRLEN, QUOTE_FORCE_HEX);
                tprints("}");
        }
 }
index a2d59d42cb97d74a257a0e2f4c0996ccd2709346..41923c0aa96d5742187d6b6d09cd1995dd79c3cc 100644 (file)
@@ -210,18 +210,22 @@ test_nlattr(const int fd)
               ", nla_type=UNIX_DIAG_NAME}}, %u, MSG_DONTWAIT, NULL, 0) = %s\n",
               fd, msg_len, nla->nla_len, msg_len, sprintrc(rc));
 
-       /* abbreviated output */
+       /* unrecognized attribute data, abbreviated output */
 #define ABBREV_LEN (DEFAULT_STRLEN + 1)
-       msg_len = NLA_HDRLEN * ABBREV_LEN + NLMSG_SPACE(sizeof(msg->udm));
-       msg = tail_memdup(&c_msg, msg_len);
-       memcpy(&msg->nlh.nlmsg_len, &msg_len, sizeof(msg_len));
+       msg_len = NLMSG_SPACE(sizeof(msg->udm)) + NLA_HDRLEN * ABBREV_LEN * 2;
+       msg = tail_alloc(msg_len);
+       memcpy(msg, &c_msg, sizeof(c_msg));
+       msg->nlh.nlmsg_len = msg_len;
        unsigned int i;
        nla = NLMSG_ATTR(msg, sizeof(msg->udm));
-       for (i = 0; i < ABBREV_LEN; ++i)
-               nla[i] = (struct nlattr) {
-                       .nla_len = NLA_HDRLEN,
+       for (i = 0; i < ABBREV_LEN; ++i) {
+               nla[i * 2] = (struct nlattr) {
+                       .nla_len = NLA_HDRLEN * 2 - 1,
                        .nla_type = UNIX_DIAG_SHUTDOWN + 1 + i
                };
+               fill_memory_ex(&nla[i * 2 + 1], NLA_HDRLEN,
+                              '0' + i, '~' - '0' - i);
+       }
 
        rc = sendto(fd, msg, msg_len, MSG_DONTWAIT, NULL, 0);
        printf("sendto(%d, {{len=%u, type=SOCK_DIAG_BY_FAMILY"
@@ -233,8 +237,10 @@ test_nlattr(const int fd)
        for (i = 0; i < DEFAULT_STRLEN; ++i) {
                if (i)
                        printf(", ");
-               printf("{nla_len=%u, nla_type=%#x /* UNIX_DIAG_??? */}",
+               printf("{{nla_len=%u, nla_type=%#x /* UNIX_DIAG_??? */}, ",
                       nla->nla_len, UNIX_DIAG_SHUTDOWN + 1 + i);
+               print_quoted_hex(&nla[i * 2 + 1], NLA_HDRLEN - 1);
+               printf("}");
        }
        printf(", ...]}, %u, MSG_DONTWAIT, NULL, 0) = %s\n",
               msg_len, sprintrc(rc));