diff options
author | Mattias Andrée <maandree@kth.se> | 2021-03-08 00:21:02 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2021-03-08 00:21:02 +0100 |
commit | b058098fdcc5d4ed9b81fdb17f64820c0360ad48 (patch) | |
tree | e39e5f547b900922775d466507c29b352f046a53 /fake-quartz-cg.c | |
parent | misc (diff) | |
download | libgamma-b058098fdcc5d4ed9b81fdb17f64820c0360ad48.tar.gz libgamma-b058098fdcc5d4ed9b81fdb17f64820c0360ad48.tar.bz2 libgamma-b058098fdcc5d4ed9b81fdb17f64820c0360ad48.tar.xz |
m + style fix + check memory allocation overflows
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r-- | fake-quartz-cg.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/fake-quartz-cg.c b/fake-quartz-cg.c index b0cc574..999609b 100644 --- a/fake-quartz-cg.c +++ b/fake-quartz-cg.c @@ -6,7 +6,8 @@ * It should by no means be used, without additional modification, as a * part of a compatibility layer. The purpose of this file is only to make * it possible to test for logical errors in Max OS X specific code on - * a GNU/Linux system under X. */ + * a Linux system under X. + */ @@ -217,7 +218,7 @@ CGGetOnlineDisplayList(uint32_t max_size, CGDirectDisplayID *restrict displays_o } /* Get the number of CRTC:s */ - crtc_count = (uint32_t)(res_reply->num_crtcs); + crtc_count = (uint32_t)res_reply->num_crtcs; /* Get the CRTC ID:s */ crtcs = xcb_randr_get_screen_resources_current_crtcs(res_reply); @@ -227,8 +228,13 @@ CGGetOnlineDisplayList(uint32_t max_size, CGDirectDisplayID *restrict displays_o * `CGDisplayRestoreColorSyncSettings` which restore the * all gamma ramps on the system to the system settnigs. */ + if (crtc_count > SIZE_MAX / sizeof(*original_ramps) / 256 / 3) { + errno = ENOMEM; + goto original_ramps_malloc_fail; + } original_ramps = malloc(crtc_count * 3 * 256 * sizeof(*original_ramps)); if (!original_ramps) { + original_ramps_malloc_fail: perror("malloc"); xcb_disconnect(connection); crtc_count = 0; |