Changeset View
Changeset View
Standalone View
Standalone View
g10/parse-packet.c
Show First 20 Lines • Show All 723 Lines • ▼ Show 20 Lines | for (i = 0; i < 4; i ++) | ||||
rc = gpg_error (GPG_ERR_INV_PACKET); | rc = gpg_error (GPG_ERR_INV_PACKET); | ||||
goto leave; | goto leave; | ||||
} | } | ||||
value[i] = hdr[hdrlen++] = c; | value[i] = hdr[hdrlen++] = c; | ||||
} | } | ||||
pktlen = buf32_to_ulong (value); | pktlen = buf32_to_ulong (value); | ||||
} | } | ||||
else if (ctx->sigs_only || onlykeypkts) | |||||
{ | |||||
log_error ("%s: partial length found for packet type %d" | |||||
" when reading signature, certificate, or key", | |||||
iobuf_where(inp), pkttype); | |||||
rc = gpg_error (GPG_ERR_UNEXPECTED); | |||||
goto leave; | |||||
} | |||||
else /* Partial body length. */ | else /* Partial body length. */ | ||||
{ | { | ||||
switch (pkttype) | switch (pkttype) | ||||
{ | { | ||||
case PKT_PLAINTEXT: | case PKT_PLAINTEXT: | ||||
case PKT_ENCRYPTED: | case PKT_ENCRYPTED: | ||||
case PKT_ENCRYPTED_MDC: | case PKT_ENCRYPTED_MDC: | ||||
case PKT_ENCRYPTED_AEAD: | case PKT_ENCRYPTED_AEAD: | ||||
Show All 30 Lines | tag. */ | ||||
if (pkttype != PKT_ENCRYPTED && pkttype != PKT_PLAINTEXT | if (pkttype != PKT_ENCRYPTED && pkttype != PKT_PLAINTEXT | ||||
&& pkttype != PKT_COMPRESSED) | && pkttype != PKT_COMPRESSED) | ||||
{ | { | ||||
log_error ("%s: indeterminate length for invalid" | log_error ("%s: indeterminate length for invalid" | ||||
" packet type %d\n", iobuf_where (inp), pkttype); | " packet type %d\n", iobuf_where (inp), pkttype); | ||||
rc = gpg_error (GPG_ERR_INV_PACKET); | rc = gpg_error (GPG_ERR_INV_PACKET); | ||||
goto leave; | goto leave; | ||||
} | } | ||||
else if (ctx->sigs_only || onlykeypkts) | |||||
{ | |||||
log_error ("%s: indeterminate length when reading" | |||||
" key or signature\n", | |||||
iobuf_where (inp)); | |||||
rc = gpg_error (GPG_ERR_UNEXPECTED); | |||||
goto leave; | |||||
} | |||||
} | } | ||||
else | else | ||||
{ | { | ||||
for (; lenbytes; lenbytes--) | for (; lenbytes; lenbytes--) | ||||
{ | { | ||||
pktlen <<= 8; | pktlen <<= 8; | ||||
c = iobuf_get (inp); | c = iobuf_get (inp); | ||||
if (c == -1) | if (c == -1) | ||||
Show All 37 Lines | again: | ||||
} | } | ||||
rc = iobuf_write (out, hdr, hdrlen); | rc = iobuf_write (out, hdr, hdrlen); | ||||
if (!rc) | if (!rc) | ||||
rc = copy_packet (inp, out, pkttype, pktlen, partial); | rc = copy_packet (inp, out, pkttype, pktlen, partial); | ||||
goto leave; | goto leave; | ||||
} | } | ||||
if (with_uid && pkttype == PKT_USER_ID) | if (pkttype == PKT_PADDING || | ||||
(pkttype >= PKT_FIRST_NON_CRITICAL && | |||||
pkttype != PKT_COMMENT && pkttype != PKT_GPG_CONTROL)) | |||||
goto again; /* Skip this packet */ | |||||
else if (ctx->sigs_only && pkttype != PKT_SIGNATURE | |||||
&& pkttype != PKT_PADDING && pkttype != PKT_MARKER) | |||||
{ | |||||
iobuf_skip_rest (inp, pktlen, partial); | |||||
*skip = 1; | |||||
rc = GPG_ERR_UNEXPECTED; | |||||
goto leave; | |||||
} | |||||
else if (with_uid && pkttype == PKT_USER_ID) | |||||
/* If ONLYKEYPKTS is set to 2, then we never skip user id packets, | /* If ONLYKEYPKTS is set to 2, then we never skip user id packets, | ||||
even if DO_SKIP is set. */ | even if DO_SKIP is set. */ | ||||
; | ; | ||||
else if (do_skip | else if (do_skip | ||||
/* type==0 is not allowed. This is an invalid packet. */ | /* type==0 is not allowed. This is an invalid packet. */ | ||||
|| !pkttype | || !pkttype | ||||
/* When ONLYKEYPKTS is set, we don't skip keys. */ | /* When ONLYKEYPKTS is set, we don't skip keys. */ | ||||
|| (onlykeypkts && pkttype != PKT_PUBLIC_SUBKEY | || (onlykeypkts && pkttype != PKT_PUBLIC_SUBKEY | ||||
▲ Show 20 Lines • Show All 2,925 Lines • Show Last 20 Lines |