[ovs-dev] [PATCH] ofp-actions: Fix undefined behavior shifting 'int' 16 places left.

Ben Pfaff blp at ovn.org
Mon Jun 25 19:45:50 UTC 2018


Shifting a 16-bit signed int 16 bits is technically undefined behavior.
This fixes the problem.  (In practice this should be harmless in this
case.)

Reported-at: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=9049
Signed-off-by: Ben Pfaff <blp at ovn.org>
---
 lib/ofp-actions.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib/ofp-actions.c b/lib/ofp-actions.c
index e91e0b252390..607a947159cd 100644
--- a/lib/ofp-actions.c
+++ b/lib/ofp-actions.c
@@ -8902,7 +8902,8 @@ ofpact_hdrs_equal(const struct ofpact_hdrs *a,
 static uint32_t
 ofpact_hdrs_hash(const struct ofpact_hdrs *hdrs)
 {
-    return hash_2words(hdrs->vendor, (hdrs->type << 16) | hdrs->ofp_version);
+    return hash_2words(hdrs->vendor,
+                       ((uint32_t) hdrs->type << 16) | hdrs->ofp_version);
 }
 
 #include "ofp-actions.inc2"
-- 
2.16.1



More information about the dev mailing list