* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ * along with this program; if not, see <https://www.gnu.org/licenses/>.
*/
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <assert.h>
-
-#if GNUPG_MAJOR_VERSION == 1
-#define GPG_ERR_EOF (-1)
-#define GPG_ERR_BAD_BER (1) /*G10ERR_GENERAL*/
-#define GPG_ERR_INV_SEXP (45) /*G10ERR_INV_ARG*/
-typedef int gpg_error_t;
-#define gpg_make_err(x,n) (n)
-#else
#include <gpg-error.h>
-#endif
+
#include "util.h"
#include "tlv.h"
+
static const unsigned char *
do_find_tlv (const unsigned char *buffer, size_t length,
int tag, size_t *nbytes, int nestlevel)
for (;;)
{
- buffer = s;
if (n < 2)
return NULL; /* Buffer definitely too short for tag and length. */
if (!*s || *s == 0xff)
{ /* Two byte length follows. */
if (n < 2)
return NULL; /* We expected 2 more bytes with the length. */
- len = (s[0] << 8) | s[1];
+ len = ((size_t)s[0] << 8) | s[1];
s += 2; n -= 2;
}
else
else
{
unsigned long len = 0;
- int count = c & 0x7f;
+ int count = (c & 0x7f);
- if (count > sizeof (len) || count > sizeof (size_t))
+ if (count > (sizeof(len)<sizeof(size_t)?sizeof(len):sizeof(size_t)))
return gpg_err_make (default_errsource, GPG_ERR_BAD_BER);
for (; count; count--)
returned as a pointer into the original buffer at TOK and TOKLEN.
If a parentheses is the next token, TOK will be set to NULL.
TOKLEN is checked to be within the bounds. On error an error code
- is returned and no pointer is not guaranteed to point to
- a meaningful value. DEPTH should be initialized to 0 and will
+ is returned and pointers are not guaranteed to point to
+ meaningful values. DEPTH should be initialized to 0 and will
reflect on return the actual depth of the tree. To detect the end
of the S-expression it is advisable to check DEPTH after a
successful return.