From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1kVxPq-0001SD-Hp for mharc-grub-devel@gnu.org; Fri, 23 Oct 2020 09:47:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60264) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kVxPo-0001Qd-SZ for grub-devel@gnu.org; Fri, 23 Oct 2020 09:47:32 -0400 Received: from dibed.net-space.pl ([84.10.22.86]:49729) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_3DES_EDE_CBC_SHA1:192) (Exim 4.90_1) (envelope-from ) id 1kVxPn-0004hB-3t for grub-devel@gnu.org; Fri, 23 Oct 2020 09:47:32 -0400 Received: from router-fw.i.net-space.pl ([192.168.52.1]:40440 "EHLO tomti.i.net-space.pl") by router-fw-old.i.net-space.pl with ESMTP id S1955438AbgJWMIX (ORCPT ); Fri, 23 Oct 2020 14:08:23 +0200 X-Comment: RFC 2476 MSA function at dibed.net-space.pl logged sender identity as: dkiper Date: Fri, 23 Oct 2020 14:08:18 +0200 From: Daniel Kiper To: Glenn Washburn Cc: grub-devel@gnu.org, Patrick Steinhardt Subject: Re: [PATCH v3 01/10] luks2: Fix use of incorrect index and some grub_error() messages. Message-ID: <20201023120818.iqss6nawibucw63x@tomti.i.net-space.pl> References: <20201009100122.GH2088@tanuki> <80dd653c989818e86f219cbfc83be9115c06ccd2.1603148099.git.development@efficientek.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <80dd653c989818e86f219cbfc83be9115c06ccd2.1603148099.git.development@efficientek.com> User-Agent: NeoMutt/20170113 (1.7.2) Received-SPF: pass client-ip=84.10.22.86; envelope-from=dkiper@net-space.pl; helo=dibed.net-space.pl X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/23 09:47:25 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 23 Oct 2020 13:47:33 -0000 On Mon, Oct 19, 2020 at 06:09:49PM -0500, Glenn Washburn wrote: > When looping over the digests and segments, the loop variable is j, but the > variable i is used to index in the the digests and segments json array. The > variable i is the keyslot index. Similarly, there are several grub_error() > statements using the wrong index in constructing the error string. > > Signed-off-by: Glenn Washburn > --- > grub-core/disk/luks2.c | 14 +++++++------- > 1 file changed, 7 insertions(+), 7 deletions(-) > > diff --git a/grub-core/disk/luks2.c b/grub-core/disk/luks2.c > index 31d7166fc..2241e0312 100644 > --- a/grub-core/disk/luks2.c > +++ b/grub-core/disk/luks2.c > @@ -275,34 +275,34 @@ luks2_get_keyslot (grub_luks2_keyslot_t *k, grub_luks2_digest_t *d, grub_luks2_s > return grub_error (GRUB_ERR_BAD_ARGUMENT, "Could not get digests"); > for (j = 0; j < size; j++) > { > - if (grub_json_getchild (&digest, &digests, i) || > + if (grub_json_getchild (&digest, &digests, j) || > grub_json_getchild (&digest, &digest, 0) || > luks2_parse_digest (d, &digest)) > - return grub_error (GRUB_ERR_BAD_ARGUMENT, "Could not parse digest %"PRIuGRUB_SIZE, i); > + return grub_error (GRUB_ERR_BAD_ARGUMENT, "Could not parse digest %"PRIuGRUB_SIZE, j); > > if ((d->keyslots & (1 << idx))) > break; > } > if (j == size) > - return grub_error (GRUB_ERR_FILE_NOT_FOUND, "No digest for keyslot %"PRIuGRUB_SIZE); > + return grub_error (GRUB_ERR_FILE_NOT_FOUND, "No digest for keyslot %"PRIuGRUB_SIZE, i); > > /* Get segment that matches the digest. */ > if (grub_json_getvalue (&segments, root, "segments") || > grub_json_getsize (&size, &segments)) > return grub_error (GRUB_ERR_BAD_ARGUMENT, "Could not get segments"); > - for (j = 0; j < size; j++) > + for (i = j, j = 0; j < size; j++) Should not it be "i = j = 0" instead of "i = j, j = 0"? > { > - if (grub_json_getchild (&segment, &segments, i) || > + if (grub_json_getchild (&segment, &segments, j) || > grub_json_getuint64 (&idx, &segment, NULL) || > grub_json_getchild (&segment, &segment, 0) || > luks2_parse_segment (s, &segment)) > - return grub_error (GRUB_ERR_BAD_ARGUMENT, "Could not parse segment %"PRIuGRUB_SIZE, i); > + return grub_error (GRUB_ERR_BAD_ARGUMENT, "Could not parse segment %"PRIuGRUB_SIZE, j); > > if ((d->segments & (1 << idx))) > break; > } > if (j == size) > - return grub_error (GRUB_ERR_FILE_NOT_FOUND, "No segment for digest %"PRIuGRUB_SIZE); > + return grub_error (GRUB_ERR_FILE_NOT_FOUND, "No segment for digest %"PRIuGRUB_SIZE, i); s/PRIuGRUB_SIZE, i/PRIuGRUB_SIZE, j/? Daniel