From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1p29fe-000253-Ok for mharc-grub-devel@gnu.org; Mon, 05 Dec 2022 06:30:02 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p29fc-000248-BV for grub-devel@gnu.org; Mon, 05 Dec 2022 06:30:00 -0500 Received: from mail-pj1-x1035.google.com ([2607:f8b0:4864:20::1035]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1p29fa-00058i-CY for grub-devel@gnu.org; Mon, 05 Dec 2022 06:29:59 -0500 Received: by mail-pj1-x1035.google.com with SMTP id o1-20020a17090a678100b00219cf69e5f0so2553198pjj.2 for ; Mon, 05 Dec 2022 03:29:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YmXLbKQgxQ7OfnQPck9LQNnKOCr37nRpdkEOfy2e6P8=; b=gTtgvTkl1x1Y/bLvkF80iX2ooJ4ULgU2uzsolvu4YmR2yRX7SoeNDi5B8Zxa2fE3WP dUH2+Bh2Ap2FownoBPC7rRvqdNWK6dTFaWKpqAMnRVPv2uDNU1M7AosRrF8Q6MQO4bZE sFE61nCvju95MRKTb1BdgPoE/ABJta/fXl8FPYgc6UWwxXj9TD4e5sGyVPeL/YAxdZZz juDbrTPh0XE15cgV0PLmzJbDkCPGvPxAi25C3gxF5m9lj8+HhF7FVaC3oqmtCwqtNHOe Bnf5YqZnKASflwkQUE1u9sOXSY4KUo0BTyTHkhMRvOfJXEHiGN8g1lyd/AVyz6zEDLQT Za9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YmXLbKQgxQ7OfnQPck9LQNnKOCr37nRpdkEOfy2e6P8=; b=IiqX0vz8AFAXChdnbqKmp+fSvkH+D0w4Ya2mRQggVV2N43BDMBHbyjNioidZcms7FK bFUnaM/6snlNJFitqP9qIX9UfuETr/DYnIAxALEOXQeJIDtsIOv/9nljAnDFaeWXUr6F QqMYU1WnB6RVSHcT6YpCeFFK/T18GqdIBKxLXs/Lj2Mdt739YezJgsInoOeJBPeL032v wwWqpob05SnYwZM+vtejA6ydQsGvf4tqlROpbNLoB5sQfLf8SW1yxwVIMQsjEtcijmXv mP8C801iTNv5UsWQAecC5B23oxZCDqgnKF2j4xOQLyCm0IgJbT+8JpqQ2tFxl6St2UCq VH9A== X-Gm-Message-State: ANoB5pm9oAlzlceOLYcDJVekyMWo+3LpJetloZCGVN990rFF1grWEjz9 0nS57lA54yEQes1/GWz/qVuRZsoJkjY= X-Google-Smtp-Source: AA0mqf6Fux0ve+WLtIOcxpEaXgT7yZHXcYTMw33fVbFZjQEr17Pt4/864ZKqMra5Zq4JiOmFTMZDiA== X-Received: by 2002:a17:90a:eac2:b0:219:484:e955 with SMTP id ev2-20020a17090aeac200b002190484e955mr51776649pjb.214.1670239796878; Mon, 05 Dec 2022 03:29:56 -0800 (PST) Received: from localhost.localdomain (ec2-13-113-80-70.ap-northeast-1.compute.amazonaws.com. [13.113.80.70]) by smtp.gmail.com with ESMTPSA id b7-20020a170902650700b0018869119e37sm10381729plk.142.2022.12.05.03.29.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Dec 2022 03:29:56 -0800 (PST) From: Zhang Boyang To: grub-devel@gnu.org Cc: Zhang Boyang Subject: [PATCH 1/5] font: Check return value of grub_malloc() in ascii_glyph_lookup() Date: Mon, 5 Dec 2022 19:29:36 +0800 Message-Id: <20221205112940.246486-2-zhangboyang.id@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221205112940.246486-1-zhangboyang.id@gmail.com> References: <20221205112940.246486-1-zhangboyang.id@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::1035; envelope-from=zhangboyang.id@gmail.com; helo=mail-pj1-x1035.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, FREEMAIL_FROM=0.001, 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.29 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 05 Dec 2022 11:30:00 -0000 There is a problem in ascii_glyph_lookup(). It doesn't check the return value of grub_malloc(). If memory can't be allocated, then NULL pointer will be written to. This patch fixes the problem by fallbacking to unknown_glyph in case of grub_malloc() returns NULL. Signed-off-by: Zhang Boyang --- grub-core/font/font.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/grub-core/font/font.c b/grub-core/font/font.c index 3821937e6..19a47f873 100644 --- a/grub-core/font/font.c +++ b/grub-core/font/font.c @@ -131,6 +131,11 @@ ascii_glyph_lookup (grub_uint32_t code) { ascii_font_glyph[current] = grub_malloc (sizeof (struct grub_font_glyph) + ASCII_BITMAP_SIZE); + if (ascii_font_glyph[current] == NULL) + { + ascii_font_glyph[current] = unknown_glyph; + continue; + } ascii_font_glyph[current]->width = 8; ascii_font_glyph[current]->height = 16; -- 2.30.2