Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1lRz9G-000200-IW for mharc-grub-devel@gnu.org; Thu, 01 Apr 2021 11:22:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45676) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lRz9E-0001x1-MC for grub-devel@gnu.org; Thu, 01 Apr 2021 11:22:16 -0400 Received: from mail-pg1-x536.google.com ([2607:f8b0:4864:20::536]:45052) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lRz9C-0006Ir-PK for grub-devel@gnu.org; Thu, 01 Apr 2021 11:22:16 -0400 Received: by mail-pg1-x536.google.com with SMTP id y32so1714745pga.11 for ; Thu, 01 Apr 2021 08:22:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axtens.net; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=vBnygFzRcF5keZ0ORJsPQRlKNpUd/fhr8eGwoykILro=; b=WWADA3gM0K4iIlsbKKmHk7fj1FU/WIpVoteEG3+9Fo7iBpXaX3bobK+b0MkIXmkkuW qMbKhpQe+B1geG9rH2WHWGnybCkRtoVGKtFWhqus4Vwb7NxtfzypvD16ke5Bu7i6TBoJ 1w4l1iPI39N2FWGFkLDferADw5XEtTFQWcJkc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=vBnygFzRcF5keZ0ORJsPQRlKNpUd/fhr8eGwoykILro=; b=HbV8jfgMrMlab5u2CSZ6UNTtX5HloL6edoo0cwT0BXHWXcn4/aAIgWhxk1uiATIyg0 i9cl/KS+bsd8e4JKAcLsChd/zCPY8iS1nmang08pFntGiRWPZ8HZhd+KcgiumL0ClEuH 5/QfYqBQrtGkZH1PqZn+wDCwwVhO9UOeMhJMHSPsTuzWHTrEvF2aiYH21Ze0HNCjM7Uo VY03HPUgacJ6QCCeAAfU8x/jOcSxz5iQ5/M1GFs6Adxi3GQRSQcKXfo52rXzA/AwAs3Q jac3lZHCO7lU5JDDQNSOkd8DusPbBPSQIEPpJoPx/seV7XbOiifiCtHVsQVqcwBJAwjZ OUJg== X-Gm-Message-State: AOAM5322FmxnpnURG+FJImLW2DB3pNHML5EB53gk1d1uyQXlTohfO9bY KCJgSLN9dueD9RcgqUgsECwrXv6C9ABmEQ== X-Google-Smtp-Source: ABdhPJwFrLRNC3wdhUb2eqToFh2EeJ7vOWWNx5+iB/9OGOgoLqFuRcK6IgsVBxhMXW5zkfMblT9h1w== X-Received: by 2002:a62:d45a:0:b029:218:669c:4f37 with SMTP id u26-20020a62d45a0000b0290218669c4f37mr8129346pfl.48.1617290529360; Thu, 01 Apr 2021 08:22:09 -0700 (PDT) Received: from localhost (2001-44b8-1113-6700-e887-9584-858d-f393.static.ipv6.internode.on.net. [2001:44b8:1113:6700:e887:9584:858d:f393]) by smtp.gmail.com with ESMTPSA id 190sm5831871pgh.61.2021.04.01.08.22.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Apr 2021 08:22:08 -0700 (PDT) From: Daniel Axtens To: grub-devel@gnu.org Cc: Daniel Axtens Subject: [PATCH for 2.06] video/fbfill: use unsigned integers for width/height Date: Fri, 2 Apr 2021 02:22:04 +1100 Message-Id: <20210401152204.944340-1-dja@axtens.net> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::536; envelope-from=dja@axtens.net; helo=mail-pg1-x536.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 01 Apr 2021 15:22:17 -0000 Since commit 7ce3259f67ac ("video/fb/fbfill: Fix potential integer overflow"), clang builds of grub-emu have failed with messages like: /usr/bin/ld: libgrubmods.a(libgrubmods_a-fbfill.o): in function `grub_video_fbfill_direct24': fbfill.c:(.text+0x28e): undefined reference to `__muloti4' This appears to be due to a weird quirk in how clang compiles grub_mul (dst->mode_info->bytes_per_pixel, width, &rowskip) which is grub_mul (unsigned int, int, &grub_size_t). It looks like clang somewhere promotes everything to 128-bit maths before ultimately reducing down to 64 bit for grub_size_t. I think this is because width is signed, and indeed converting width to an unsigned int makes the problem go away. This conversion also makes more sense generally: - the caller of all the fbfill_directN functions is grub_video_fb_fill_dispatch and it takes width and height as unsigned ints already, - it doesn't make sense to fill a negative width or height. Convert the width and height arguments and associated loop counters to unsigned ints. Fixes: 7ce3259f67ac ("video/fb/fbfill: Fix potential integer overflow") Signed-off-by: Daniel Axtens --- This should go in for 2.06, otherwise the Clang build will be broken. --- grub-core/video/fb/fbfill.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/grub-core/video/fb/fbfill.c b/grub-core/video/fb/fbfill.c index a37acd1e2939..51b1f6557007 100644 --- a/grub-core/video/fb/fbfill.c +++ b/grub-core/video/fb/fbfill.c @@ -38,10 +38,10 @@ static void grub_video_fbfill (struct grub_video_fbblit_info *dst, grub_video_color_t color, int x, int y, - int width, int height) + unsigned int width, unsigned int height) { - int i; - int j; + unsigned int i; + unsigned int j; for (j = 0; j < height; j++) for (i = 0; i < width; i++) @@ -53,10 +53,10 @@ grub_video_fbfill (struct grub_video_fbblit_info *dst, static void grub_video_fbfill_direct32 (struct grub_video_fbblit_info *dst, grub_video_color_t color, int x, int y, - int width, int height) + unsigned int width, unsigned int height) { - int i; - int j; + unsigned int i; + unsigned int j; grub_uint32_t *dstptr; grub_size_t rowskip; @@ -84,10 +84,10 @@ grub_video_fbfill_direct32 (struct grub_video_fbblit_info *dst, static void grub_video_fbfill_direct24 (struct grub_video_fbblit_info *dst, grub_video_color_t color, int x, int y, - int width, int height) + unsigned int width, unsigned int height) { - int i; - int j; + unsigned int i; + unsigned int j; grub_size_t rowskip; grub_uint8_t *dstptr; #ifndef GRUB_CPU_WORDS_BIGENDIAN @@ -127,10 +127,10 @@ grub_video_fbfill_direct24 (struct grub_video_fbblit_info *dst, static void grub_video_fbfill_direct16 (struct grub_video_fbblit_info *dst, grub_video_color_t color, int x, int y, - int width, int height) + unsigned int width, unsigned int height) { - int i; - int j; + unsigned int i; + unsigned int j; grub_size_t rowskip; grub_uint16_t *dstptr; @@ -158,10 +158,10 @@ grub_video_fbfill_direct16 (struct grub_video_fbblit_info *dst, static void grub_video_fbfill_direct8 (struct grub_video_fbblit_info *dst, grub_video_color_t color, int x, int y, - int width, int height) + unsigned int width, unsigned int height) { - int i; - int j; + unsigned int i; + unsigned int j; grub_size_t rowskip; grub_uint8_t *dstptr; grub_uint8_t fill = (grub_uint8_t)color & 0xFF; -- 2.27.0