aboutsummaryrefslogtreecommitdiffstats
path: root/g10/parse-packet.c
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2017-03-29 09:57:40 +0000
committerWerner Koch <[email protected]>2017-03-29 10:08:31 +0000
commitafa86809087909a8ba2f9356588bf90cc923529c (patch)
treeff0941a7831c23a47f9dafa522b375b7cc00daa4 /g10/parse-packet.c
parentindent: Re-indent function free-packet. (diff)
downloadgnupg-afa86809087909a8ba2f9356588bf90cc923529c.tar.gz
gnupg-afa86809087909a8ba2f9356588bf90cc923529c.zip
gpg: Extend free_packet to handle a packet parser context.
* g10/packet.h (struct parse_packet_ctx_s): Add fields LAST_PKT and FREE_LAST_PKT. (init_parse_packet): Clear them. (deinit_parse_packet): New macro. Change all users if init_parse_packet to also call this macro. * g10/free-packet.c (free_packet): Add arg PARSECTX and handle shallow packet copies in the context. Change all callers. * g10/parse-packet.c (parse): Store certain packets in the parse context. -- Signed-off-by: Werner Koch <[email protected]>
Diffstat (limited to 'g10/parse-packet.c')
-rw-r--r--g10/parse-packet.c38
1 files changed, 36 insertions, 2 deletions
diff --git a/g10/parse-packet.c b/g10/parse-packet.c
index 7766a45f6..ab273a5fa 100644
--- a/g10/parse-packet.c
+++ b/g10/parse-packet.c
@@ -352,6 +352,9 @@ dbg_copy_all_packets (iobuf_t inp, iobuf_t out, const char *dbg_f, int dbg_l)
(rc =
parse (&parsectx, &pkt, 0, NULL, &skip, out, 0, "copy",
dbg_f, dbg_l)));
+
+ deinit_parse_packet (&parsectx);
+
return rc;
}
#else /*!DEBUG_PARSE_PACKET*/
@@ -372,6 +375,9 @@ copy_all_packets (iobuf_t inp, iobuf_t out)
init_packet (&pkt);
}
while (!(rc = parse (&parsectx, &pkt, 0, NULL, &skip, out, 0)));
+
+ deinit_parse_packet (&parsectx);
+
return rc;
}
#endif /*!DEBUG_PARSE_PACKET*/
@@ -397,11 +403,17 @@ dbg_copy_some_packets (iobuf_t inp, iobuf_t out, off_t stopoff,
do
{
if (iobuf_tell (inp) >= stopoff)
- return 0;
+ {
+ deinit_parse_packet (&parsectx);
+ return 0;
+ }
init_packet (&pkt);
}
while (!(rc = parse (&parsectx, &pkt, 0, NULL, &skip, out, 0,
"some", dbg_f, dbg_l)));
+
+ deinit_parse_packet (&parsectx);
+
return rc;
}
#else /*!DEBUG_PARSE_PACKET*/
@@ -418,10 +430,16 @@ copy_some_packets (iobuf_t inp, iobuf_t out, off_t stopoff)
do
{
if (iobuf_tell (inp) >= stopoff)
- return 0;
+ {
+ deinit_parse_packet (&parsectx);
+ return 0;
+ }
init_packet (&pkt);
}
while (!(rc = parse (&parsectx, &pkt, 0, NULL, &skip, out, 0)));
+
+ deinit_parse_packet (&parsectx);
+
return rc;
}
#endif /*!DEBUG_PARSE_PACKET*/
@@ -447,6 +465,9 @@ dbg_skip_some_packets (iobuf_t inp, unsigned n, const char *dbg_f, int dbg_l)
rc = parse (&parsectx, &pkt, 0, NULL, &skip, NULL, 1, "skip",
dbg_f, dbg_l);
}
+
+ deinit_parse_packet (&parsectx);
+
return rc;
}
#else /*!DEBUG_PARSE_PACKET*/
@@ -465,6 +486,9 @@ skip_some_packets (iobuf_t inp, unsigned int n)
init_packet (&pkt);
rc = parse (&parsectx, &pkt, 0, NULL, &skip, NULL, 1);
}
+
+ deinit_parse_packet (&parsectx);
+
return rc;
}
#endif /*!DEBUG_PARSE_PACKET*/
@@ -804,6 +828,16 @@ parse (parse_packet_ctx_t ctx, PACKET *pkt, int onlykeypkts, off_t * retpos,
break;
}
+ /* Store a shallow copy of certain packets in the context. */
+ if (!rc && (pkttype == PKT_PUBLIC_KEY
+ || pkttype == PKT_SECRET_KEY
+ || pkttype == PKT_USER_ID
+ || pkttype == PKT_ATTRIBUTE
+ || pkttype == PKT_SIGNATURE))
+ ctx->last_pkt = pkt;
+ else
+ ctx->last_pkt = NULL;
+
leave:
/* FIXME: We leak in case of an error (see the xmalloc's above). */
if (!rc && iobuf_error (inp))