*
* This file is part of GnuPG.
*
- * GnuPG is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
+ * This file is free software; you can redistribute it and/or modify
+ * it under the terms of either
*
- * GnuPG is distributed in the hope that it will be useful,
+ * - the GNU Lesser General Public License as published by the Free
+ * Software Foundation; either version 3 of the License, or (at
+ * your option) any later version.
+ *
+ * or
+ *
+ * - the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at
+ * your option) any later version.
+ *
+ * or both in parallel, as here.
+ *
+ * This file is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* 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 <gpg-error.h>
#endif
+#include "util.h"
#include "tlv.h"
static const unsigned char *
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
and the length part from the TLV triplet. Update BUFFER and SIZE
on success. */
gpg_error_t
-_parse_ber_header (unsigned char const **buffer, size_t *size,
- int *r_class, int *r_tag,
- int *r_constructed, int *r_ndef,
- size_t *r_length, size_t *r_nhdr,
- gpg_err_source_t errsource)
+parse_ber_header (unsigned char const **buffer, size_t *size,
+ int *r_class, int *r_tag,
+ int *r_constructed, int *r_ndef,
+ size_t *r_length, size_t *r_nhdr)
{
int c;
unsigned long tag;
/* Get the tag. */
if (!length)
- return gpg_err_make (errsource, GPG_ERR_EOF);
+ return gpg_err_make (default_errsource, GPG_ERR_EOF);
c = *buf++; length--; ++*r_nhdr;
*r_class = (c & 0xc0) >> 6;
{
tag <<= 7;
if (!length)
- return gpg_err_make (errsource, GPG_ERR_EOF);
+ return gpg_err_make (default_errsource, GPG_ERR_EOF);
c = *buf++; length--; ++*r_nhdr;
tag |= c & 0x7f;
/* Get the length. */
if (!length)
- return gpg_err_make (errsource, GPG_ERR_EOF);
+ return gpg_err_make (default_errsource, GPG_ERR_EOF);
c = *buf++; length--; ++*r_nhdr;
if ( !(c & 0x80) )
else if (c == 0x80)
*r_ndef = 1;
else if (c == 0xff)
- return gpg_err_make (errsource, GPG_ERR_BAD_BER);
+ return gpg_err_make (default_errsource, GPG_ERR_BAD_BER);
else
{
unsigned long len = 0;
- int count = c & 0x7f;
+ int count = (c & 0x7f);
- if (count > sizeof (len) || count > sizeof (size_t))
- return gpg_err_make (errsource, GPG_ERR_BAD_BER);
+ 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--)
{
len <<= 8;
if (!length)
- return gpg_err_make (errsource, GPG_ERR_EOF);
+ return gpg_err_make (default_errsource, GPG_ERR_EOF);
c = *buf++; length--; ++*r_nhdr;
len |= c & 0xff;
}
handle_error ();
*/
gpg_error_t
-_parse_sexp (unsigned char const **buf, size_t *buflen,
- int *depth, unsigned char const **tok, size_t *toklen,
- gpg_err_source_t errsource)
+parse_sexp (unsigned char const **buf, size_t *buflen,
+ int *depth, unsigned char const **tok, size_t *toklen)
{
const unsigned char *s;
size_t n, vlen;
*tok = NULL;
*toklen = 0;
if (!n)
- return *depth ? gpg_err_make (errsource, GPG_ERR_INV_SEXP) : 0;
+ return *depth ? gpg_err_make (default_errsource, GPG_ERR_INV_SEXP) : 0;
if (*s == '(')
{
s++; n--;
if (*s == ')')
{
if (!*depth)
- return gpg_err_make (errsource, GPG_ERR_INV_SEXP);
+ return gpg_err_make (default_errsource, GPG_ERR_INV_SEXP);
*toklen = 1;
s++; n--;
(*depth)--;
for (vlen=0; n && *s && *s != ':' && (*s >= '0' && *s <= '9'); s++, n--)
vlen = vlen*10 + (*s - '0');
if (!n || *s != ':')
- return gpg_err_make (errsource, GPG_ERR_INV_SEXP);
+ return gpg_err_make (default_errsource, GPG_ERR_INV_SEXP);
s++; n--;
if (vlen > n)
- return gpg_err_make (errsource, GPG_ERR_INV_SEXP);
+ return gpg_err_make (default_errsource, GPG_ERR_INV_SEXP);
*tok = s;
*toklen = vlen;
s += vlen;