On Thu, Oct 25, 2018 at 10:57:58AM +0200, Claudio Jeker wrote:
> Currently struct aspath is defined with a placeholder for the dynamic data
> part.
> struct aspath {
> LIST_ENTRY(aspath) entry;
> int refcnt; /* reference count */
> u_int16_t len; /* total length of aspath in octets */
> u_int16_t ascnt; /* number of AS hops in data */
> u_char data[1]; /* placeholder for actual data */
> };
>
> The size of the struct - this placeholder was calculated as
> ASPATH_HEADER_SIZE using (sizeof(struct aspath) - sizeof(u_char)).
> Now that does not consider any padding bytes added. Instead this should
> use offsetof(struct aspath, data) so that the malloc does not allocate too
> much memory.
>
OK denis@
> --
> :wq Claudio
>
> Index: rde.h
> ===================================================================
> RCS file: /cvs/src/usr.sbin/bgpd/rde.h,v
> retrieving revision 1.198
> diff -u -p -r1.198 rde.h
> --- rde.h 24 Oct 2018 08:26:37 -0000 1.198
> +++ rde.h 25 Oct 2018 08:48:38 -0000
> @@ -23,6 +23,7 @@
> #include <sys/queue.h>
> #include <sys/tree.h>
> #include <stdint.h>
> +#include <stddef.h>
>
> #include "bgpd.h"
> #include "log.h"
> @@ -125,7 +126,7 @@ struct rde_peer {
> #define AS_SEQUENCE 2
> #define AS_CONFED_SEQUENCE 3
> #define AS_CONFED_SET 4
> -#define ASPATH_HEADER_SIZE (sizeof(struct aspath) - sizeof(u_char))
> +#define ASPATH_HEADER_SIZE (offsetof(struct aspath, data))
>
> struct aspath {
> LIST_ENTRY(aspath) entry;
>