Merge pull request #944 from kernelkit/coverity-fixes

Coverity fixes
This commit is contained in:
Mattias Walström
2025-02-16 12:36:56 +01:00
committed by GitHub
9 changed files with 47 additions and 38 deletions
+2 -5
View File
@@ -84,13 +84,10 @@ static void set_owner(const char *fn, const char *user)
struct passwd *pw;
pw = getpwnam(user);
if (!pw) {
fprintf(stderr, ERRMSG "setting owner %s on %s: %s\n", fn, user, strerror(errno));
if (pw && !chmod(fn, 0660) && !chown(fn, pw->pw_uid, pw->pw_gid))
return;
}
chmod(fn, 0660);
chown(fn, pw->pw_uid, pw->pw_gid);
fprintf(stderr, ERRMSG "setting owner %s on %s: %s\n", fn, user, strerror(errno));
}
static const char *infix_ds(const char *text, struct infix_ds **ds)
+1
View File
@@ -148,6 +148,7 @@ int ietf_keystore_init(struct confd *confd)
REGISTER_CHANGE(confd->session, "ietf-keystore", "/ietf-keystore:keystore//.",
SR_SUBSCR_UPDATE, change_cb, confd, &confd->sub);
return SR_ERR_OK;
fail:
if(rc)
ERROR("%s failed: %s", __func__, sr_strerror(rc));
+2 -1
View File
@@ -289,7 +289,8 @@ static void del(const char *subnet, struct lyd_node *cfg)
fclose(next);
/* Replace old leases file */
rename(DNSMASQ_LEASES"+", DNSMASQ_LEASES);
if (rename(DNSMASQ_LEASES"+", DNSMASQ_LEASES))
ERRNO("Failed switching to new %s", DNSMASQ_LEASES);
}
static int change(sr_session_ctx_t *session, uint32_t sub_id, const char *module,
+3 -1
View File
@@ -136,6 +136,8 @@ int bridge_mcd_gen(struct lyd_node *cifs)
}
out_remove:
remove("/etc/mc.d/bridges.conf.next");
if (remove("/etc/mc.d/bridges.conf.next"))
ERRNO("Failed removing /etc/mc.d/bridges.conf.next");
return err;
}
+3 -9
View File
@@ -426,10 +426,8 @@ static int init_snippets(struct ixif_br *br, struct lyd_node *dif, struct lyd_no
br->cif = cif;
br->ip = ip;
err = snippet_open(&br->bropts);
if (err)
goto err;
err = snippet_open(&br->bropts);
err = err ? : snippet_open(&br->init.vlan);
err = err ? : snippet_open(&br->init.mcast);
err = err ? : snippet_open(&br->init.mdb);
@@ -443,15 +441,11 @@ static int init_snippets(struct ixif_br *br, struct lyd_node *dif, struct lyd_no
snippet_close(&br->init.mdb, NULL);
snippet_close(&br->init.mcast, NULL);
snippet_close(&br->init.vlan, NULL);
goto err_close_bropts;
snippet_close(&br->bropts, NULL);
return err;
}
return 0;
err_close_bropts:
snippet_close(&br->bropts, NULL);
err:
return err;
}
static int collect_snippets(struct ixif_br *br)
+4 -3
View File
@@ -5,17 +5,18 @@
int gre_gen(struct lyd_node *dif, struct lyd_node *cif, FILE *ip)
{
const char *ifname, *local, *remote;
const char *local, *remote;
struct lyd_node *gre;
int ipv6;
ifname = lydx_get_cattr(cif, "name");
gre = lydx_get_child(cif, "gre");
local = lydx_get_cattr(gre, "local");
remote = lydx_get_cattr(gre, "remote");
ipv6 = !!strstr(local, ":");
fprintf(ip, "link add name %s", ifname);
fprintf(ip, "link add name %s",
lydx_get_cattr(cif, "name"));
switch (iftype_from_iface(cif)) {
case IFT_GRE:
+12 -15
View File
@@ -5,24 +5,21 @@
int vxlan_gen(struct lyd_node *dif, struct lyd_node *cif, FILE *ip)
{
const char *ifname, *local, *remote, *mac = NULL;
const char *vni, *remote_port;
struct lyd_node *node = NULL;
struct lyd_node *vxlan = NULL;
ifname = lydx_get_cattr(cif, "name");
node = lydx_get_descendant(lyd_child(cif), "vxlan", NULL);
if (!node)
vxlan = lydx_get_descendant(lyd_child(cif), "vxlan", NULL);
if (!vxlan)
return -EINVAL;
local = lydx_get_cattr(node, "local");
remote = lydx_get_cattr(node, "remote");
vni = lydx_get_cattr(node, "vni");
remote_port = lydx_get_cattr(node, "remote-port");
fprintf(ip, "link add name %s type vxlan id %s local %s remote %s dstport %s", ifname, vni, local, remote, remote_port);
if (mac)
fprintf(ip, "address %s\n", mac);
else
fprintf(ip, "\n");
fprintf(ip, "link add name %s type vxlan id %s local %s remote %s dstport %s",
lydx_get_cattr(cif, "name"),
lydx_get_cattr(vxlan, "vni"),
lydx_get_cattr(vxlan, "local"),
lydx_get_cattr(vxlan, "remote"),
lydx_get_cattr(vxlan, "remote-port"));
link_gen_address(cif, ip);
fputc('\n', ip);
return 0;
}
+12 -3
View File
@@ -349,7 +349,8 @@ static int lldp_change(sr_session_ctx_t *session, uint32_t sub_id, const char *m
if (erase(LLDP_CONFIG))
ERRNO("Failed to remove old %s", LLDP_CONFIG);
rename(LLDP_CONFIG_NEXT, LLDP_CONFIG);
if (rename(LLDP_CONFIG_NEXT, LLDP_CONFIG))
ERRNO("Failed switching to new %s", LLDP_CONFIG);
}
else
if (erase(LLDP_CONFIG))
@@ -531,7 +532,10 @@ static int change_keystore_cb(sr_session_ctx_t *session, uint32_t sub_id, const
if(rmrf(SSH_HOSTKEYS)) {
ERRNO("Failed to remove old SSH hostkeys: %d", errno);
}
rename(SSH_HOSTKEYS_NEXT, SSH_HOSTKEYS);
if (rename(SSH_HOSTKEYS_NEXT, SSH_HOSTKEYS))
ERRNO("Failed switching to new %s", SSH_HOSTKEYS);
svc_change(session, event, "/infix-services:ssh", "ssh", "sshd");
}
return SR_ERR_OK;
@@ -564,7 +568,12 @@ static int change_keystore_cb(sr_session_ctx_t *session, uint32_t sub_id, const
}
private_key = lydx_get_cattr(change, "cleartext-private-key");
public_key = lydx_get_cattr(change, "public-key");
mkdir(SSH_HOSTKEYS_NEXT, 0600);
if (mkdir(SSH_HOSTKEYS_NEXT, 0600) && (errno != EEXIST)) {
ERRNO("Failed creating %s", SSH_HOSTKEYS_NEXT);
rc = SR_ERR_INTERNAL;
}
if(systemf("/usr/libexec/infix/mksshkey %s %s %s %s", name, SSH_HOSTKEYS_NEXT, public_key, private_key))
rc = SR_ERR_INTERNAL;
}
@@ -16,6 +16,13 @@ directly connected to A.
import infamy
from infamy.util import parallel, until
def stp_compatible(physical, logical):
# Multi-chip mv88e6xxx systems do not flush their ATU's correctly
# (tracked by kernelkit/linux#2)
return "broken-stp" not in physical["provides"]
def addbr(dut):
ip = {
"A": "10.0.0.101",
@@ -133,7 +140,7 @@ def port_role(dut, port):
with infamy.Test() as test:
with test.step("Set up topology and attach to target DUT"):
env = infamy.Env()
env = infamy.Env(nodes_compatible=stp_compatible)
a, b, c, d = parallel(lambda: env.attach("A"), lambda: env.attach("B"),
lambda: env.attach("C"), lambda: env.attach("D"))