From patchwork Mon Jun 3 08:55:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dominique Martinet X-Patchwork-Id: 1942758 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.a=rsa-sha256 header.s=20230601 header.b=qao7qCdH; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=googlegroups.com (client-ip=2607:f8b0:4864:20::738; helo=mail-qk1-x738.google.com; envelope-from=swupdate+bncbcwivbv7sugrbluk62zamgqet3sevui@googlegroups.com; receiver=patchwork.ozlabs.org) Received: from mail-qk1-x738.google.com (mail-qk1-x738.google.com [IPv6:2607:f8b0:4864:20::738]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Vt6yp3YtHz20Pb for ; Mon, 3 Jun 2024 18:56:18 +1000 (AEST) Received: by mail-qk1-x738.google.com with SMTP id af79cd13be357-792ff352462sf595869485a.1 for ; Mon, 03 Jun 2024 01:56:18 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717404975; cv=pass; d=google.com; s=arc-20160816; b=k57IhJr2A6ttWIbzVhy+g68MqrfC+tPRv1nU3MsebzmR++bNvgrfnqcgxuuG63v8ys T78nUs6uTo31EVH1MrXn3+3DwVktAFAXb4JM4P6TFzxdfkHq4GLwN8ddIOtPCWVB4om1 tKT8bqIAt99hpQrC4xpNlFjLkuyc9WaGmhkNuoDotHgv4UkXmIQx7yKdAxtKx9+b0zdc 0LXHrlLmUfo20Dfjgj0EvUURFvSeRVy/BabRmpTGJj3DMaoeYnPHmzzlFd/FtnyOGoLL 3EMC6+NqJsGjbe/galj5ZfcBPL8abdOKb3ktCULBptD9wNQSMuMqsdD6VNnk9x7HDtPG Bcfw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:dkim-signature; bh=JuseOxxHRFjPb9zh1fWzIb2iAU3KgcZc//YvP67EXMQ=; fh=+HOhZVcH38yXfp1jho6rEMtVed0J8BeDvWIx/QQx6jg=; b=irHsS8XLTiu/GqrzLKaAH/rJ6B0Pmd53iypzNiJKPbXmMxIzjjGR5bmRPcjdNVXOo/ lZdSUOo9pEla6DjQNcjRtQ7QPxmiN3n/+qdRVHHPtps5TZ/TzosIKDXDfhaTGoBrCad1 mtQv6aDt4TdqoY8qLzVI2f+Qf/9UqOXHopoPrKFTJ6Av+0w4zKFt9Nlp01WZqRj9fcFs v33KwUQZZPxqHHYQ1cOzqCBFSREJOJOBepG7kfHKcegztsIS3u/0nAz7HRtY23SUugLe TSK612NGQ/+hQYdrnhsEE9/k4bnGvU4k/qWg6NH/+yj6NhSasyTpdCkzTez8S60GkEsj aBzQ==; darn=patchwork.ozlabs.org ARC-Authentication-Results: i=2; gmr-mx.google.com; dkim=pass header.i=@atmark-techno.com header.s=gw2_bookworm header.b=x2beX1Gu; dkim=pass header.i=@atmark-techno.com header.s=google header.b=In1PilU7; spf=pass (google.com: domain of dominique.martinet@atmark-techno.com designates 35.74.137.57 as permitted sender) smtp.mailfrom=dominique.martinet@atmark-techno.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=atmark-techno.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20230601; t=1717404975; x=1718009775; darn=patchwork.ozlabs.org; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:x-original-authentication-results :x-original-sender:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:sender:from:to:cc:subject:date:message-id :reply-to; bh=JuseOxxHRFjPb9zh1fWzIb2iAU3KgcZc//YvP67EXMQ=; b=qao7qCdHgVPz0iljj56ufjB+7C2HfWsVLmGfqojhmjTQnf2u+uUBR+cGruw9puXnQx Vij4I6yHNea4XoNUH7Lt4ntlCl9WgfE8EwfDRS0kOfTM+7FRigeDg0ZXGDwAzn0VqQzv TrpBQYp5Z8zHn6jBrwB6l3WR5S23xo0UqF55/4ZS0k0/8yJIjbOms+yo0dMNsPttZskk OxDS2RUXdo27gwGRrnxm3Y0Jy5yFUbuNfUsB2tf9c4BmzzGkBe7bCX9oxZVZjXuvKqAs oG5kbkDUPue66umTEgDhOQXfUi1MtXS21r4/kRFobJ+M+WYdi+vb3+VCzLxS09S2gVC/ YeWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717404975; x=1718009775; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :x-spam-checked-in-group:list-id:mailing-list:precedence :x-original-authentication-results:x-original-sender:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :x-beenthere:x-gm-message-state:sender:from:to:cc:subject:date :message-id:reply-to; bh=JuseOxxHRFjPb9zh1fWzIb2iAU3KgcZc//YvP67EXMQ=; b=YBT8CZ+ji3y7TQjIJwExoS29cveb317S+ZyPflSkTkF26x8lBS8x/ozYJmQJy1Lyw/ ZgLO3U/513Fw/PckyJHORGjcTBU3Yw3FQWgk1jPSvQDfxCjtY3MfGjuNhphufNb3pkSn G8atPpKyU0qUzYUK70cMcDhtXd9cOINlj6nzmVwYcYpVgNNkx/t62p8nkLwwvxkaJzTF TwqFysUJmIwmPdmVf5b4mjrK46vnd6hWGWXZU9x2XhzD67V9/ahCEK+41LkDDUBC0G74 hW14EN813MnjbQqU0/V+r8EBrPO1k8223QAWlDxyk8RpnohmwYZbHRmIPG3FF4PtP5f+ dX4g== Sender: swupdate@googlegroups.com X-Forwarded-Encrypted: i=2; AJvYcCXiCPJDvaI3NhLe1RrzFAq9UuFSCyzKOdGSUKhlTtanHYhlxSAoQmXxBwpI9O98/nbDX4Q7dZuNaRqCpd0sjxgltNPV6GtrvyzFuCAP6A== X-Gm-Message-State: AOJu0YzzilZsKJ4K9QPdZKVf7k27y1RFFqCrIVSHC95vNS2yR7vPBEI/ AaogK6bsZj0qXiLKH7/EKsdcj9j7vk6XgjeYcPrvKQmvlSYu1SnK X-Google-Smtp-Source: AGHT+IFYSDXfJHS9HlpCthFNKPOHgDOq1o6GOQ8eiq2huviydTzXOoKJhiXWRcoR9v6ICAcUfTK++Q== X-Received: by 2002:a05:620a:564f:b0:78e:db73:913b with SMTP id af79cd13be357-794f5c6e0fdmr945528785a.28.1717404975240; Mon, 03 Jun 2024 01:56:15 -0700 (PDT) X-BeenThere: swupdate@googlegroups.com Received: by 2002:ac8:5d15:0:b0:437:8eae:5bbe with SMTP id d75a77b69052e-4400188cfc1ls24565811cf.0.-pod-prod-05-us; Mon, 03 Jun 2024 01:56:14 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWzw/DI0YDVrZ6z3Hl4OjtH2JW2HBDDOkFfovrz9zSiY/4FH/WaA93CLWEGEOBPi87jyC8QhS1Je5y+hBuK4H18TfyLaz0SpftG X-Received: by 2002:a05:620a:190f:b0:792:bc0b:e269 with SMTP id af79cd13be357-794f5cc688bmr1022753785a.52.1717404973909; Mon, 03 Jun 2024 01:56:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1717404973; cv=none; d=google.com; s=arc-20160816; b=jEawEUjYbqV8VQnjkTj5IRPBKpatSYjy3PqttD3hF1QD6FkYwNAKVIiweWKPCajwe+ DojxCEY64WoFs19yK+BtSmABsAH0H6IoAXAXX0eZKFj5AWEB/aeYe+aSOGr0L5y5VMYo Q3tKCuA/cMbDTskCdmPoHO69ztE9amxFGC8Qa6zschVc5kJl8NsG6dntQCfJ1CN4LgW7 XWlMK0exUjtRZa8beLLVDUpr8p5ErqH2Au6GFiSVoL91xLlTDR1RZ3j1SGvg5EVUDiMT /HYNJlnfZxp7hgs18T0tEKdAaqclBNHNDCEqgT30hnsfhyRBehL1YnvnptjCnBy+pXOP 9klQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature:dkim-signature; bh=W359nTpbI1Fk9qW+AIt/2jgo7M+eI255ymHh3tAJmZs=; fh=e6ThJdgbDrjaxNT9UZhiDip0vc8vcYglFRKaU5kdzM0=; b=ucCGNyoLv5EIknVN2HhJu+jIK/WzX5cfFYErZsP+n8utK9FST3c25nBefmSxyYYDLS e+MfptjJU5bdfU00L804g5eieetScoe5DqPXncOAODYCo94vNVHF3G5G3Oc/opfFrjDt X/bWJvxh8q36bcWWPTFnXG1+i2VHI0xL/IQSzUgspIy0kES/C8NDYnNXFwCK8MEtv/hw U/kd6fBv6aTLAk/dvQhPX6Lp7Hw06c+r0wO4/mb0LqUdAgzviloISQ8r9lz+hpfqp9zg jONlLTDnHENbxgPStwdjRfBlf3FZoMDTUOUj8myBmhrgKAI8qtasMCefS47JUQH6Mjz6 stlg==; dara=google.com ARC-Authentication-Results: i=1; gmr-mx.google.com; dkim=pass header.i=@atmark-techno.com header.s=gw2_bookworm header.b=x2beX1Gu; dkim=pass header.i=@atmark-techno.com header.s=google header.b=In1PilU7; spf=pass (google.com: domain of dominique.martinet@atmark-techno.com designates 35.74.137.57 as permitted sender) smtp.mailfrom=dominique.martinet@atmark-techno.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=atmark-techno.com Received: from gw2.atmark-techno.com (gw2.atmark-techno.com. [35.74.137.57]) by gmr-mx.google.com with ESMTPS id af79cd13be357-794f305ae8fsi35871185a.4.2024.06.03.01.56.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jun 2024 01:56:13 -0700 (PDT) Received-SPF: pass (google.com: domain of dominique.martinet@atmark-techno.com designates 35.74.137.57 as permitted sender) client-ip=35.74.137.57; Received: from gw2.atmark-techno.com (localhost [127.0.0.1]) by gw2.atmark-techno.com (Postfix) with ESMTP id 75955A7C for ; Mon, 3 Jun 2024 17:56:11 +0900 (JST) Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) by gw2.atmark-techno.com (Postfix) with ESMTPS id E89ED932 for ; Mon, 3 Jun 2024 17:56:09 +0900 (JST) Received: by mail-pl1-f200.google.com with SMTP id d9443c01a7336-1f6768af0b3so8042925ad.0 for ; Mon, 03 Jun 2024 01:56:09 -0700 (PDT) X-Forwarded-Encrypted: i=1; AJvYcCWhlNm9vyEsdozCtNe4QuCEc5l+47K3Aj3F8S39iXCFYKUMG2K23/wwfJWUOHavXdFlQyg5zwTR6f5u4Bd4z/B7g8L1FBnnncfB X-Received: by 2002:a17:902:f90f:b0:1f6:1dd3:a4cb with SMTP id d9443c01a7336-1f636ffe0f8mr79602565ad.17.1717404968992; Mon, 03 Jun 2024 01:56:08 -0700 (PDT) X-Received: by 2002:a17:902:f90f:b0:1f6:1dd3:a4cb with SMTP id d9443c01a7336-1f636ffe0f8mr79602465ad.17.1717404968609; Mon, 03 Jun 2024 01:56:08 -0700 (PDT) Received: from pc-0182.atmarktech (117.209.187.35.bc.googleusercontent.com. [35.187.209.117]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f632338c14sm60327255ad.36.2024.06.03.01.56.07 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Jun 2024 01:56:08 -0700 (PDT) Received: from [::1] (helo=pc-0182.atmark.tech) by pc-0182.atmarktech with esmtp (Exim 4.96) (envelope-from ) id 1sE3U6-009riT-0G; Mon, 03 Jun 2024 17:56:06 +0900 From: Dominique Martinet To: stefano.babic@swupdate.org, swupdate@googlegroups.com Cc: Dominique Martinet Subject: [swupdate] [PATCH RFC 1/9] parser: set_find_path: properly return to-free string array Date: Mon, 3 Jun 2024 17:55:54 +0900 Message-Id: <20240603085602.2351411-2-dominique.martinet@atmark-techno.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240603085602.2351411-1-dominique.martinet@atmark-techno.com> References: <20240603085602.2351411-1-dominique.martinet@atmark-techno.com> MIME-Version: 1.0 X-Original-Sender: dominique.martinet@atmark-techno.com X-Original-Authentication-Results: gmr-mx.google.com; dkim=pass header.i=@atmark-techno.com header.s=gw2_bookworm header.b=x2beX1Gu; dkim=pass header.i=@atmark-techno.com header.s=google header.b=In1PilU7; spf=pass (google.com: domain of dominique.martinet@atmark-techno.com designates 35.74.137.57 as permitted sender) smtp.mailfrom=dominique.martinet@atmark-techno.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=atmark-techno.com Precedence: list Mailing-list: list swupdate@googlegroups.com; contact swupdate+owners@googlegroups.com List-ID: X-Spam-Checked-In-Group: swupdate@googlegroups.com X-Google-Group-Id: 605343134186 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , properly set 'tmp' through an extra indirection instead of leaking the string array Reported-by: gcc -fanalyzer Signed-off-by: Dominique Martinet --- core/parsing_library.c | 5 ++--- corelib/parsing_library_libconfig.c | 2 +- corelib/parsing_library_libjson.c | 2 +- include/parselib.h | 2 +- parser/parser.c | 2 +- 5 files changed, 6 insertions(+), 7 deletions(-) diff --git a/core/parsing_library.c b/core/parsing_library.c index a97f8114becc..038c6851adf9 100644 --- a/core/parsing_library.c +++ b/core/parsing_library.c @@ -210,7 +210,7 @@ void get_hash_value(parsertype p, void *elem, unsigned char *hash) ascii_to_hash(hash, hash_ascii); } -bool set_find_path(const char **nodes, const char *newpath, char **tmp) +bool set_find_path(const char **nodes, const char *newpath, char ***tmp) { char **paths; unsigned int count; @@ -218,7 +218,6 @@ bool set_find_path(const char **nodes, const char *newpath, char **tmp) char *token, *ref; bool first = true; int allocstr = 0; - (void)tmp; /* * Include of files is not supported, @@ -301,7 +300,7 @@ bool set_find_path(const char **nodes, const char *newpath, char **tmp) } free(ref); - tmp = paths; + *tmp = paths; return true; } diff --git a/corelib/parsing_library_libconfig.c b/corelib/parsing_library_libconfig.c index ddb79f6fb152..4ddc338031a0 100644 --- a/corelib/parsing_library_libconfig.c +++ b/corelib/parsing_library_libconfig.c @@ -196,7 +196,7 @@ void *find_root_libconfig(config_t *cfg, const char **nodes, unsigned int depth) if (elem && config_setting_is_group(elem) == CONFIG_TRUE) { ref = get_field_string_libconfig(elem, "ref"); if (ref) { - if (!set_find_path(nodes, ref, tmp)) { + if (!set_find_path(nodes, ref, &tmp)) { free(root); return NULL; } diff --git a/corelib/parsing_library_libjson.c b/corelib/parsing_library_libjson.c index 4728d200fc8e..9456d51eca9d 100644 --- a/corelib/parsing_library_libjson.c +++ b/corelib/parsing_library_libjson.c @@ -237,7 +237,7 @@ void *find_root_json(json_object *root, const char **nodes, unsigned int depth) if (type == json_type_object || type == json_type_array) { str = get_field_string_json(node, "ref"); if (str) { - if (!set_find_path(nodes, str, tmp)) + if (!set_find_path(nodes, str, &tmp)) return NULL; node = find_root_json(root, nodes, depth); free_string_array(tmp); diff --git a/include/parselib.h b/include/parselib.h index 99b6519fa480..48f38d2a8c92 100644 --- a/include/parselib.h +++ b/include/parselib.h @@ -64,7 +64,7 @@ void get_hash_value(parsertype p, void *elem, unsigned char *hash); void check_field_string(const char *src, char *dst, const size_t max_len); void *find_root(parsertype p, void *root, const char **nodes); void *get_node(parsertype p, void *root, const char **nodes); -bool set_find_path(const char **nodes, const char *newpath, char **tmp); +bool set_find_path(const char **nodes, const char *newpath, char ***tmp); #define GET_FIELD_STRING(p, e, name, d) \ get_field_string_with_size(p, e, name, d, sizeof(d)) diff --git a/parser/parser.c b/parser/parser.c index 04d7b72c9b9a..2273796e0452 100644 --- a/parser/parser.c +++ b/parser/parser.c @@ -144,7 +144,7 @@ static int parser_follow_link(parsertype p, void *cfg, void *elem, for (int j = 0; j < count_string_array(nodes); j++) { linknodes[j] = nodes[j]; } - if (!set_find_path(linknodes, ref, tmp)) { + if (!set_find_path(linknodes, ref, &tmp)) { free(linknodes); return -1; }