[Spice-devel] [PATCH 01/14] Remove small possible buffer overflow

Frediano Ziglio fziglio at redhat.com
Thu Sep 1 12:00:43 UTC 2016


wcsncpy requires number of characters, not bytes.

Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
 vdagent/display_configuration.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/vdagent/display_configuration.cpp b/vdagent/display_configuration.cpp
index c0d6342..79ea3b4 100644
--- a/vdagent/display_configuration.cpp
+++ b/vdagent/display_configuration.cpp
@@ -17,6 +17,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 #include "display_configuration.h"
 #include <winternl.h>
+#include <spice/macros.h>
 
 /* The following definitions and structures are taken
 from the wine project repository and can be found
@@ -631,7 +632,7 @@ D3D_HANDLE WDDMInterface::handle_from_GDI_name(LPCTSTR adapter_name)
     NTSTATUS status;
 
     ZeroMemory(&gdi_display_name, sizeof(gdi_display_name));
-    wcsncpy(gdi_display_name.DeviceName, adapter_name, sizeof(TCHAR)* CCHDEVICENAME);
+    wcsncpy(gdi_display_name.DeviceName, adapter_name, SPICE_N_ELEMENTS(gdi_display_name.DeviceName));
 
     if (NT_SUCCESS(status = _pfnOpen_adapter_gdi_name(&gdi_display_name))) {
         return  gdi_display_name.hAdapter;
-- 
2.7.4



More information about the Spice-devel mailing list