[Rpm-maint] [rpm-software-management/rpm] rpm-4.14.0/tools/debugedit.c:2144]: (style) Array index 'lndx' is used before limits check. (#332)

Mark Wielaard mark at klomp.org
Fri Oct 13 21:28:50 UTC 2017


On Fri, Oct 13, 2017 at 07:30:01AM +0000, dcb314 wrote:
> Source code is
> 
>                       while (r_offset > (dso->lines.table[lndx].old_idx
>                                          + 4
>                                          + dso->lines.table[lndx].unit_length)
>                              && lndx < dso->lines.used)
>                         lndx++;
> 
> Suggest limit check array index before use, not after.

Yes, nice catch. The conditions should be swapped.
Patch attached.

Cheers,

Mark
-------------- next part --------------
>From 3be44f93ab963169b1b1f4f24c7adffb2029f0df Mon Sep 17 00:00:00 2001
From: Mark Wielaard <mark at klomp.org>
Date: Fri, 13 Oct 2017 23:27:32 +0200
Subject: [PATCH] debugedit: edit_dwarf2 check lndx is in range before checking
 r_offset.

---
 tools/debugedit.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/tools/debugedit.c b/tools/debugedit.c
index a271b916e..fa47aa5e2 100644
--- a/tools/debugedit.c
+++ b/tools/debugedit.c
@@ -2141,10 +2141,10 @@ edit_dwarf2 (DSO *dso)
 			  r_offset = rel.r_offset;
 			}
 
-		      while (r_offset > (dso->lines.table[lndx].old_idx
-					 + 4
-					 + dso->lines.table[lndx].unit_length)
-			     && lndx < dso->lines.used)
+		      while (lndx < dso->lines.used
+			     && r_offset > (dso->lines.table[lndx].old_idx
+					    + 4
+					    + dso->lines.table[lndx].unit_length))
 			lndx++;
 
 		      if (lndx >= dso->lines.used)
-- 
2.13.6



More information about the Rpm-maint mailing list