From 8d831f143cb258aee89d94984835d52c06554973 Mon Sep 17 00:00:00 2001 From: claudio Date: Tue, 31 Jul 2018 11:01:29 +0000 Subject: [PATCH] Make ber type and encoding a unsigned int instead of unsigned long. This way the size is the same on all archs and 32bit should be good enough. OK rob@ --- usr.sbin/snmpd/ber.3 | 10 +++++----- usr.sbin/snmpd/ber.c | 32 ++++++++++++++++---------------- usr.sbin/snmpd/ber.h | 16 ++++++++-------- usr.sbin/snmpd/smi.c | 4 ++-- usr.sbin/snmpd/snmpd.h | 4 ++-- usr.sbin/snmpd/snmpe.c | 4 ++-- 6 files changed, 35 insertions(+), 35 deletions(-) diff --git a/usr.sbin/snmpd/ber.3 b/usr.sbin/snmpd/ber.3 index e2173bc6030..8de49f06e28 100644 --- a/usr.sbin/snmpd/ber.3 +++ b/usr.sbin/snmpd/ber.3 @@ -1,4 +1,4 @@ -.\" $OpenBSD: ber.3,v 1.16 2018/06/29 20:28:11 jmc Exp $ +.\" $OpenBSD: ber.3,v 1.17 2018/07/31 11:01:29 claudio Exp $ .\" .\" Copyright (c) 2007, 2012 Reyk Floeter .\" @@ -14,7 +14,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: June 29 2018 $ +.Dd $Mdocdate: July 31 2018 $ .Dt BER 3 .Os .Sh NAME @@ -65,9 +65,9 @@ .Sh SYNOPSIS .Fd #include .Ft "struct ber_element *" -.Fn "ber_get_element" "unsigned long encoding" +.Fn "ber_get_element" "unsigned int encoding" .Ft "void" -.Fn "ber_set_header" "struct ber_element *elm" "int class" "unsigned long type" +.Fn "ber_set_header" "struct ber_element *elm" "int class" "unsigned int type" .Ft "void" .Fn "ber_link_elements" "struct ber_element *prev" "struct ber_element *elm" .Ft "struct ber_element *" @@ -145,7 +145,7 @@ .Ft "size_t" .Fn "ber_calc_len" "struct ber_element *root" .Ft "void" -.Fn "ber_set_application" "struct ber *ber" "unsigned long (*cb)(struct ber_element *)" +.Fn "ber_set_application" "struct ber *ber" "unsigned int (*cb)(struct ber_element *)" .Ft "void" .Fn "ber_set_writecallback" "struct ber_element *elm" "void (*cb)(void *arg, size_t offs)" "void *arg" .Ft "void" diff --git a/usr.sbin/snmpd/ber.c b/usr.sbin/snmpd/ber.c index 1eb78b024c6..1cedb4d5bf7 100644 --- a/usr.sbin/snmpd/ber.c +++ b/usr.sbin/snmpd/ber.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ber.c,v 1.43 2018/07/13 08:50:38 rob Exp $ */ +/* $OpenBSD: ber.c,v 1.44 2018/07/31 11:01:29 claudio Exp $ */ /* * Copyright (c) 2007, 2012 Reyk Floeter @@ -42,7 +42,7 @@ static int ber_dump_element(struct ber *ber, struct ber_element *root); static void ber_dump_header(struct ber *ber, struct ber_element *root); static void ber_putc(struct ber *ber, u_char c); static void ber_write(struct ber *ber, void *buf, size_t len); -static ssize_t get_id(struct ber *b, unsigned long *tag, int *class, +static ssize_t get_id(struct ber *b, unsigned int *tag, int *class, int *cstruct); static ssize_t get_len(struct ber *b, ssize_t *len); static ssize_t ber_read_element(struct ber *ber, struct ber_element *elm); @@ -56,7 +56,7 @@ static ssize_t ber_read(struct ber *ber, void *buf, size_t len); #endif struct ber_element * -ber_get_element(unsigned long encoding) +ber_get_element(unsigned int encoding) { struct ber_element *elm; @@ -70,7 +70,7 @@ ber_get_element(unsigned long encoding) } void -ber_set_header(struct ber_element *elm, int class, unsigned long type) +ber_set_header(struct ber_element *elm, int class, unsigned int type) { elm->be_class = class & BER_CLASS_MASK; if (type == BER_TYPE_DEFAULT) @@ -521,7 +521,7 @@ ber_printf_elements(struct ber_element *ber, char *fmt, ...) va_list ap; int d, class; size_t len; - unsigned long type; + unsigned int type; long long i; char *s; void *p; @@ -578,7 +578,7 @@ ber_printf_elements(struct ber_element *ber, char *fmt, ...) break; case 't': class = va_arg(ap, int); - type = va_arg(ap, unsigned long); + type = va_arg(ap, unsigned int); ber_set_header(ber, class, type); break; case 'x': @@ -626,7 +626,7 @@ ber_scanf_elements(struct ber_element *ber, char *fmt, ...) #define _MAX_SEQ 128 va_list ap; int *d, level = -1; - unsigned long *t; + unsigned int *t; long long *i, l; void **ptr; size_t *len, ret = 0, n = strlen(fmt); @@ -694,7 +694,7 @@ ber_scanf_elements(struct ber_element *ber, char *fmt, ...) break; case 't': d = va_arg(ap, int *); - t = va_arg(ap, unsigned long *); + t = va_arg(ap, unsigned int *); *d = ber->be_class; *t = ber->be_type; ret++; @@ -867,7 +867,7 @@ ber_free_elements(struct ber_element *root) size_t ber_calc_len(struct ber_element *root) { - unsigned long t; + unsigned int t; size_t s; size_t size = 2; /* minimum 1 byte head and 1 byte size */ @@ -945,8 +945,8 @@ ber_dump_element(struct ber *ber, struct ber_element *root) static void ber_dump_header(struct ber *ber, struct ber_element *root) { - u_char id = 0, t, buf[8]; - unsigned long type; + u_char id = 0, t, buf[5]; + unsigned int type; size_t size; /* class universal, type encoding depending on type value */ @@ -1010,11 +1010,11 @@ ber_write(struct ber *ber, void *buf, size_t len) * extract a BER encoded tag. There are two types, a short and long form. */ static ssize_t -get_id(struct ber *b, unsigned long *tag, int *class, int *cstruct) +get_id(struct ber *b, unsigned int *tag, int *class, int *cstruct) { u_char u; size_t i = 0; - unsigned long t = 0; + unsigned int t = 0; if (ber_getc(b, &u) == -1) return -1; @@ -1032,7 +1032,7 @@ get_id(struct ber *b, unsigned long *tag, int *class, int *cstruct) return -1; t = (t << 7) | (u & ~BER_TAG_MORE); i++; - if (i > sizeof(unsigned long)) { + if (i > sizeof(unsigned int)) { errno = ERANGE; return -1; } @@ -1093,7 +1093,7 @@ ber_read_element(struct ber *ber, struct ber_element *elm) { long long val = 0; struct ber_element *next; - unsigned long type; + unsigned int type; int i, class, cstruct; ssize_t len, r, totlen = 0; u_char c; @@ -1221,7 +1221,7 @@ ber_get_writebuf(struct ber *b, void **buf) } void -ber_set_application(struct ber *b, unsigned long (*cb)(struct ber_element *)) +ber_set_application(struct ber *b, unsigned int (*cb)(struct ber_element *)) { b->br_application = cb; } diff --git a/usr.sbin/snmpd/ber.h b/usr.sbin/snmpd/ber.h index 4a8f194f4a7..e8865849a30 100644 --- a/usr.sbin/snmpd/ber.h +++ b/usr.sbin/snmpd/ber.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ber.h,v 1.11 2018/06/29 19:28:02 rob Exp $ */ +/* $OpenBSD: ber.h,v 1.12 2018/07/31 11:01:29 claudio Exp $ */ /* * Copyright (c) 2007, 2012 Reyk Floeter @@ -22,8 +22,8 @@ struct ber_element { struct ber_element *be_next; - unsigned long be_type; - unsigned long be_encoding; + unsigned int be_type; + unsigned int be_encoding; size_t be_len; off_t be_offs; int be_free; @@ -49,11 +49,11 @@ struct ber { u_char *br_rptr; u_char *br_rend; - unsigned long (*br_application)(struct ber_element *); + unsigned int (*br_application)(struct ber_element *); }; /* well-known ber_element types */ -#define BER_TYPE_DEFAULT ((unsigned long)-1) +#define BER_TYPE_DEFAULT ((unsigned int)-1) #define BER_TYPE_EOC 0 #define BER_TYPE_BOOLEAN 1 #define BER_TYPE_INTEGER 2 @@ -84,9 +84,9 @@ struct ber_oid { }; __BEGIN_DECLS -struct ber_element *ber_get_element(unsigned long); +struct ber_element *ber_get_element(unsigned int); void ber_set_header(struct ber_element *, int, - unsigned long); + unsigned int); void ber_link_elements(struct ber_element *, struct ber_element *); struct ber_element *ber_unlink_elements(struct ber_element *); @@ -131,7 +131,7 @@ void ber_free_element(struct ber_element *); void ber_free_elements(struct ber_element *); size_t ber_calc_len(struct ber_element *); void ber_set_application(struct ber *, - unsigned long (*)(struct ber_element *)); + unsigned int (*)(struct ber_element *)); void ber_set_writecallback(struct ber_element *, void (*)(void *, size_t), void *); void ber_free(struct ber *); diff --git a/usr.sbin/snmpd/smi.c b/usr.sbin/snmpd/smi.c index 0e951d0ef5e..676e8ff2fb5 100644 --- a/usr.sbin/snmpd/smi.c +++ b/usr.sbin/snmpd/smi.c @@ -1,4 +1,4 @@ -/* $OpenBSD: smi.c,v 1.21 2018/07/23 19:51:39 rob Exp $ */ +/* $OpenBSD: smi.c,v 1.22 2018/07/31 11:01:29 claudio Exp $ */ /* * Copyright (c) 2007, 2008 Reyk Floeter @@ -537,7 +537,7 @@ smi_print_element(struct ber_element *root) return (NULL); } -unsigned long +unsigned int smi_application(struct ber_element *elm) { if (elm->be_class != BER_CLASS_APPLICATION) diff --git a/usr.sbin/snmpd/snmpd.h b/usr.sbin/snmpd/snmpd.h index 6d93ac66144..945da0bdc42 100644 --- a/usr.sbin/snmpd/snmpd.h +++ b/usr.sbin/snmpd/snmpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: snmpd.h,v 1.78 2018/04/15 11:57:29 mpf Exp $ */ +/* $OpenBSD: snmpd.h,v 1.79 2018/07/31 11:01:29 claudio Exp $ */ /* * Copyright (c) 2007, 2008, 2012 Reyk Floeter @@ -736,7 +736,7 @@ void smi_delete(struct oid *); int smi_insert(struct oid *); int smi_oid_cmp(struct oid *, struct oid *); int smi_key_cmp(struct oid *, struct oid *); -unsigned long smi_application(struct ber_element *); +unsigned int smi_application(struct ber_element *); void smi_debug_elements(struct ber_element *); char *smi_print_element(struct ber_element *); diff --git a/usr.sbin/snmpd/snmpe.c b/usr.sbin/snmpd/snmpe.c index b1e4f60c60e..97503f46a12 100644 --- a/usr.sbin/snmpd/snmpe.c +++ b/usr.sbin/snmpd/snmpe.c @@ -1,4 +1,4 @@ -/* $OpenBSD: snmpe.c,v 1.53 2018/07/24 01:31:20 rob Exp $ */ +/* $OpenBSD: snmpe.c,v 1.54 2018/07/31 11:01:29 claudio Exp $ */ /* * Copyright (c) 2007, 2008, 2012 Reyk Floeter @@ -222,7 +222,7 @@ snmpe_parse(struct snmp_message *msg) struct ber_element *a; long long ver, req; long long errval, erridx; - unsigned long type; + unsigned int type; u_int class; char *comn; char *flagstr, *ctxname; -- 2.20.1