From patchwork Mon Oct 9 15:28:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefano Babic X-Patchwork-Id: 1845312 X-Patchwork-Delegate: sbabic@denx.de 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=EqWK20HX; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:4864:20::13d; helo=mail-lf1-x13d.google.com; envelope-from=swupdate+bncbaabbknyscuqmgqe4yk7ntq@googlegroups.com; receiver=patchwork.ozlabs.org) Received: from mail-lf1-x13d.google.com (mail-lf1-x13d.google.com [IPv6:2a00:1450:4864:20::13d]) (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 4S42xV2vCqz1yq1 for ; Tue, 10 Oct 2023 02:28:46 +1100 (AEDT) Received: by mail-lf1-x13d.google.com with SMTP id 2adb3069b0e04-5043307ec0bsf4059330e87.2 for ; Mon, 09 Oct 2023 08:28:45 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1696865322; cv=pass; d=google.com; s=arc-20160816; b=uldHFZrexNMwH5jzEtnjSW9Q+2rxat9zwPimCr3mx4nNsJ/KY2sf/Z6HBQ8Ut61ELZ 5Bzi/V9eUZ9maInSYKFIP5wv8cpSa9vFRkEFKTfKEVP4O2mWOF2x91kX4+NIdpitKRuB KEwWgc8wUn1pcmYsQpOGsvGQxYzroLDH8ZVLkuRVAmZ0NpOLsp91nA1Fsq7H4iJ5v+BO ykY5AaOSgmpsXNtII4cgJ+y7v7aqlsJYR35sWTK3KbXwfleZ6Bq7nbcCpHy+xsx+Meu1 No9MdZZDByETjIz/eKy0CMZJP9hb0Mv/GFofXWb99sW+FFSptXwkwL+ywqSXDZq22jIx vBnA== 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:ui-outboundreport :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:dkim-signature; bh=LyLODBYUHxitEKRDyzkGNHsHFILBv1W1EtP25VH8eeI=; fh=xyVQkp0/GQNgAb1PNWWO8gt7zijvopO38DEdoUKgFOk=; b=FH9rTPfyge9p1f2BGh2p5OFcoP8e4eW1Oq5VZstEPf15bnhBsRZwmfgpohvDc8ziI1 37YpmeuzLsOzMs3svuPLhRFpk9eSYcAgdrgJcFcHG/W/qXbzRDp4nj+d36CpXOGAg42J kaS+4LB1JOf9my3mnn69cvpFEFMFhvjbUVYpG/uOEYPa1KhLvhaL/IM+v2iI6SDBKCpW mI0Hxi7KiM6yh5gqiakty5XvJ+51ne1B6xvAcZDtm9HpdDLl84Rrg58fXWJMSYAoT5ju j42PcfVTZwVhv5xSW/ynpUM6RSg6K3T4J/tLXbFjFV4rcBE/UhR8pM64H1eWIIH+hYhl hLhw== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=pass (google.com: domain of stefano.babic@swupdate.org designates 212.227.17.24 as permitted sender) smtp.mailfrom=stefano.babic@swupdate.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20230601; t=1696865322; x=1697470122; 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:ui-outboundreport:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:sender:from:to:cc:subject:date:message-id:reply-to; bh=LyLODBYUHxitEKRDyzkGNHsHFILBv1W1EtP25VH8eeI=; b=EqWK20HXtA4JpQ5GH6XejpzRTR7uYm3/bZJFECKPyR/wH+lqWzvsYTX2NkqzthqOzg vD7kerzfhQ/WnVCW4wvgT1Zcxf++ZNMKYomrvW8vJopX9FCRhtzrMZ5rD9fxdphEWN8X LUIMzfYxWhicR7nD0oX6EXzd0pC5iDDGBeDR2iNw9TqP4OvW7LXYzomvSVyFIopYZuRt QDeGduauZPzu30r2k8dvlhcxImpyYzwqYTLfv/5CwE7t20FPI6HtRhl4L83mGXtHutzU tp7CmZp6EeHnsFOJ3roUq1pfe8RFhkv27I2gdY9ESyxMh1qJlU6+0b75exSLvs/rzZog 4bEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696865322; x=1697470122; 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 :ui-outboundreport:content-transfer-encoding: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=LyLODBYUHxitEKRDyzkGNHsHFILBv1W1EtP25VH8eeI=; b=kyPcAGNt7rSaJ1i/dhgSQ/fz1QyupFadwrHj9U/iHilwoxG7V0wn5LTFwSnCnai89H mXletyNkzQVmr/VaHxBovvGs6dX4PrvnRJ7SpMdBxdmvQPPle6aU90J4ViIYldFZLva4 qlJHw3zaD8+VbLMlDAKl6bQmmr7ajAedR3COZuau06+nzHH3eh15MFkFcIWZFJkMwe6N fuoH026in7Yy6osHrv4krY06sy0NOzeUae4hGZFWLV8t6oUpwQ8kW8g8Q0KTVxhLaA95 rk478ntupGgeNe8er8VAR9eh5ygX948ofhuoorsBJ3/16EX2NF052ItpfRZlzm4ih5ZR Hw7w== Sender: swupdate@googlegroups.com X-Gm-Message-State: AOJu0YyT/NstmAu4D/706GMCgZhyCoo7Fsrxmkmv6m+mrF9mu1aE4V1t 7CpY0i6iVJhRJCh7x4o1I6Q= X-Google-Smtp-Source: AGHT+IFIGQ451igVB5QipbGuu1UviWxrr4HuPhDKSiKPYKCoL7idyVogu/1Ebj7dElL6Y6ENrN7gXw== X-Received: by 2002:a05:6512:238f:b0:500:a002:292a with SMTP id c15-20020a056512238f00b00500a002292amr18593980lfv.29.1696865321736; Mon, 09 Oct 2023 08:28:41 -0700 (PDT) X-BeenThere: swupdate@googlegroups.com Received: by 2002:a05:6512:3c95:b0:506:85c4:49d3 with SMTP id h21-20020a0565123c9500b0050685c449d3ls1508433lfv.1.-pod-prod-09-eu; Mon, 09 Oct 2023 08:28:40 -0700 (PDT) X-Received: by 2002:ac2:5e69:0:b0:505:6fcd:dc32 with SMTP id a9-20020ac25e69000000b005056fcddc32mr11436767lfr.28.1696865320095; Mon, 09 Oct 2023 08:28:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696865320; cv=none; d=google.com; s=arc-20160816; b=RenJlrRSjYlb2TLtT+6dHJwr94y8eGIEC9ZbLS+7qLMWDoznC0V8H11h1CEUWpxYaa qb94kbm8+jE4hsTQeTUq6Ce9E5iThXpCcEo3bpJgWG+XtM2Wrq3/kO1EKzVrYvTaXaiu rnNcy/xz1C6S3Ls7cWH3eRTj2Fb2FxnICcNTH1V7boUQmBAFPAdZmZAuv5fN4oOlZTVA /9mNVRLeRO0JbFDpWowjC6LmCaP23Klcm87cCbf5MklSFZvlmNmSyn6D3br43msCHLb8 nSAuhQ5FDz1P4jtbEk0ImUduM4uSbppcjWbAV2N8jirJRyGXMmAUsg/ZHxpg7sYe54lA j0LQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=ui-outboundreport:content-transfer-encoding:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from; bh=sV3smAynKpjYnMWZQwra/RzFXLQkjeV7oXXbBPK9Hzg=; fh=xyVQkp0/GQNgAb1PNWWO8gt7zijvopO38DEdoUKgFOk=; b=bYDGBguJXvPfUQlsP58CV1eEQGZr4+E8fi7VBlFYQ94ojqrf0uZ/9ByMQvCTeBjZC9 RgNbPEsB8tUYu0GXyoQjato/u8QjYqtisPU4HyHmbJc3mo5V1BPf+qurZoILLjbbl/vW mc3y8b2QuSJzjlGV2E1gZTS6yt/1MdZtuD5g+TzPSFUuvD22/xM5gdsEJB3XyZCR0lNi Jzu7kn+BNjxqulzvNAP2d6UxnCgTwtxFvsqtE6ABYOZZMCurCjZiskrAZm29p/1krYFJ L0iO/iOZ7Qi4Cs6dUgWb2Nf+YVMZBMC133tt3pIs/zVWdqxoVDMZUyVGRWo9FrQ3POfu 4z0Q== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of stefano.babic@swupdate.org designates 212.227.17.24 as permitted sender) smtp.mailfrom=stefano.babic@swupdate.org Received: from mout.kundenserver.de (mout.kundenserver.de. [212.227.17.24]) by gmr-mx.google.com with ESMTPS id m7-20020a056512114700b005008765a16fsi367764lfg.13.2023.10.09.08.28.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 08:28:40 -0700 (PDT) Received-SPF: pass (google.com: domain of stefano.babic@swupdate.org designates 212.227.17.24 as permitted sender) client-ip=212.227.17.24; Received: from paperino.fritz.box ([88.217.136.221]) by mrelayeu.kundenserver.de (mreue109 [213.165.67.113]) with ESMTPSA (Nemesis) id 1N0G5h-1rkz0z2gPn-00xJST; Mon, 09 Oct 2023 17:28:38 +0200 From: Stefano Babic To: swupdate@googlegroups.com Cc: Stefano Babic , =?utf-8?q?Einar_J=C3=B3n?= Subject: [swupdate] [PATCH 2/2] BUG: JSON parser can't handle a string "offset" Date: Mon, 9 Oct 2023 17:28:36 +0200 Message-Id: <20231009152836.416267-2-stefano.babic@swupdate.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231009152836.416267-1-stefano.babic@swupdate.org> References: <20231009152836.416267-1-stefano.babic@swupdate.org> MIME-Version: 1.0 X-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Fhw+wk/5NOIGyBvBfPNnMlKnub3yvoXFM3F fY4D2QYFR8N2IUzLb7btdKp9Rq+5xKK7dJ/An0GQtnrzuD/sxDrYkEvhOLZTWZRi7WXKcQaxo 3fbfUKu2Xa4/kTV33uXUUVrYuFLjZ5eoXzpw= X-Original-Sender: stefano.babic@swupdate.org X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of stefano.babic@swupdate.org designates 212.227.17.24 as permitted sender) smtp.mailfrom=stefano.babic@swupdate.org 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: , get_field(p, elem, "offset", &offset) in case of JSON does not return 0 if field is a string, causing a wrong offset to be evaluated. This bug does not happen if libconfig is the parser. Call is_field_numeric() in advance to check if offset is set as number or string. Signed-off-by: Stefano Babic Reported-by: Einar Jón --- include/parselib.h | 2 ++ parser/parser.c | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/include/parselib.h b/include/parselib.h index 387ddc67..a027d53a 100644 --- a/include/parselib.h +++ b/include/parselib.h @@ -54,6 +54,7 @@ void *get_node_libconfig(config_t *cfg, const char **nodes); #define get_field_cfg(e, path, dest) #define find_root_libconfig(cfg, nodes, depth) (NULL) #define get_node_libconfig(cfg, nodes) (NULL) +#define is_field_numeric_cfg(e, path) (false) #endif #ifdef CONFIG_JSON @@ -85,6 +86,7 @@ void *get_node_json(json_object *root, const char **nodes); #define json_object_array_length(a) (0) #define find_root_json(root, nodes, depth) (NULL) #define get_node_json(root, nodes) (NULL) +#define is_field_numeric_json(e, path) (false) #endif bool is_field_numeric(parsertype p, void *e, const char *path); diff --git a/parser/parser.c b/parser/parser.c index 4c0a8f2f..52661384 100644 --- a/parser/parser.c +++ b/parser/parser.c @@ -398,8 +398,6 @@ static int parse_common_attributes(parsertype p, void *elem, struct img_type *im GET_FIELD_STRING(p, elem, "mtdname", image->mtdname); GET_FIELD_STRING(p, elem, "filesystem", image->filesystem); GET_FIELD_STRING(p, elem, "type", image->type); - get_field(p, elem, "offset", &offset); - GET_FIELD_STRING(p, elem, "offset", seek_str); GET_FIELD_STRING(p, elem, "data", image->type_data); get_hash_value(p, elem, image->sha256); @@ -407,9 +405,11 @@ static int parse_common_attributes(parsertype p, void *elem, struct img_type *im * offset can be set as number or string. As string, * multiplier suffixes are allowed */ - if (offset) + if (is_field_numeric(p, elem, "offset")) { + get_field(p, elem, "offset", &offset); image->seek = offset; - else { + } else { + GET_FIELD_STRING(p, elem, "offset", seek_str); /* convert the offset handling multiplicative suffixes */ image->seek = ustrtoull(seek_str, NULL, 0); if (errno){