From patchwork Fri Jun 23 12:20:41 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: 695233 Delivered-To: patch@linaro.org Received: by 2002:adf:e885:0:0:0:0:0 with SMTP id d5csp1920034wrm; Fri, 23 Jun 2023 05:22:39 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4MEK69c4au/qKUWyxnhl5UUchhPM/MvWjtQN0RS3XpfyOcyJHMZXDv/GUNzqzc3k6hUPni X-Received: by 2002:a05:622a:1a1d:b0:3f3:96c9:b071 with SMTP id f29-20020a05622a1a1d00b003f396c9b071mr18256602qtb.26.1687522958913; Fri, 23 Jun 2023 05:22:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687522958; cv=none; d=google.com; s=arc-20160816; b=YtJLcheGcID1K8hqShJj3InFUYD0Qob8+TgJ9Avqs+0ESi9F/ZBHZaA63y2ETxIMfh yS5XV/n+EzyMg7Owo6GPxJO3YP2m7HihIvJotjRYlfhGoO95QEgZX/PYwxVCRT0/QGZZ QShh6GiJnqJGoNQivoICU0oN3rIqkRkYz2mGrfFJM21M+XOqHeSjvyxr/N9LfYI2EJot bEVv7MfxOO19GqU3tNBUd0zbMKPtIAPyfghUXJYnmdisNA3wDnpA36JMT6xmXMthz6CA SEkbbekyEdqXnEq+k2vDvD05DMzFvErbSUyc98D+/T7LhrvMu1ouav50rXGE6dOdBWjc 5EUA== 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=UiwEwjAi6lomr9E2iVsjR5pQJHgLNYXOTgd+ktx/cfE=; b=Csd8x8b8JQxXNlhl8t3narQOAxMt53MYJH2rlTp0ggzsMm1b8VvoJOwBZXs+rxBNlS L/6yBm2gIuIONDbDP4QULomARjVPt1ZofNWG4QazEw8iR9ez6OQsD7ghpHroOsru8NaW GjqBsh2tqZ2BKvY3GEptCp266lRFvzCEjAJvLWi71LAztLSRuEHPB4bnpRib52sa6CsE EshFuSzrTi95Q4/aHgzDFBJB5bTAgzP1wPyi66pc63vG9x4sKCHENy4zcnNsQpbY2Z2/ WdNFmYgTB7qBSW5LTuQ3hSbUkqTOGNXLcv1jlTPSFDS5Xf3Lw4dEP4ZhT3DEIrsOQFER KQRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="u4t/Tgi8"; 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 n22-20020a05622a11d600b003f4f5bfe7a3si3632380qtk.31.2023.06.23.05.22.38 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 23 Jun 2023 05:22:38 -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="u4t/Tgi8"; 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 1qCfo0-0004Vt-R4; Fri, 23 Jun 2023 08:22:24 -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 1qCfmv-0003oA-K5 for qemu-devel@nongnu.org; Fri, 23 Jun 2023 08:21:18 -0400 Received: from mail-lf1-x12e.google.com ([2a00:1450:4864:20::12e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qCfmo-0003hO-Hj for qemu-devel@nongnu.org; Fri, 23 Jun 2023 08:21:15 -0400 Received: by mail-lf1-x12e.google.com with SMTP id 2adb3069b0e04-4f870247d6aso706492e87.0 for ; Fri, 23 Jun 2023 05:21:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1687522864; x=1690114864; 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=UiwEwjAi6lomr9E2iVsjR5pQJHgLNYXOTgd+ktx/cfE=; b=u4t/Tgi8JNEuzIancjMufZUWhxuNov8a4Y93qN9/0qphNFe21QqNLKzQykIBIlUZvo bVB9HvJT6CgfPh7M1SaClNkKi8buyRlhhUXAxJpKYUbk1LF6hUApYb77S1rSRV/Yu6Xb vAScRVQU5irjrkcB2TtZotE3taJDDXgFzlTZvXgzKv42PbOKBs9mFN2yo+Z8kPWiEdQw TZbVH2vmk4b9ymnZ8FU/+DniKH9TURSyNaICHiZstfNzi0u2Wp2unPPD90lZMDtQs0CK AMIIt2OMRZP0ZIpO6Us2oVpZl0nM3WxqHlDM7E7l1B4txjhBrf0jhmvYWTch8mxeZXwK ZQbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687522864; x=1690114864; 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=UiwEwjAi6lomr9E2iVsjR5pQJHgLNYXOTgd+ktx/cfE=; b=ai2Aq9biaspCO8GQ7THcF5vWNydviZJvaTeznlteJ5zHTkBk4JKuwxOcx1q2neKM+a ko9JT5ZIOzRt6qER1NFkYEYP6eQhh1F/VkA0bk73b0rgPhROkr2E9MCImR1V5Hv3QqRt zE6JhEx3U6PjpFifG3n4v3TLv6il7rgieji9y4QxtIastRkou4DKaL/DT3qqPSMxZG2N muOx/YPu1QdQvC9ED4LjWZYY9iA0eGzi6WdKzi3ejouH4aR4Im+1X9M2g2bPxCCAf+Qa 88w5S9iwSM3G34mwUPcC1gR1aRE91RMj5raL94tdpLm9Tv6qtGYLSm84maWrqqWmJXtX VWIw== X-Gm-Message-State: AC+VfDzqHA9onhdOvRjehLOG1bVkoJjAH2pot9Ldchv1WkidCsnITQBC mbl0Dyb+cQYmfrCqHhrzC8yEbQ== X-Received: by 2002:a19:ca02:0:b0:4f9:586b:dba1 with SMTP id a2-20020a19ca02000000b004f9586bdba1mr4956649lfg.4.1687522864472; Fri, 23 Jun 2023 05:21:04 -0700 (PDT) Received: from zen.linaroharston ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id q19-20020a7bce93000000b003f9b53959a4sm2159572wmj.43.2023.06.23.05.21.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Jun 2023 05:21:02 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 494361FFC2; Fri, 23 Jun 2023 13:21:01 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Richard Henderson , Juan Quintela , Peter Maydell , Cleber Rosa , Darren Kenny , Alexandre Iooss , Peter Xu , qemu-arm@nongnu.org, Eduardo Habkost , Riku Voipio , Mahmoud Mandour , =?utf-8?q?Daniel_P=2E_Berrang?= =?utf-8?q?=C3=A9?= , Paolo Bonzini , Bandan Das , Marcin Juszkiewicz , Radoslaw Biernacki , Alexander Bulekov , Leif Lindholm , Qiuhao Li , Wainer dos Santos Moschetta , Marcel Apfelbaum , Leonardo Bras , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Stefan Hajnoczi , Bin Meng , Thomas Huth , Beraldo Leal , Laurent Vivier , Yanan Wang , =?utf-8?q?Alex_Benn=C3=A9e?= Subject: [PATCH 07/26] qemu-keymap: properly check return from xkb_keymap_mod_get_index Date: Fri, 23 Jun 2023 13:20:41 +0100 Message-Id: <20230623122100.1640995-8-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230623122100.1640995-1-alex.bennee@linaro.org> References: <20230623122100.1640995-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::12e; envelope-from=alex.bennee@linaro.org; helo=mail-lf1-x12e.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 which rightly gets flagged by sanitisers as an overly wide shift attempt. Signed-off-by: Alex Bennée --- 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);