From e9df998a8915c45aff2f17f80a2711584fba9d5d Mon Sep 17 00:00:00 2001 From: Peter Jung Date: Fri, 18 Oct 2024 22:44:59 +0200 Subject: [PATCH 5/6] nvkms: Sanitize & trim ELD product name strings Signed-off-by: Peter Jung --- src/nvidia-modeset/src/nvkms-hdmi.c | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/src/nvidia-modeset/src/nvkms-hdmi.c b/src/nvidia-modeset/src/nvkms-hdmi.c index 07841ef5..338d2dad 100644 --- a/src/nvidia-modeset/src/nvkms-hdmi.c +++ b/src/nvidia-modeset/src/nvkms-hdmi.c @@ -1046,27 +1046,13 @@ static NvBool FillELDBuffer(const NVDpyEvoRec *pDpyEvo, if (status == NVT_STATUS_SUCCESS) { /* - * NvTiming_GetProductName() returns a nul-terminated string, but the - * string in the EDID is terminated with 0x0A and padded with 0x20. - * Put back these special characters. + * NvTiming_GetProductName returns a nul-terminated string. Figure out + * how long it is and copy the bytes up to, but not including, the nul + * terminator. */ - NvBool pastTerminator = FALSE; - NvU32 i; - - for (i = 0; i < NVT_EDID_LDD_PAYLOAD_SIZE; i++) { - if (pastTerminator) { - name[i] = 0x20; - } - if (name[i] == '\0') { - name[i] = 0x0A; - pastTerminator = TRUE; - } - } - - monitorNameLen = NVT_EDID_LDD_PAYLOAD_SIZE; - pEld->buffer[4] |= NVT_EDID_LDD_PAYLOAD_SIZE; - nvkms_memcpy(&pEld->buffer[20], name, - NVT_EDID_LDD_PAYLOAD_SIZE); + monitorNameLen = nvkms_strlen((char *)name); + pEld->buffer[4] |= monitorNameLen; + nvkms_memcpy(&pEld->buffer[20], name, monitorNameLen); } /* offset 20 + MNL ~ 20 + MNL + (3 * SAD_Count) - 1 : CEA_SADs */ -- 2.47.0