There is a bit of strange code in the ip parser of rpki-client to parse
the AFI. This is a 2byte network byte order value. Instead of using a a
char buf and a short just do everything with a one uint16_t. The current
code does *(uint16_t)buf which is not save since buf is a char array.
Lucky us that the stack ends up enough aligned that this code does not
blow up on strict align archs. Still fix is simple and makes the code much
cleaner.

-- 
:wq Claudio

Index: ip.c
===================================================================
RCS file: /cvs/src/usr.sbin/rpki-client/ip.c,v
retrieving revision 1.9
diff -u -p -r1.9 ip.c
--- ip.c        27 Nov 2019 17:18:24 -0000      1.9
+++ ip.c        16 Apr 2020 09:48:02 -0000
@@ -41,8 +41,7 @@
 int
 ip_addr_afi_parse(const char *fn, const ASN1_OCTET_STRING *p, enum afi *afi)
 {
-       char     buf[2];
-       short    v;
+       uint16_t v;
 
        if (p->length == 0 || p->length > 3) {
                warnx("%s: invalid field length, want 1--3, have %d",
@@ -50,8 +49,8 @@ ip_addr_afi_parse(const char *fn, const 
                return 0;
        }
 
-       memcpy(buf, p->data, sizeof(uint16_t));
-       v = ntohs(*(uint16_t *)buf);
+       memcpy(&v, p->data, sizeof(v));
+       v = ntohs(v);
 
        /* Only accept IPv4 and IPv6 AFIs. */
 

Reply via email to