From 6bb6a1a10fdf01c618be5bde0beeb65a1c90f866 Mon Sep 17 00:00:00 2001 From: Nikos Mavrogiannopoulos Date: Fri, 8 Jul 2016 08:29:40 +0200 Subject: encode and decode object identifiers with elements larger than 2^32 in 32-bit systems --- lib/coding.c | 4 ++-- lib/decoding.c | 2 +- lib/int.h | 6 ++++++ lib/parser_aux.c | 4 ++-- lib/parser_aux.h | 2 +- 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/coding.c b/lib/coding.c index 66531b0..7141df7 100644 --- a/lib/coding.c +++ b/lib/coding.c @@ -337,7 +337,7 @@ _asn1_objectid_der (unsigned char *str, unsigned char *der, int *der_len) int len_len, counter, k, first, max_len; char *temp, *n_end, *n_start; unsigned char bit7; - unsigned long val, val1 = 0; + uint64_t val, val1 = 0; int str_len = _asn1_strlen (str); max_len = *der_len; @@ -355,7 +355,7 @@ _asn1_objectid_der (unsigned char *str, unsigned char *der, int *der_len) while ((n_end = strchr (n_start, '.'))) { *n_end = 0; - val = strtoul (n_start, NULL, 10); + val = _asn1_strtou64 (n_start, NULL, 10); counter++; if (counter == 1) diff --git a/lib/decoding.c b/lib/decoding.c index cfe2322..31c3708 100644 --- a/lib/decoding.c +++ b/lib/decoding.c @@ -395,7 +395,7 @@ asn1_get_object_id_der (const unsigned char *der, int der_len, int *ret_len, int len_len, len, k; int leading; char temp[LTOSTR_MAX_SIZE]; - unsigned long val, val1; + uint64_t val, val1; *ret_len = 0; if (str && str_size > 0) diff --git a/lib/int.h b/lib/int.h index f1f1302..7d2eea3 100644 --- a/lib/int.h +++ b/lib/int.h @@ -118,6 +118,12 @@ extern const tag_and_class_st _asn1_tags[]; #define _asn1_strcpy(a,b) strcpy((char *)a, (const char *)b) #define _asn1_strcat(a,b) strcat((char *)a, (const char *)b) +#if SIZEOF_UNSIGNED_LONG_INT == 8 +# define _asn1_strtou64(n,e,b) strtoul((const char *) n, e, b) +#else +# define _asn1_strtou64(n,e,b) strtoull((const char *) n, e, b) +#endif + #define MAX_LOG_SIZE 1024 /* maximum number of characters of a log message */ /* Define used for visiting trees. */ diff --git a/lib/parser_aux.c b/lib/parser_aux.c index 52700c6..2285b20 100644 --- a/lib/parser_aux.c +++ b/lib/parser_aux.c @@ -549,9 +549,9 @@ _asn1_delete_list_and_nodes (void) char * -_asn1_ltostr (long v, char str[LTOSTR_MAX_SIZE]) +_asn1_ltostr (int64_t v, char str[LTOSTR_MAX_SIZE]) { - long d, r; + int64_t d, r; char temp[LTOSTR_MAX_SIZE]; int count, k, start; diff --git a/lib/parser_aux.h b/lib/parser_aux.h index 10b864b..9f91833 100644 --- a/lib/parser_aux.h +++ b/lib/parser_aux.h @@ -54,7 +54,7 @@ void _asn1_delete_list_and_nodes (void); /* Max 64-bit integer length is 20 chars + 1 for sign + 1 for null termination */ #define LTOSTR_MAX_SIZE 22 -char *_asn1_ltostr (long v, char str[LTOSTR_MAX_SIZE]); +char *_asn1_ltostr (int64_t v, char str[LTOSTR_MAX_SIZE]); asn1_node _asn1_find_up (asn1_node node); -- cgit v1.2.1