From patchwork Mon Jun 26 21:59:06 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: 696493 Delivered-To: patch@linaro.org Received: by 2002:adf:e885:0:0:0:0:0 with SMTP id d5csp3446474wrm; Mon, 26 Jun 2023 15:00:22 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5onQF/DH1ehiV2PU89jX7q6rXm5SCv9bUapoRTguMXq7qCDso02rJJ2eoankeMabY9BVxM X-Received: by 2002:ac8:7f10:0:b0:3ff:23da:6676 with SMTP id f16-20020ac87f10000000b003ff23da6676mr23948655qtk.2.1687816822716; Mon, 26 Jun 2023 15:00:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687816822; cv=none; d=google.com; s=arc-20160816; b=P0t96IhqUufoeYCYAj4jWHCDAYAZ0I0Cq9VXC9AwsyZX5AsFFMARZUZ2a5BH7l0ogp whYHv72eFXA8zQ7YvEqv99K9Lnjsi4vnJincnhTUn/Yk5wX0lhrnf3uTqsIKoQbk/2vk wLKhwwER+tbgxYpsYPDz6CkWesVLChaCr/nVXgToQYku5iZZJzlS9Sms1F4QzC8eG9Zh xVv2gBOV4OZljmlXVIJLkYGOcBr4qnd+1ngYB7D7tFCZzTLlbb/rQps7bGMOmeMGOhe/ XWt+/PfYmkAqhlAzScKFW35hD5mpd2asqcjcpVhm8sFA4mq8X6mFccwIaZHiCQWXjaxo qINA== 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=; fh=sQEya64SXtq2IEsk3H77u01QQAMvGjGQGvqUW/mcVd0=; b=BDwtCCrdIzyXfr8zh+2D2rV9KFK0ScPMDcUxrA1pQ7YFUSbbAwYXHZZat5YQSYXb4f wB9rGwjOR7qvl9VVz3hakOykZkCjpLFBp5CPu5aElgz2phUaQoLnayXDDJh//S8YZeYo Om14+wI9ITYgNqVaxb1Pzy0aX9aKYC8WbOIxkOeS3LlLuDd64AARP6S7gPl8tn99ke48 Ui5VMbuWkXaNxoBZOWP1awwlKD0vu0HrKaaPzY/KhO37LdxbeDbx2UvO3c9cVx/G1bJt yK/g4vkDc21HApjlblOhZnAurQHBQuT9frKyPK23NGoOBzYBafp772e4nkgDXq+Mnkq6 t7kg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QkOu34Yv; 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 a12-20020ac85b8c000000b003e654e6f272si2317321qta.185.2023.06.26.15.00.22 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 26 Jun 2023 15:00:22 -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=QkOu34Yv; 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 1qDuFH-0002cU-HT; Mon, 26 Jun 2023 17:59:39 -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 1qDuFD-0002ZT-Uk for qemu-devel@nongnu.org; Mon, 26 Jun 2023 17:59:35 -0400 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qDuF9-0004ra-NV for qemu-devel@nongnu.org; Mon, 26 Jun 2023 17:59:35 -0400 Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-313f2a24cb6so1564719f8f.0 for ; Mon, 26 Jun 2023 14:59:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1687816770; x=1690408770; 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=QkOu34Yveyl8EiKH6w1I+VpWN75HOx78BZ1f3bRxys7JRSBcYpRQDaubEmoDaD/1S2 ly36S4aKVBzALA0WbqzrX4gQM9SbW7SDmG1FLCCTQ4Bp9mh72aELgwCiI4jb1imBhGCW wEJsNTJTJzZQ8o89uKQX8czAt4GgUVKKBJimGqI83NfBGU+M77/sOkP5ZRt3pW1CvocU h4vdapLDWWdG1Jcs7dSB7hiMuruutsiJbZ+sP8GwclBf3uRJ3i11hbF3EnzjRS1nX/K7 Vh9RY/1Z5PyEdaAG43p4NMyuM2DoTZGAV/8ZJJoSQRkYNP5eKCvFAP5i9/dWgznEJj1g YkoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687816770; x=1690408770; 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=lBcI6Rc5IPxUH3QBlQrBvj+wrZW/JsLwKIRYFvq2c+4FDrCSfBRQKjWhlbyU2f5Qgg 2ISCxTwgw2VjfpiA5e116XcCk6/DY4ARoZIFBwb1zBmBWvW1dnao7JIvM/Mok+u3xZy+ J8jvEgVBondci1fbELLAvFB8HiPDQHX3OjiTRVtQ+90riZifr8qqqKwfxfNSpOn0maY9 oNCFq0qCudLTPDnHoO7WNM51iOkKnTdcFZtvLBQxrYoa0Akvuc8vs+Sr45oZdtVgdzZG xwvSiF2gj1mnw59v1HEixTjFTBkfY83P2zjwGc7ohUS5J+ZGE10G90lP7/2/XwMVzZ+5 zrwg== X-Gm-Message-State: AC+VfDytNlTRPMlVXGKsdBkEr75hi+GwaMoNXVeyma5HzeB8wecNSqCV AUwYyem05lr85D1FqmwtmgGNUw== X-Received: by 2002:a05:6000:d0:b0:313:fca6:5f56 with SMTP id q16-20020a05600000d000b00313fca65f56mr212679wrx.8.1687816770334; Mon, 26 Jun 2023 14:59:30 -0700 (PDT) Received: from zen.linaroharston ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id f4-20020a0560001b0400b00307a86a4bcesm8511640wrz.35.2023.06.26.14.59.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Jun 2023 14:59:29 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 863FA1FFC1; Mon, 26 Jun 2023 22:59:27 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Alexander Bulekov , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Juan Quintela , Alexandre Iooss , Thomas Huth , Marcel Apfelbaum , Leif Lindholm , Riku Voipio , Peter Maydell , Paolo Bonzini , Bandan Das , Leonardo Bras , Cleber Rosa , Richard Henderson , Beraldo Leal , =?utf-8?q?Alex_Benn=C3=A9e?= , Peter Xu , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Mahmoud Mandour , Stefan Hajnoczi , Yanan Wang , Eduardo Habkost , Bin Meng , qemu-arm@nongnu.org, Wainer dos Santos Moschetta , Darren Kenny , Radoslaw Biernacki , Marcin Juszkiewicz , Qiuhao Li , Laurent Vivier Subject: [PATCH v2 06/26] qemu-keymap: properly check return from xkb_keymap_mod_get_index Date: Mon, 26 Jun 2023 22:59:06 +0100 Message-Id: <20230626215926.2522656-7-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230626215926.2522656-1-alex.bennee@linaro.org> References: <20230626215926.2522656-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::433; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x433.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 Reviewed-by: Thomas Huth --- 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);