]> granicus.if.org Git - strace/commitdiff
bpf: harmonize length checks
authorDmitry V. Levin <ldv@altlinux.org>
Thu, 12 Apr 2018 23:00:29 +0000 (23:00 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Thu, 12 Apr 2018 23:00:29 +0000 (23:00 +0000)
The rest of the decoder uses offsetof to check the length.

* bpf.c (BEGIN_BPF_CMD_DECODER(BPF_OBJ_PIN),
BEGIN_BPF_CMD_DECODER(BPF_PROG_GET_NEXT_ID),
BEGIN_BPF_CMD_DECODER(BPF_PROG_GET_FD_BY_ID),
BEGIN_BPF_CMD_DECODER(BPF_MAP_GET_FD_BY_ID)): Use offsetof instead
of offsetofend.

bpf.c

diff --git a/bpf.c b/bpf.c
index dc5df34559ddd00b15ab17b873785a2f87f3f0ee..6b602b72429a3911c82f362f8358e66b26da114a 100644 (file)
--- a/bpf.c
+++ b/bpf.c
@@ -275,10 +275,10 @@ BEGIN_BPF_CMD_DECODER(BPF_OBJ_PIN)
        printpath(tcp, attr.pathname);
 
        PRINT_FIELD_FD(", ", attr, bpf_fd, tcp);
-       if (len <= offsetofend(struct BPF_OBJ_PIN_struct, bpf_fd))
-               break;
 
        /* file_flags field was added in Linux v4.15-rc1~84^2~384^2~4 */
+       if (len <= offsetof(struct BPF_OBJ_PIN_struct, file_flags))
+               break;
        PRINT_FIELD_FLAGS(", ", attr, file_flags, bpf_file_mode_flags,
                          "BPF_F_???");
 }
@@ -321,10 +321,10 @@ BEGIN_BPF_CMD_DECODER(BPF_PROG_GET_NEXT_ID)
 {
        PRINT_FIELD_U("{", attr, start_id);
        PRINT_FIELD_U(", ", attr, next_id);
-       if (len <= offsetofend(struct BPF_PROG_GET_NEXT_ID_struct, next_id))
-               break;
 
        /* open_flags field has been added in Linux v4.15-rc1~84^2~384^2~4 */
+       if (len <= offsetof(struct BPF_PROG_GET_NEXT_ID_struct, open_flags))
+               break;
        PRINT_FIELD_FLAGS(", ", attr, open_flags, bpf_file_mode_flags,
                          "BPF_F_???");
 }
@@ -336,10 +336,10 @@ BEGIN_BPF_CMD_DECODER(BPF_PROG_GET_FD_BY_ID)
 {
        PRINT_FIELD_U("{", attr, prog_id);
        PRINT_FIELD_U(", ", attr, next_id);
-       if (len <= offsetofend(struct BPF_PROG_GET_FD_BY_ID_struct, next_id))
-               break;
 
        /* open_flags field has been added in Linux v4.15-rc1~84^2~384^2~4 */
+       if (len <= offsetof(struct BPF_PROG_GET_FD_BY_ID_struct, open_flags))
+               break;
        PRINT_FIELD_FLAGS(", ", attr, open_flags, bpf_file_mode_flags,
                          "BPF_F_???");
 }
@@ -349,10 +349,10 @@ BEGIN_BPF_CMD_DECODER(BPF_MAP_GET_FD_BY_ID)
 {
        PRINT_FIELD_U("{", attr, map_id);
        PRINT_FIELD_U(", ", attr, next_id);
-       if (len <= offsetofend(struct BPF_MAP_GET_FD_BY_ID_struct, next_id))
-               break;
 
        /* open_flags field has been added in Linux v4.15-rc1~84^2~384^2~4 */
+       if (len <= offsetof(struct BPF_MAP_GET_FD_BY_ID_struct, open_flags))
+               break;
        PRINT_FIELD_FLAGS(", ", attr, open_flags, bpf_file_mode_flags,
                          "BPF_F_???");
 }