-Checks: '-*,bugprone-narrowing-conversions'
-HeaderFilterRegex: '.*'
-WarningsAsErrors: '*'
+Checks: "-*,performance-*,modernize-*,misc-*,-misc-no-recursion,bugprone-*,-bugprone-macro-parentheses,-bugprone-easily-swappable-parameters,-bugprone-reserved-identifier,-bugprone-suspicious-string-compare,-bugprone-implicit-widening-of-multiplication-result,-bugprone-not-null-terminated-result,-bugprone-branch-clone,-bugprone-sizeof-expression,clang-analyzer-*,-clang-analyzer-security.insecureAPI.*,-clang-analyzer-core.UndefinedBinaryOperatorResult"
+HeaderFilterRegex: ".*"
+WarningsAsErrors: "*"
++total_vars;
}
+ if(!total_vars) {
+ splay_empty_tree(&config);
+ return;
+ }
+
const size_t countlen = total_vars * sizeof(int);
int *count = alloca(countlen);
memset(count, 0, countlen);
}
static char *grep(const char *data, const char *var) {
- static char value[1024];
+ char value[1024];
const char *p = data;
size_t varlen = strlen(var);
memcpy(value, p, e - p);
value[e - p] = 0;
- return value;
+ return xstrdup(value);
}
static bool finalize_join(void) {
}
if(!netname) {
- const char *net = grep(data, "NetName");
+ char *net = grep(data, "NetName");
if(net) {
- netname = xstrdup(net);
+ netname = net;
if(!check_netname(netname, true)) {
fprintf(stderr, "Unsafe NetName found in invitation!\n");
}
static bool read_packet(vpn_packet_t *packet) {
- ssize_t inlen;
-
switch(state) {
case 0: {
struct sockaddr sa;
}
case 1: {
- if((inlen = read(request_fd, &request, sizeof(request))) != sizeof(request)) {
+ if(read(request_fd, &request, sizeof(request)) != sizeof(request)) {
logger(DEBUG_ALWAYS, LOG_ERR, "Error while reading request from %s %s: %s", device_info,
device, strerror(errno));
event_exit();
}
case 2: {
- if((inlen = read(data_fd, DATA(packet), MTU)) <= 0) {
+ ssize_t inlen = read(data_fd, DATA(packet), MTU);
+
+ if(inlen <= 0) {
logger(DEBUG_ALWAYS, LOG_ERR, "Error while reading from %s %s: %s", device_info,
device, strerror(errno));
event_exit();
static const char *device_info = "raw_socket";
static bool setup_device(void) {
- struct ifreq ifr;
- struct sockaddr_ll sa;
+ struct ifreq ifr = {0};
+ struct sockaddr_ll sa = {0};
if(!get_config_string(lookup_config(&config_tree, "Interface"), &iface)) {
iface = xstrdup("eth0");
return false;
}
- memset(&ifr, 0, sizeof(ifr));
-
#ifdef FD_CLOEXEC
fcntl(device_fd, F_SETFD, FD_CLOEXEC);
#endif
return false;
}
- memset(&sa, '0', sizeof(sa));
sa.sll_family = AF_PACKET;
sa.sll_protocol = htons(ETH_P_ALL);
sa.sll_ifindex = ifr.ifr_ifindex;
static void sigint_handler(int sig) {
(void)sig;
- fprintf(stderr, "\n");
+ if(write(2, "\n", 1) < 0) {
+ // nothing we can do
+ }
+
shutdown(fd, SHUT_RDWR);
}
#endif
char filename[PATH_MAX];
if(node) {
- if((size_t)snprintf(filename, sizeof(filename), "%s" SLASH "%s", hosts_dir, node) >= sizeof(filename)) {
- fprintf(stderr, "Filename too long: %s" SLASH "%s\n", hosts_dir, node);
- free(node);
- return 1;
- }
+ size_t wrote = (size_t)snprintf(filename, sizeof(filename), "%s" SLASH "%s", hosts_dir, node);
if(node != line) {
free(node);
node = NULL;
}
+
+ if(wrote >= sizeof(filename)) {
+ fprintf(stderr, "Filename too long: %s" SLASH "%s\n", hosts_dir, node);
+ return 1;
+ }
+
} else {
snprintf(filename, sizeof(filename), "%s", tinc_conf);
}
goto exit_fail;
case OPT_CONFIG_FILE:
+ assert(optarg);
free(confbase);
confbase = get_path_arg(optarg);
break;
break;
case OPT_NETNAME:
+ assert(optarg);
free(netname);
netname = xstrdup(optarg);
break;
break;
case OPT_PIDFILE:
+ assert(optarg);
free(pidfilename);
pidfilename = get_path_arg(optarg);
break;