[Stable-11.0.4 084/120] hw/nvme: fix unintentional integer overflow in shift

Michael Tokarev <[email protected]>
Newsgroups gmane.comp.emulators.qemu,gmane.comp.emulators.qemu.stable
Message-ID <[email protected]>
From: Klaus Jensen <[email protected]>

Fix potentially overflowing shift operation.

Cc: [email protected]
Suggested-by: Peter Maydell <[email protected]>
Suggested-by: Philippe Mathieu-Daudé <[email protected]>
Resolves: Coverity CID 1663674
Fixes: ec917cd49918 ("hw/nvme: fix FDP set FDP events")
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Signed-off-by: Klaus Jensen <[email protected]>
(cherry picked from commit c39e05af439a3a2bd58a847fc30d7eb590fcf61e)
Signed-off-by: Michael Tokarev <[email protected]>

diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c
index e482685c8b0..582a04542cd 100644
--- a/hw/nvme/ctrl.c
+++ b/hw/nvme/ctrl.c
@@ -194,6 +194,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/bitops.h"
 #include "qemu/cutils.h"
 #include "qemu/error-report.h"
 #include "qemu/log.h"
@@ -6540,7 +6541,8 @@ static uint16_t nvme_set_feature_fdp_events(NvmeCtrl *n, NvmeNamespace *ns,
         if (!shift && event_type) {
             continue;
         }
-        event_mask |= (1 << nvme_fdp_evf_shifts[events[i]]);
+        event_mask =
+            deposit64(event_mask, nvme_fdp_evf_shifts[events[i]], 1, 1);
     }
 
     if (enable) {
-- 
2.47.3
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.