From patchwork Tue Jun 27 16:09:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 696890 Delivered-To: patch@linaro.org Received: by 2002:adf:e885:0:0:0:0:0 with SMTP id d5csp3868314wrm; Tue, 27 Jun 2023 09:17:46 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4hghk0xvxs2179hUBiDIA1GxxjyXNbPAqx4DoFnku/O+j2q+9yrkBUoCCOs4VB7ICPIUvv X-Received: by 2002:a05:6808:14cb:b0:39e:cb0c:c639 with SMTP id f11-20020a05680814cb00b0039ecb0cc639mr38507733oiw.4.1687882666420; Tue, 27 Jun 2023 09:17:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687882666; cv=none; d=google.com; s=arc-20160816; b=VTZkRb0LTHneUKdXhrFhrxZG8r7MF/+MLX1t1tOA7o812CiKxj6EQppbTQLvT+MM2Y oKILPmuuAOLCLdSGrq0d7ODxBzjiRGrhfV8dhWrUYSOdEp/uz/SP9dKFBNAwr/3CeIa5 UM23O1KSBZrXeKcwAdApjOYJJgcbeL1MFsTvEXCYPpHUtCTWtm/snyiHkx5kicXGONaV L/TTHcAEXeh2gsPal3gRjwfwW7s/YTd38QtxfRPjbMaN1sV8jzj6u7HIPhBxANbCuPtM aApWZxml0kC1/7fPNVoB1pdrTV3CJBEXb0RY+8QsL6btUOYXqLHrsd0cq06Pk2yhQJ1I T3dQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=JwYXISrmUwYEeEBYbvf+rC+BgUtqy99AwD9pTl/rVpc=; fh=ArV5Yx1z9lg+jufSSsiXTUg87d1rJ5PmrQDHLSB2i58=; b=qHhJ8KJT8TfOERYqmatbTWufasbPNxTrzR0Jd2XH0h8lb26V0g4JcC9jl85JEZkMjE aTORaDvTjeUcn7H6PjY8P31KmPsxMHJ8CdAo09Q98qnft0qv6t8lqlC7Fiw5h2fFyh5V pJPOKaSeAjsL21rtDOrxT/gLbEYBwUDV5eCWVhQUFcpXY8BorgrGKMnYUwcARopkP9BW IcA+Z5fuogmgd//WO7pf70qRJ0e5Td9Qx1kAb84z0pb7t4CIxlJzluC/GDVwVrHTxySp hX8A4zLtZ84m7ck/n55HAb9aUNHpwuoe6hcmsh3Ryrp2X7mdlttHBoVbwllfYPe1Xl1G R22w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xlQSGBHA; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id z9-20020a05622a028900b003f9ccf932f0si3304807qtw.605.2023.06.27.09.17.46 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 27 Jun 2023 09:17:46 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xlQSGBHA; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qEBMP-0001CV-MA; Tue, 27 Jun 2023 12:16:09 -0400 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 1qEBMK-00016f-8o for qemu-devel@nongnu.org; Tue, 27 Jun 2023 12:16:04 -0400 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qEBMB-0008A1-QQ for qemu-devel@nongnu.org; Tue, 27 Jun 2023 12:16:03 -0400 Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-3fba66f3e1dso8276105e9.3 for ; Tue, 27 Jun 2023 09:15:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1687882554; x=1690474554; 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=JwYXISrmUwYEeEBYbvf+rC+BgUtqy99AwD9pTl/rVpc=; b=xlQSGBHAk2dlQ/9WRsnCMFXkgv65KdRtfZR8wjkzDURh0rA+Xn0rOje23/4U6kR/+L /8Gd657+oq0w80zVTq3nu6bWy6yIRE2/7yngjIiNfQOUiVixGQTiDC8/AYkug6nTMXVW Rstq4ZxyztYo+QnejsGgUFBN/iDbNski2GM9N+UoooKZi3lyAaRozGGRKT+FeLLMdTrq ExS7hzKhbbABjo//yXgml79yariHWw2P1f1x+Qbhp/iESC4m6isPc7Xdv7Qkk/GY8gw7 F2UI0foP2pD8zWkmq4EkM/DEezcqsX+IJOkegLgZ9iBaShHhE/Lg2n/UdSz3mzrqSYni /98Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687882554; x=1690474554; 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=JwYXISrmUwYEeEBYbvf+rC+BgUtqy99AwD9pTl/rVpc=; b=H6EO0ie2C+7BQrcV9Z4IDWI0U5TF0ePogtBF+NxwtFyCg9XQeD8MdRgocv4w+YzQ/Q jV+c0a1AS1TocBwVs+C9JK4yXeG4YwPyncX55ejgzjR7PPmL3paP1xbttpnGXGFgrK5K qWqnwMUUd+w+A3dnJmjTk97Wdc3QTnEztNt4Z+nIWf1ipzZrHbOUXeQx2KddBOoyWFt3 a8IcSVh7mqJ7TkCEtTq2CajDQHdTzI240Nl3DhHzddWuJQwvdwpgjX2raP3zvHXymZYy 6m3UrCH/eBeOhAYpd0R00hWncdoo4hrpfxV/fvdHJZY51CDAQWNaILIitwX3BhVNM8Fj 7o1g== X-Gm-Message-State: AC+VfDyTNFVHhZdoIOjXUjZlw0fCHuNlMWNoNHs0FBpkcyjUdMDkNxUv 8W6dTdPu4VCamymYgN7uwOeAgg== X-Received: by 2002:a05:600c:2903:b0:3fa:7fb1:11df with SMTP id i3-20020a05600c290300b003fa7fb111dfmr7395796wmd.19.1687882554404; Tue, 27 Jun 2023 09:15:54 -0700 (PDT) Received: from zen.linaroharston ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id m13-20020a7bcb8d000000b003fba97b1252sm1302569wmi.1.2023.06.27.09.15.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Jun 2023 09:15:53 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 8A6EC1FFC2; Tue, 27 Jun 2023 17:09:44 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Wainer dos Santos Moschetta , Juan Quintela , Thomas Huth , Cleber Rosa , Leonardo Bras , Beraldo Leal , Peter Maydell , Bin Meng , Yanan Wang , Darren Kenny , Alexander Bulekov , Marcel Apfelbaum , Peter Xu , Radoslaw Biernacki , Laurent Vivier , Paolo Bonzini , Eduardo Habkost , qemu-arm@nongnu.org, Stefan Hajnoczi , Richard Henderson , Bandan Das , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Dani?= =?utf-8?q?el_P=2E_Berrang=C3=A9?= , Alexandre Iooss , Marcin Juszkiewicz , Leif Lindholm , Laurent Vivier , Qiuhao Li , Mahmoud Mandour , Riku Voipio , =?utf-8?q?Alex_Benn=C3=A9e?= Subject: [PATCH v3 06/36] qemu-keymap: properly check return from xkb_keymap_mod_get_index Date: Tue, 27 Jun 2023 17:09:13 +0100 Message-Id: <20230627160943.2956928-7-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230627160943.2956928-1-alex.bennee@linaro.org> References: <20230627160943.2956928-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::329; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x329.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, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org We can return XKB_MOD_INVALID for AltGr which rightly gets flagged by sanitisers as an overly wide shift attempt. Properly check the return type and leave the bitmap as zero in that case. Tested output before and after is unchanged with the gb and ara keymaps. Signed-off-by: Alex Bennée Reviewed-by: Juan Quintela --- qemu-keymap.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/qemu-keymap.c b/qemu-keymap.c index 229866e004..8c80f7a4ed 100644 --- a/qemu-keymap.c +++ b/qemu-keymap.c @@ -140,6 +140,18 @@ static void usage(FILE *out) names.options ?: "-"); } +static xkb_mod_mask_t get_mod(struct xkb_keymap *map, const char *name) +{ + xkb_mod_index_t mod; + xkb_mod_mask_t mask = 0; + + mod = xkb_keymap_mod_get_index(map, name); + if (mod != XKB_MOD_INVALID) { + mask = (1 << mod); + } + return mask; +} + int main(int argc, char *argv[]) { struct xkb_context *ctx; @@ -215,14 +227,10 @@ int main(int argc, char *argv[]) mod, xkb_keymap_mod_get_name(map, mod)); } - mod = xkb_keymap_mod_get_index(map, "Shift"); - shift = (1 << mod); - mod = xkb_keymap_mod_get_index(map, "Control"); - ctrl = (1 << mod); - mod = xkb_keymap_mod_get_index(map, "AltGr"); - altgr = (1 << mod); - mod = xkb_keymap_mod_get_index(map, "NumLock"); - numlock = (1 << mod); + shift = get_mod(map, "Shift"); + ctrl = get_mod(map, "Control"); + altgr = get_mod(map, "AltGr"); + numlock = get_mod(map, "NumLock"); state = xkb_state_new(map); xkb_keymap_key_for_each(map, walk_map, state);