From patchwork Fri Jun 30 18:03:51 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: 697957 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp593094wrs; Fri, 30 Jun 2023 11:06:36 -0700 (PDT) X-Google-Smtp-Source: APBJJlHu4hqcuji1QboC3fxPDZUBltM91GocQZ+8lyYAmyxDSTnbyJCxAcaDPXFqwflA7w+W/2+7 X-Received: by 2002:a05:6358:cc2f:b0:134:e5ec:6ab6 with SMTP id gx47-20020a056358cc2f00b00134e5ec6ab6mr3363667rwb.25.1688148396134; Fri, 30 Jun 2023 11:06:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688148396; cv=none; d=google.com; s=arc-20160816; b=MfCfdaHhBgumJOGyZSSrv10NHt2S07SGtiNP2+EMKVRYCL61QlKmIxljIf44wluF4u CySSjAgb0etY4GCgKAdKh5i8pV0sqzRiyT6dPoel5w0TlFF0KzTzJ/3t8TY7J/C+fBuS XRwA3FBS4fmb+4Rmo3MVfTU2bEEEgZ525XDcyKqbM8O1/Jhc+RX+QHxm/Guu1VPq9Z0d +NAmAWd9B8/Zg8UXAT6oh5OhgfDoN75ZzfUQedu6IarngbAPWScll+rXpftt0eaRP85D Ew2w1j6KzpwzvrAeO8hXMOjy0wgArRGzT6u3sgpW65umU4wPeLUg6RKnUePtP/RbDXjT 5UDQ== 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=OltHerz+Vf7zZkebZbScoRT4WgVwJDskRS7DoEjx2Hw=; b=My4fEsM1veEyZVvAHQzeBZVb06VSUA7Eyyt3uQMES6H3cUKfGRAzPO1NqnRnHvydyE yoAZrUe3iO3P+u9veJ3fgYtt+J2lKjq5hUswrAOj6Cd8Zc/Ac0oiDGBLFD8n1VxsPotG go3sCcJRkUSbKp7SSyfEd/U8HFBUOOjmD/RN+b2tnv2hdOFwO2wKZGthEvbXwEteATGb 814PvWYvUE/5+XxUhAoBo4bT1RBuf1wQTaZ4fX/D64/TWyMJlky0MarE9SdAomKJg0V0 stL75zpPO1HSslxYxfVRqMnkHH5lqnOToEtm3F9mM5hlzH7hScZbL7XDESWWVAleSESS 1ATg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MpO2MOS4; 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 m20-20020ac85b14000000b004033ec2f5e4si1401790qtw.464.2023.06.30.11.06.35 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 30 Jun 2023 11:06:36 -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=MpO2MOS4; 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 1qFIUB-0008Q2-PO; Fri, 30 Jun 2023 14:04:47 -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 1qFITx-0008IJ-Rc for qemu-devel@nongnu.org; Fri, 30 Jun 2023 14:04:35 -0400 Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qFITt-0006yt-Pq for qemu-devel@nongnu.org; Fri, 30 Jun 2023 14:04:32 -0400 Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-3fbc12181b6so19815185e9.2 for ; Fri, 30 Jun 2023 11:04:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688148267; x=1690740267; 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=MpO2MOS4a98PEtb2uWvjbuhddvjIe20YxqcF3E3H8bVlwK2tLZ+90AxPHqHk9qJqzY 2gPtLSIJj3hFE7C7usNN64fgOBoeoS1cfO+DgM9sqo+7CDm0hKlcQMZRRpypk6QfckWf bvc+EDldvonBgUdZaLLFTNZiWzwcVPW9s5V7wyfWRmeJ5H0kcOfvuctgcK8FZfP+ubtP crRYg39gl7y1/tj3at73i2yv333nzywosh2ljppkTeyHCmb/nipiGbdYcOLzut/ZVBlH GfDxrp7inwXlasLtPzcSdO6mtjMIDfi2tNoauXOuNsX0wBMdcysR9puTXZ5G3OsskeL4 DCbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688148267; x=1690740267; 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=XIEKQjqB3mtCd64lJhemvdt2cH4vvwb5ZCWyBf22MhBqY6eApOJ/7+1HkR82An4eHX EpoW8l844Y+UKS26I+MUU+pumBY/axgt1oXiUqkSyH1WGO6EZ7ZWqvd7UHOvnrpZnO0T 3ReIDR/NnaGY4lc3izbdwuUSLMlsY/+hzRzF8YOOwcpR+7FrDO8qVifmczphUcO9/Nsr Czwb48vLBJ2Muvb/RdTUGD31m7Jce5CmhDlqsx1Q6fIhMyL8uhxRq6p5XHJ7jVKFWofW GB6EmrNgC8o7QbfYPtX/hjxQcz8aAQ5BqVwj4BwC316t7d5SLbP8X5xV25rbx26L5Idi 3K/g== X-Gm-Message-State: AC+VfDya2dUWhhDihmaRAGeRIeovqphnf0fNfFASfrRXVDuqnHQwdcq2 S2DzCNLvd5ipwtgJ8bZPHFCWOw== X-Received: by 2002:a05:600c:2299:b0:3fb:b2a5:aeac with SMTP id 25-20020a05600c229900b003fbb2a5aeacmr2508315wmf.20.1688148267615; Fri, 30 Jun 2023 11:04:27 -0700 (PDT) Received: from zen.linaroharston ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id y5-20020a05600c364500b003fbc9d178a8sm1192326wmq.4.2023.06.30.11.04.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Jun 2023 11:04:26 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 8BF481FFC1; Fri, 30 Jun 2023 19:04:24 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Paolo Bonzini , Stefan Hajnoczi , Leonardo Bras , Laurent Vivier , Peter Xu , Juan Quintela , Beraldo Leal , Radoslaw Biernacki , Qiuhao Li , Peter Maydell , Yanan Wang , Riku Voipio , Wainer dos Santos Moschetta , Mahmoud Mandour , Alexandre Iooss , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_M?= =?utf-8?q?athieu-Daud=C3=A9?= , Eduardo Habkost , Thomas Huth , Laurent Vivier , Bin Meng , Marcel Apfelbaum , Bandan Das , Cleber Rosa , Richard Henderson , Leif Lindholm , Marcin Juszkiewicz , qemu-arm@nongnu.org, Darren Kenny , Alexander Bulekov Subject: [PATCH v4 06/38] qemu-keymap: properly check return from xkb_keymap_mod_get_index Date: Fri, 30 Jun 2023 19:03:51 +0100 Message-Id: <20230630180423.558337-7-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230630180423.558337-1-alex.bennee@linaro.org> References: <20230630180423.558337-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32a; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x32a.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=unavailable 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);