Skip to content

Commit

Permalink
Merge pull request #944 from kernelkit/coverity-fixes
Browse files Browse the repository at this point in the history
Coverity fixes
  • Loading branch information
mattiaswal authored Feb 16, 2025
2 parents dc3b78e + 4d7dde5 commit 4e0ad1d
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 38 deletions.
7 changes: 2 additions & 5 deletions src/bin/copy.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/confd/src/ietf-keystore.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
3 changes: 2 additions & 1 deletion src/confd/src/infix-dhcp-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion src/confd/src/infix-if-bridge-mcd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
12 changes: 3 additions & 9 deletions src/confd/src/infix-if-bridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions src/confd/src/infix-if-gre.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
27 changes: 12 additions & 15 deletions src/confd/src/infix-if-vxlan.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
15 changes: 12 additions & 3 deletions src/confd/src/infix-services.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
9 changes: 8 additions & 1 deletion test/case/ietf_interfaces/bridge_stp_basic/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@
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",
Expand Down Expand Up @@ -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"))

Expand Down

0 comments on commit 4e0ad1d

Please sign in to comment.