Просмотр исходного кода

nvhost_ctrl_gpu: Avoid sending null pointer to memcpy

Undefined Behaviour Sanitizer reports a null pointer is being sent to
memcpy, thought it's "guaranteed to never be null". Guard it with an if
statement, and log when the action has been averted.
lat9nq 5 лет назад
Родитель
Сommit
638c892edf
1 измененных файлов с 7 добавлено и 1 удалено
  1. 7 1
      src/core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.cpp

+ 7 - 1
src/core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.cpp

@@ -248,7 +248,13 @@ NvResult nvhost_ctrl_gpu::ZBCSetTable(const std::vector<u8>& input, std::vector<
     IoctlZbcSetTable params{};
     IoctlZbcSetTable params{};
     std::memcpy(&params, input.data(), input.size());
     std::memcpy(&params, input.data(), input.size());
     // TODO(ogniK): What does this even actually do?
     // TODO(ogniK): What does this even actually do?
-    std::memcpy(output.data(), &params, output.size());
+
+    // Prevent null pointer being passed as arg 1
+    if (output.empty()) {
+        LOG_WARNING(Service_NVDRV, "Avoiding passing null pointer to memcpy");
+    } else {
+        std::memcpy(output.data(), &params, output.size());
+    }
     return NvResult::Success;
     return NvResult::Success;
 }
 }