From patchwork Mon Jun 17 07:29:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dominique Martinet X-Patchwork-Id: 1948523 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=t3Sjq7V+; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=googlegroups.com (client-ip=2607:f8b0:4864:20::33f; helo=mail-ot1-x33f.google.com; envelope-from=swupdate+bncbcwivbv7sugrbtolx6zqmgqejmmi5ty@googlegroups.com; receiver=patchwork.ozlabs.org) Received: from mail-ot1-x33f.google.com (mail-ot1-x33f.google.com [IPv6:2607:f8b0:4864:20::33f]) (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 4W2hNM5Hnmz23tx for ; Mon, 17 Jun 2024 17:29:36 +1000 (AEST) Received: by mail-ot1-x33f.google.com with SMTP id 46e09a7af769-6f9866bd6d6sf4969611a34.1 for ; Mon, 17 Jun 2024 00:29:36 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718609358; cv=pass; d=google.com; s=arc-20160816; b=TuL/DBfI3FOq573Lt9HhPjlW8LQUMuz5JQ8/3toUbt48SjyDJvvfSlV9w/eJ3SJTvP ClWhE/UcnYOHaM4o9T4lhHhhWMseyGzzR7+v9zfsjYljARVdR2+aXztPZR3LsdeKcE4q OXSIv9DzGkDf+N/m6P93+RIaS6ZwbILbs+MOogl6RDq3eQN2aecU/MQo63qevh1UY6R/ BjEoDN6Ee5QXa402qSWLt1JkPwwXFHmYJbvl6i/KBvO2r1lzgJcQJpBfTLt2e4M4NNWj nBK6LQBJW2MRZ7abXww1TbWLm5iPalHY3czRhOW/5y1HN5sgm//KOflqXJcbOZU+CcGc BVUw== 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=Dkk2oBOMwWJM51MS8H601huS8A0MEJ8YI8m5plvazG4=; fh=mhzrxU8dmc8DxbNUWyCvCWwKJxWW14+qnJUJSqtI54g=; b=wDF/xyQ53SQLPJUjAret+xQd1/wi4bt3UqCGcCwH1HI6dItLTAJ92pxXHpj7zMh5+u 0o3vdNEWLxX5WV3eWn1OFgoIYKdHai2uZ1x4RijCfmRgHLGInJSw9cy1v9e6j4vtsHT+ mb82JtvT79XmkuTSIYN2INkMxNOZpiFLq2vhf8yIwav9fOw93sfwCmrkw/Jn8X2xs3rU d7t5lzy9S+tZr/erOl+y7RAvzmdqR/l8tNRyy1AtHWToBCvKsYnfCUpVv43cij/d23+m nWQZ5qkt6WOuAsEK/kfqhaOZ1ujGXSSNuup14aj2OZQ/uO0Ipy7NZnJT5j+6WsjmvNo+ wqbw==; 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=RHnyk56G; dkim=pass header.i=@atmark-techno.com header.s=google header.b=Z135yh0Q; 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=1718609358; x=1719214158; 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=Dkk2oBOMwWJM51MS8H601huS8A0MEJ8YI8m5plvazG4=; b=t3Sjq7V+ks0TfwrZT13uhPv14KfpmCT90yPhlz9ai5nUrzzYy9m3L1Q3DnZdFQNY3j ahneRiewyEeh812HrFoSQTmmtiTN697f88bUtsbFUn2EK80wd8MYUdHYhT/wZTPqsScQ 9jmi51TtZ3TtZ3KdMSCeHm9eh51y4f5XLYZw3VRYdwTTfqoqvqfFdaswixubZmfKaKtx 6Kq6bwiqFC0zUmsKYNFVtgAUVh6zyspGNNQ8tVPPRftPlb/nzt9+pgp3+Qc1lIpfv0GR yo6gAfTyTztfgbEEXGhtpY88sj8Fe8yEy/Z05543yt3uDV9RY2dmVrEuhjZKc+V07QQv mH2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718609358; x=1719214158; 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=Dkk2oBOMwWJM51MS8H601huS8A0MEJ8YI8m5plvazG4=; b=uf+F8PyqhRL+yUdcrT1oafb5rrttxlzuQ9qZ/qt1U3ItyZ5i8itMIIBFL1fUUKFSVx wlhvgLOzNh9KpZaxx61Qh23okUiXDywBdOP5xyTVwpKXlOzWlBAHdK9QaumczNB1lYM0 tuIyN4KxEkH48mPx0sscg/4QRjCpmYiT8J2HLgNmoyuR6ipKxIniO+nqUeymUyac59Y0 5qRgidWgpbu2KZEpzktiAVK4jzqXpEwBf7pwPGPyoAfbBnSxRP/uGDUKJM3UEaLJ7Pen +euzrvXK13gIyJGSxLu+iPiNoSeEeF0M/hh4Col82ml9sb3su0Q5UW/0gXfb9LWX7+tC SyPA== Sender: swupdate@googlegroups.com X-Forwarded-Encrypted: i=2; AJvYcCWlPLdagrV/DTo0gpiTn8mQPNDIKAeDOp58QPJC4yE+JVSu2CdyNTlhq+WjsLL8pErqy49Hd5mIUx7FmSUXfimF4HsRRhIZhoUtXbCx6A== X-Gm-Message-State: AOJu0YzlrVf5cZPL6+R5m8Tzr0uCWBWHY8mG9ftfJaYSIg9hcyvBNTiA UGyl+Rbr+Q//QP9ir/GFprou+aMA88OpuToo4ex2XVVnYffafCVd X-Google-Smtp-Source: AGHT+IF6nlCoHonkyUlqS8gjVzTpyVPzIVeXGvQ1LG8WeWhP81lXBmZgncbb6ZIi47Svh/xETCDMCw== X-Received: by 2002:a05:6870:3906:b0:254:b2e8:163d with SMTP id 586e51a60fabf-258428b4e11mr10677283fac.19.1718609358279; Mon, 17 Jun 2024 00:29:18 -0700 (PDT) X-BeenThere: swupdate@googlegroups.com Received: by 2002:a05:6870:718f:b0:254:6df2:beae with SMTP id 586e51a60fabf-2552b6aac4cls4137227fac.0.-pod-prod-04-us; Mon, 17 Jun 2024 00:29:17 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVAHQkJnLsmH/b0rwts5ck4sDfBU848IB7X61bGtoe07ZD+22WucuWjs2K8zjpj+GslM0IHKqJ/9zoYi3mBu/mUeorWddGFV4E1 X-Received: by 2002:a05:6870:5387:b0:254:d1d6:2ff with SMTP id 586e51a60fabf-258429a3affmr10429001fac.34.1718609356758; Mon, 17 Jun 2024 00:29:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1718609356; cv=none; d=google.com; s=arc-20160816; b=pSvkIf7Otd9NFXT9V6S1YJf4bjl7g1Lxs5eREzqnCUq+vsj523bwtoeocTpJFuwMJ2 xPlwyICCUui//PzmWbxkxJuk2amKqLco8jNGvV3zHd6dBM87llicLDqz4T3ZiJGXr+S5 M85IY3sMb3mYYFiupiJQD7HsvEx5ob/r6X7zm0nnD0yWVZPLRBmd3vW1rPhxS3FW3U9h FcdNbR/YUCBU+WEMidsWmjdtrPxUW/vwDq4eqKDLVGg33Jv+I4gEcvVcjI2W7wwWtkyB 6nJsKLMzOMdwDYqQcYBRvMh6LPjB21pVT4ZiuwMnrIeN7vuDCnEn+z45sJCw0U/xDHwg 0t3Q== 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=ILSOYzF5xatB7BPgosENgTurR+BSOxxoFiBnY+Qf/vY=; b=zMfKlMDWAX+xOffUr4Bvd0E153FKz17tRHTwfw1Yqj4L+sKfukUooO4buAVxpFMafP OvGg88lz3QXxwKwBgPJpcAfkdEl/s7eJuDNq2ZLETt8BuIPHmTB+Fcke9OupNEhttVZ9 MIKrgaxTLcqMXnKuYWtJSuAACBJWbnUL+g9jLc66a3UsOA2j+k0A64xEa5dbrUWAiw4c sAYBqcVbEoumg6vhgSW5/cAwZBl3MDlEgTgInAHzpQNdNobgYX/MxBMqCTLp5chf1wTn xn2fvfJFQ52aB9iYKLerjUokuOxo6C/Xh/RmDUiLjv4flMagdX8Pibj5H8eq7mzKnYFZ JhTw==; 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=RHnyk56G; dkim=pass header.i=@atmark-techno.com header.s=google header.b=Z135yh0Q; 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 586e51a60fabf-25699377358si407669fac.4.2024.06.17.00.29.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Jun 2024 00:29:16 -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 712C4A6B for ; Mon, 17 Jun 2024 16:29:14 +0900 (JST) Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) by gw2.atmark-techno.com (Postfix) with ESMTPS id A71C5A77 for ; Mon, 17 Jun 2024 16:29:13 +0900 (JST) Received: by mail-pg1-f198.google.com with SMTP id 41be03b00d2f7-649731dd35bso3480447a12.0 for ; Mon, 17 Jun 2024 00:29:13 -0700 (PDT) X-Forwarded-Encrypted: i=1; AJvYcCXgetodJppceoUXIebF1wvSsY5W4q8iyqWhI4hRz2A4V5QREhLyJOkEy5DKt9FTskDEYVqFPL9i3xgFQj3XCy/okl92KBV+QTLT X-Received: by 2002:a05:6a21:191:b0:1b5:2fbb:2d78 with SMTP id adf61e73a8af0-1bae83c6280mr9178430637.48.1718609352663; Mon, 17 Jun 2024 00:29:12 -0700 (PDT) X-Received: by 2002:a05:6a21:191:b0:1b5:2fbb:2d78 with SMTP id adf61e73a8af0-1bae83c6280mr9178403637.48.1718609351813; Mon, 17 Jun 2024 00:29:11 -0700 (PDT) Received: from pc-0182.atmarktech (162.198.187.35.bc.googleusercontent.com. [35.187.198.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f855ee6eacsm74246965ad.179.2024.06.17.00.29.10 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Jun 2024 00:29:10 -0700 (PDT) Received: from [::1] (helo=pc-0182.atmark.tech) by pc-0182.atmarktech with esmtp (Exim 4.96) (envelope-from ) id 1sJ6nd-009Y52-1I; Mon, 17 Jun 2024 16:29:09 +0900 From: Dominique Martinet To: stefano.babic@swupdate.org, swupdate@googlegroups.com Cc: Dominique Martinet Subject: [swupdate] [PATCH 1/4] parser: set_find_path: properly return to-free string array Date: Mon, 17 Jun 2024 16:29:02 +0900 Message-Id: <20240617072905.2275940-2-dominique.martinet@atmark-techno.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240617072905.2275940-1-dominique.martinet@atmark-techno.com> References: <20240617072905.2275940-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=RHnyk56G; dkim=pass header.i=@atmark-techno.com header.s=google header.b=Z135yh0Q; 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 Reviewed-by: Stefano Babic --- 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; }