diff mbox series

[ovs-dev,v3,10/14] ofp-errors: Ensure parsed OFPT_ERROR messages are properly aligned.

Message ID 20220124141930.11777.76283.stgit@dceara.remote.csb
State Superseded
Headers show
Series Fix UndefinedBehaviorSanitizer reported issues and enable it in CI. | expand

Checks

Context Check Description
ovsrobot/apply-robot success apply and check: success
ovsrobot/github-robot-_Build_and_Test success github build: passed

Commit Message

Dumitru Ceara Jan. 24, 2022, 2:19 p.m. UTC
Trim the ofpbuf to ensure proper alignment.

UB Sanitizer report:
  lib/ofp-print.c:1218:24: runtime error: member access within misaligned address 0x0000019229d2 for type 'const struct ofp_header', which requires 4 byte alignment
  0x0000019229d2: note: pointer points here
   00 00  5a 5a 05 22 00 3e 00 00  00 09 00 00 00 00 00 00  00 03 05 0d 00 2e 00 00  00 09 ff ff ff ff
                ^
      #0 0x7d45cc in ofp_to_string lib/ofp-print.c:1218
      #1 0x774fa8 in ofperr_msg_format lib/ofp-errors.c:253
      #2 0x7d2617 in ofp_print_error_msg lib/ofp-print.c:435
      #3 0x7d3eb7 in ofp_to_string__ lib/ofp-print.c:998
      #4 0x7d47fb in ofp_to_string lib/ofp-print.c:1244
      #5 0x8dcc4b in do_send lib/vconn.c:688
      #6 0x8dca64 in vconn_send lib/vconn.c:671

Signed-off-by: Dumitru Ceara <dceara@redhat.com>
---
v3: Split out from old patch 07/11.
---
 lib/ofp-errors.c |    2 ++
 1 file changed, 2 insertions(+)
diff mbox series

Patch

diff --git a/lib/ofp-errors.c b/lib/ofp-errors.c
index 35191abf16dd..eb099d355270 100644
--- a/lib/ofp-errors.c
+++ b/lib/ofp-errors.c
@@ -20,6 +20,7 @@ 
 #include "openflow/openflow.h"
 #include "openflow/nicira-ext.h"
 #include "openvswitch/dynamic-string.h"
+#include "openvswitch/ofp-actions.h"
 #include "openvswitch/ofp-errors.h"
 #include "openvswitch/ofp-msgs.h"
 #include "openvswitch/ofp-print.h"
@@ -346,6 +347,7 @@  ofperr_decode_msg(const struct ofp_header *oh, struct ofpbuf *payload)
     if (error && payload) {
         ofpbuf_init(payload, b.size);
         ofpbuf_push(payload, b.data, b.size);
+        ofpbuf_trim(payload);
     }
     return error;
 }