From b058098fdcc5d4ed9b81fdb17f64820c0360ad48 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Mon, 8 Mar 2021 00:21:02 +0100 Subject: m + style fix + check memory allocation overflows MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- libgamma_x_randr_get_crtc_information.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) (limited to 'libgamma_x_randr_get_crtc_information.c') diff --git a/libgamma_x_randr_get_crtc_information.c b/libgamma_x_randr_get_crtc_information.c index 8bf2e8f..75885e6 100644 --- a/libgamma_x_randr_get_crtc_information.c +++ b/libgamma_x_randr_get_crtc_information.c @@ -109,19 +109,19 @@ get_connector_type(struct libgamma_crtc_information *restrict this) } while (0) /* Check begin on the name of the output to find out what type the connector is of */ - SELECT ("None", Unknown); - SELECT ("VGA", VGA); - SELECT ("DVI-I", DVII); - SELECT ("DVI-D", DVID); - SELECT ("DVI-A", DVIA); - SELECT ("DVI", DVI); - SELECT ("Composite", Composite); - SELECT ("S-Video", SVIDEO); - SELECT ("Component", Component); - SELECT ("LFP", LFP); - SELECT ("Proprietary", Unknown); - SELECT ("HDMI", HDMI); - SELECT ("DisplayPort", DisplayPort); + SELECT("None", Unknown); + SELECT("VGA", VGA); + SELECT("DVI-I", DVII); + SELECT("DVI-D", DVID); + SELECT("DVI-A", DVIA); + SELECT("DVI", DVI); + SELECT("Composite", Composite); + SELECT("S-Video", SVIDEO); + SELECT("Component", Component); + SELECT("LFP", LFP); + SELECT("Proprietary", Unknown); + SELECT("HDMI", HDMI); + SELECT("DisplayPort", DisplayPort); #undef SELECT @@ -153,6 +153,11 @@ get_output_name(struct libgamma_crtc_information *restrict out, xcb_randr_get_ou return out->connector_name_error = LIBGAMMA_REPLY_VALUE_EXTRACTION_FAILED; /* Allocate a memory area for a NUL-terminated copy of the name */ + if (length > SIZE_MAX / sizeof(char) - 1) { + out->connector_name = NULL; + out->connector_name_error = errno = ENOMEM; + return -1; + } store = out->connector_name = malloc(((size_t)length + 1) * sizeof(char)); if (!store) { out->connector_name_error = errno; -- cgit v1.2.3-70-g09d2