[PATCH] opt.list_packets
NIIBE Yutaka
gniibe at fsij.org
Tue Jun 28 02:41:53 CEST 2016
Hello,
Since this is a quite long-standing bug (exists even < 1.0), I'm
writing to this list.
In the function do_proc_packets (g10/mainproc.c), it says:
/* Stop processing when an invalid packet has been encountered
* but don't do so when we are doing a --list-packets. */
However, it stops always, because opt.list_packets is never 2 when
running this function.
We have a function, set_packet_list_mode which sets the variable
list_mode, and we have opt.list_packets which is set by command
line option.
It seemed that once it was tried to integrate list_mode and
opt.list_packets, with the value of 2 for opt.list_packets, but it had
never been worked as expected.
Before the fix of mine, it goes like that:
(1) opt.list_packets is assigned to 2
(2) set_packet_list_mode is called
When opt.list_packets == 2, stdout is selected as output
(3) opt.list_packets is assigend to 1
(4) do_proc_packets is called with opt.list_packets==1
I do think the assignment to the variable like opt.list_packets should
be one time, yes, once and all.
I don't usually introduce semantics change of variable or function
when I fix something, but this is a fix for a bug with wrong
semantics. Please accept this exception.
Here are the changes.
* --list-packets enables keeping running after invalid packet
* opt.list_packets is set to 1 with --list-packets
* With --list-packets, set_packet_list_mode is called after
the assignment of opt.list_packets
I'm going to apply this change to 1.4, 2.0, and 2.1.
==================================
diff --git a/g10/gpg.c b/g10/gpg.c
index ef27562..9750c57 100644
--- a/g10/gpg.c
+++ b/g10/gpg.c
@@ -4656,7 +4656,6 @@ main (int argc, char **argv)
break;
case aListPackets:
- opt.list_packets=2;
default:
if( argc > 1 )
wrong_args(_("[filename]"));
@@ -4685,8 +4684,8 @@ main (int argc, char **argv)
}
}
if( cmd == aListPackets ) {
- set_packet_list_mode(1);
opt.list_packets=1;
+ set_packet_list_mode(1);
}
rc = proc_packets (ctrl, NULL, a );
if( rc )
diff --git a/g10/mainproc.c b/g10/mainproc.c
index bd738ab..c191fe0 100644
--- a/g10/mainproc.c
+++ b/g10/mainproc.c
@@ -1328,7 +1328,7 @@ do_proc_packets (ctrl_t ctrl, CTX c, iobuf_t a)
/* Stop processing when an invalid packet has been encountered
* but don't do so when we are doing a --list-packets. */
if (gpg_err_code (rc) == GPG_ERR_INV_PACKET
- && opt.list_packets != 2 )
+ && opt.list_packets == 0)
break;
continue;
}
diff --git a/g10/options.h b/g10/options.h
index 4279bd6..fc333cd 100644
--- a/g10/options.h
+++ b/g10/options.h
@@ -80,7 +80,7 @@ struct
int print_pka_records;
int print_dane_records;
int no_armor;
- int list_packets; /* list-packets mode: 1=normal, 2=invoked by command*/
+ int list_packets; /* Option --list-packets active. */
int def_cipher_algo;
int force_mdc;
int disable_mdc;
diff --git a/g10/parse-packet.c b/g10/parse-packet.c
index 1c1b389..ec8a641 100644
--- a/g10/parse-packet.c
+++ b/g10/parse-packet.c
@@ -211,7 +211,7 @@ set_packet_list_mode (int mode)
enable the list mode only with a special option. */
if (!listfp)
{
- if (opt.list_packets == 2)
+ if (opt.list_packets)
{
listfp = es_stdout;
if (opt.verbose)
--
More information about the Gnupg-devel
mailing list