diff options
author | Mark Wielaard <mark@klomp.org> | 2022-08-28 17:46:08 +0200 |
---|---|---|
committer | Mark Wielaard <mark@klomp.org> | 2022-09-14 20:48:29 +0200 |
commit | 6cb01b4ef3cdd4f83d21bbcec72fa66712ac14e6 (patch) | |
tree | 5e37ea849e6d667903ff56623f5bc4ea0b8925b5 /src/ar.c | |
parent | ee188125b10d1588a0536af033d7b7b1bbbaafaf (diff) | |
download | elfutils-6cb01b4ef3cdd4f83d21bbcec72fa66712ac14e6.tar.gz |
ar: Correct -N COUNT off-by-one
When using instance [COUNT], the instance check is wrong.
instance-- == 0 should be --instance == 0.
Add a testcase run-ar-N.sh that uses -N COUNT with extract and delete
operations checking the right instance was extracted and deleted.
https://sourceware.org/bugzilla/show_bug.cgi?id=28725
Reported-by: panxiaohe <panxh_ran@163.com>
Signed-off-by: Mark Wielaard <mark@klomp.org>
Diffstat (limited to 'src/ar.c')
-rw-r--r-- | src/ar.c | 4 |
1 files changed, 2 insertions, 2 deletions
@@ -518,7 +518,7 @@ do_oper_extract (int oper, const char *arfname, char **argv, int argc, ENTRY entry; entry.key = arhdr->ar_name; ENTRY *res = hsearch (entry, FIND); - if (res != NULL && (instance < 0 || instance-- == 0) + if (res != NULL && (instance < 0 || --instance == 0) && !found[(char **) res->data - argv]) found[(char **) res->data - argv] = do_extract = true; } @@ -952,7 +952,7 @@ do_oper_delete (const char *arfname, char **argv, int argc, ENTRY entry; entry.key = arhdr->ar_name; ENTRY *res = hsearch (entry, FIND); - if (res != NULL && (instance < 0 || instance-- == 0) + if (res != NULL && (instance < 0 || --instance == 0) && !found[(char **) res->data - argv]) found[(char **) res->data - argv] = do_delete = true; } |