diff options
| author | Werner Koch <[email protected]> | 2005-05-20 20:37:08 +0000 |
|---|---|---|
| committer | Werner Koch <[email protected]> | 2005-05-20 20:37:08 +0000 |
| commit | bd644c8d45ff2903625edb8b41bffcb6a8a69b85 (patch) | |
| tree | d9a7fedf142c24fb6b48f719d70a90bb3b192cd4 /g10/tlv.c | |
| parent | * gpg.sgml: Document --default-sig-expire and --default-cert-expire, (diff) | |
| download | gnupg-bd644c8d45ff2903625edb8b41bffcb6a8a69b85.tar.gz gnupg-bd644c8d45ff2903625edb8b41bffcb6a8a69b85.zip | |
(ccid_transceive): Arghhh. The seqno is another
bit in the R-block than in the I block, this was wrong at one
place. Fixes bug #419 and hopefully several others.
Diffstat (limited to 'g10/tlv.c')
| -rw-r--r-- | g10/tlv.c | 28 |
1 files changed, 21 insertions, 7 deletions
@@ -1,5 +1,5 @@ /* tlv.c - Tag-Length-Value Utilities - * Copyright (C) 2003, 2004 Free Software Foundation, Inc. + * Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -25,9 +25,8 @@ #include <string.h> #include <assert.h> -#include "errors.h" -#include "util.h" -#include "packet.h" +#include <gpg-error.h> + #include "tlv.h" static const unsigned char * @@ -114,17 +113,32 @@ do_find_tlv (const unsigned char *buffer, size_t length, /* Locate a TLV encoded data object in BUFFER of LENGTH and return a pointer to value as well as its length in NBYTES. Return - NULL if it was not found. Note, that the function does not check - whether the value fits into the provided buffer. */ + NULL if it was not found or if the object does not fit into the buffer. */ const unsigned char * find_tlv (const unsigned char *buffer, size_t length, int tag, size_t *nbytes) { - return do_find_tlv (buffer, length, tag, nbytes, 0); + const unsigned char *p; + + p = do_find_tlv (buffer, length, tag, nbytes, 0); + if (p && *nbytes > (length - (p-buffer))) + p = NULL; /* Object longer than buffer. */ + return p; } +/* Locate a TLV encoded data object in BUFFER of LENGTH and + return a pointer to value as well as its length in NBYTES. Return + NULL if it was not found. Note, that the function does not check + whether the value fits into the provided buffer. */ +const unsigned char * +find_tlv_unchecked (const unsigned char *buffer, size_t length, + int tag, size_t *nbytes) +{ + return do_find_tlv (buffer, length, tag, nbytes, 0); +} + /* ASN.1 BER parser: Parse BUFFER of length SIZE and return the tag and the length part from the TLV triplet. Update BUFFER and SIZE |
