gpg: Fix DoS while parsing mangled secret key packets.
* g10/parse-packet.c (parse_key): Check PKTLEN before calling mpi_read et al.
Due to the missing length checks PKTLEN may turn negative. Because
PKTLEN is an unsigned int the malloc in read_rest would try to malloc
a too large number and terminate the process with "error reading rest
of packet: Cannot allocate memory".
(backported from 2.0 commit 0aac920f23fd07e152fdb7385299c92bb9a4ade3)
- Reported-by: Hanno Böck.
- Signed-off-by: Werner Koch <wk@gnupg.org>