File: | lib/libswan/netlink_attrib.c |
Warning: | line 43, column 2 Null pointer passed to 2nd parameter expecting 'nonnull' |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* | |||
2 | * netlink attributes to message, for libreswan | |||
3 | * | |||
4 | * Copyright (C) 2018-2020 Antony Antony <antony@phenome.org> | |||
5 | * A part of this came from iproute2 lib/libnetlink.c | |||
6 | * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru> | |||
7 | * | |||
8 | * This program is free software; you can redistribute it and/or modify it | |||
9 | * under the terms of the GNU General Public License as published by the | |||
10 | * Free Software Foundation; either version 2 of the License, or (at your | |||
11 | * option) any later version. See <https://www.gnu.org/licenses/gpl2.txt>. | |||
12 | * | |||
13 | * This program is distributed in the hope that it will be useful, but | |||
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | |||
15 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |||
16 | * for more details. | |||
17 | */ | |||
18 | ||||
19 | #include <linux1/rtnetlink.h> | |||
20 | #include <linux1/if_addr.h> | |||
21 | #include <linux1/if_link.h> | |||
22 | ||||
23 | #include "lswlog.h" | |||
24 | #include "netlink_attrib.h" | |||
25 | ||||
26 | #define RTA_TAIL(rta)((struct rtattr *) (((void *) (rta)) + ( (((rta)->rta_len) +4U -1) & ~(4U -1) ))) ((struct rtattr *) (((void *) (rta)) + \ | |||
27 | RTA_ALIGN((rta)->rta_len)( (((rta)->rta_len)+4U -1) & ~(4U -1) ))) | |||
28 | ||||
29 | #define NLMSG_TAIL(nmsg)((struct rtattr *) (((void *) (nmsg)) + ( (((nmsg)->nlmsg_len )+4U -1) & ~(4U -1) ))) \ | |||
30 | ((struct rtattr *) (((void *) (nmsg)) + NLMSG_ALIGN((nmsg)->nlmsg_len)( (((nmsg)->nlmsg_len)+4U -1) & ~(4U -1) ))) | |||
31 | ||||
32 | void nl_addattr_l(struct nlmsghdr *n, const unsigned short maxlen, | |||
33 | const unsigned short type, const void *data, int alen) | |||
34 | { | |||
35 | unsigned short len = RTA_LENGTH(alen)(( ((sizeof(struct rtattr))+4U -1) & ~(4U -1) ) + (alen)); | |||
36 | ||||
37 | passert(NLMSG_ALIGN(n->nlmsg_len) + RTA_ALIGN(len) <= maxlen)({ _Bool assertion__ = ( ((n->nlmsg_len)+4U -1) & ~(4U -1) ) + ( ((len)+4U -1) & ~(4U -1) ) <= maxlen; if (! assertion__) { where_t here = ({ static const struct where here = { .func = __func__, .file = "lib/libswan/netlink_attrib.c" , .line = 37, }; &here; }); const struct logger *logger_ = &failsafe_logger; llog_passert(logger_, here, "%s", "( ((n->nlmsg_len)+4U-1) & ~(4U-1) ) + ( ((len)+4U-1) & ~(4U-1) ) <= maxlen" ); } (void) 1; }); | |||
38 | ||||
39 | struct rtattr *rta = NLMSG_TAIL(n)((struct rtattr *) (((void *) (n)) + ( (((n)->nlmsg_len)+4U -1) & ~(4U -1) ))); | |||
40 | ||||
41 | rta->rta_type = type; | |||
42 | rta->rta_len = len; | |||
43 | memcpy(RTA_DATA(rta)((void*)(((char*)(rta)) + (( ((sizeof(struct rtattr))+4U -1) & ~(4U -1) ) + (0)))), data, alen); | |||
| ||||
44 | n->nlmsg_len = NLMSG_ALIGN(n->nlmsg_len)( ((n->nlmsg_len)+4U -1) & ~(4U -1) ) + RTA_ALIGN(len)( ((len)+4U -1) & ~(4U -1) ); | |||
45 | } | |||
46 | ||||
47 | struct rtattr *nl_addattr_nest(struct nlmsghdr *n, int maxlen, int type) | |||
48 | { | |||
49 | struct rtattr *nest = NLMSG_TAIL(n)((struct rtattr *) (((void *) (n)) + ( (((n)->nlmsg_len)+4U -1) & ~(4U -1) ))); | |||
50 | ||||
51 | nl_addattr_l(n, maxlen, type, NULL((void*)0), 0); | |||
| ||||
52 | return nest; | |||
53 | } | |||
54 | ||||
55 | void nl_addattr_nest_end(struct nlmsghdr *n, struct rtattr *nest) | |||
56 | { | |||
57 | nest->rta_len = (void *)NLMSG_TAIL(n)((struct rtattr *) (((void *) (n)) + ( (((n)->nlmsg_len)+4U -1) & ~(4U -1) ))) - (void *)nest; | |||
58 | } | |||
59 | ||||
60 | void nl_addattrstrz(struct nlmsghdr *n, int maxlen, int type, const char *str /*non-NULL*/) | |||
61 | { | |||
62 | nl_addattr_l(n, maxlen, type, str, strlen(str)+1); | |||
63 | } | |||
64 | ||||
65 | void nl_addattr32(struct nlmsghdr *n, int maxlen, int type, const uint32_t data) | |||
66 | { | |||
67 | nl_addattr_l(n, maxlen, type, &data, sizeof(uint32_t)); | |||
68 | } |