Bug Summary

File:lib/libswan/netlink_attrib.c
Warning:line 43, column 2
Null pointer passed to 2nd parameter expecting 'nonnull'

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-redhat-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name netlink_attrib.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -relaxed-aliasing -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/home/build/quick-libreswan-2/lib/libswan -resource-dir /usr/lib64/clang/13.0.0 -D TimeZoneOffset=timezone -D PIE -D NSS_IPSEC_PROFILE -D XFRM_LIFETIME_DEFAULT=30 -D USE_IKEv1 -D XFRM_SUPPORT -D USE_XFRM_INTERFACE -D USE_DNSSEC -D DEFAULT_DNSSEC_ROOTKEY_FILE="/var/lib/unbound/root.key" -D HAVE_LABELED_IPSEC -D HAVE_SECCOMP -D LIBCURL -D USE_LINUX_AUDIT -D HAVE_NM -D USE_PAM_AUTH -D USE_3DES -D USE_AES -D USE_CAMELLIA -D USE_CHACHA -D USE_DH31 -D USE_MD5 -D USE_SHA1 -D USE_SHA2 -D USE_PRF_AES_XCBC -D USE_NSS_KDF -D DEFAULT_RUNDIR="/run/pluto" -D IPSEC_CONF="/etc/ipsec.conf" -D IPSEC_CONFDDIR="/etc/ipsec.d" -D IPSEC_NSSDIR="/var/lib/ipsec/nss" -D IPSEC_CONFDIR="/etc" -D IPSEC_EXECDIR="/usr/local/libexec/ipsec" -D IPSEC_SBINDIR="/usr/local/sbin" -D IPSEC_VARDIR="/var" -D POLICYGROUPSDIR="/etc/ipsec.d/policies" -D IPSEC_SECRETS_FILE="/etc/ipsec.secrets" -D FORCE_PR_ASSERT -D USE_FORK=1 -D USE_VFORK=0 -D USE_DAEMON=0 -D USE_PTHREAD_SETSCHEDPRIO=1 -D GCC_LINT -D HAVE_LIBCAP_NG -I . -I ../../OBJ.linux.x86_64/lib/libswan -I ../../include -I /usr/include/nss3 -I /usr/include/nspr4 -D HERE_FILENAME="lib/libswan/netlink_attrib.c" -internal-isystem /usr/lib64/clang/13.0.0/include -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/11/../../../../x86_64-redhat-linux/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -std=gnu99 -fdebug-compilation-dir=/home/build/quick-libreswan-2/lib/libswan -ferror-limit 19 -stack-protector 3 -fgnuc-version=4.2.1 -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/scan-build-2022-01-01-205714-1273399-1 -x c /home/build/quick-libreswan-2/lib/libswan/netlink_attrib.c
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
32void 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; })
;
3
Assuming the condition is true
4
Taking false branch
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);
5
Null pointer passed to 2nd parameter expecting 'nonnull'
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
47struct 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);
1
Passing null pointer value via 4th parameter 'data'
2
Calling 'nl_addattr_l'
52 return nest;
53}
54
55void 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
60void 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
65void 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}