mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
using memdup() will invalidate pointers to the object which might have been used during _init() and _parse() calls
This commit is contained in:
parent
9bb91af30d
commit
49c0e9957a
11 changed files with 122 additions and 122 deletions
|
@ -100,10 +100,9 @@ int fpga_card_parse(struct fpga_card *c, config_setting_t *cfg)
|
|||
const char *vlnv;
|
||||
|
||||
struct fpga_ip_type *vt;
|
||||
struct fpga_ip ip = {
|
||||
.card = c,
|
||||
.state = STATE_DESTROYED
|
||||
};
|
||||
struct fpga_ip *ip = alloc(sizeof(struct fpga_ip));
|
||||
|
||||
ip->card = c;
|
||||
|
||||
if (!config_setting_lookup_string(cfg, "vlnv", &vlnv))
|
||||
cerror(cfg, "FPGA IP core %s is missing the VLNV identifier", c->name);
|
||||
|
@ -112,15 +111,15 @@ int fpga_card_parse(struct fpga_card *c, config_setting_t *cfg)
|
|||
if (!vt)
|
||||
cerror(cfg, "FPGA IP core VLNV identifier '%s' is invalid", vlnv);
|
||||
|
||||
ret = fpga_ip_init(&ip, vt);
|
||||
ret = fpga_ip_init(ip, vt);
|
||||
if (ret)
|
||||
error("Failed to initalize FPGA IP core");
|
||||
|
||||
ret = fpga_ip_parse(&ip, cfg_ip);
|
||||
ret = fpga_ip_parse(ip, cfg_ip);
|
||||
if (ret)
|
||||
cerror(cfg_ip, "Failed to parse FPGA IP core");
|
||||
|
||||
list_push(&c->ips, memdup(&ip, sizeof(ip)));
|
||||
list_push(&c->ips, ip);
|
||||
}
|
||||
|
||||
c->cfg = cfg;
|
||||
|
@ -139,13 +138,13 @@ int fpga_card_parse_list(struct list *cards, config_setting_t *cfg)
|
|||
for (int i = 0; i < config_setting_length(cfg); i++) {
|
||||
config_setting_t *cfg_fpga = config_setting_get_elem(cfg, i);
|
||||
|
||||
struct fpga_card c;
|
||||
struct fpga_card *c = alloc(sizeof(struct fpga_card));
|
||||
|
||||
ret = fpga_card_parse(&c, cfg_fpga);
|
||||
ret = fpga_card_parse(c, cfg_fpga);
|
||||
if (ret)
|
||||
cerror(cfg_fpga, "Failed to parse FPGA card configuration");
|
||||
|
||||
list_push(cards, memdup(&c, sizeof(c)));
|
||||
list_push(cards, c);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -47,7 +47,6 @@ static int model_xsg_map_parse(uint32_t *map, size_t len, struct list *parameter
|
|||
{
|
||||
#define copy_string(off) strndup((char *) (data + (off)), (length - (off)) * 4);
|
||||
int j;
|
||||
struct model_param p, *e;
|
||||
struct model_info *i;
|
||||
|
||||
/* Check magic */
|
||||
|
@ -64,21 +63,21 @@ static int model_xsg_map_parse(uint32_t *map, size_t len, struct list *parameter
|
|||
case XSG_BLOCK_GATEWAY_OUT:
|
||||
if (length < 4)
|
||||
break; /* block is to small to describe a gateway */
|
||||
|
||||
struct model_param *e, *p = alloc(sizeof(struct model_param));
|
||||
|
||||
memset(&p, 0, sizeof(p));
|
||||
p->name = copy_string(3);
|
||||
p->default_value.flt = *((float *) &data[1]);
|
||||
p->offset = data[2];
|
||||
p->direction = type & 0x1;
|
||||
p->type = (data[0] >> 0) & 0xFF;
|
||||
p->binpt = (data[0] >> 8) & 0xFF;
|
||||
|
||||
p.name = copy_string(3);
|
||||
p.default_value.flt = *((float *) &data[1]);
|
||||
p.offset = data[2];
|
||||
p.direction = type & 0x1;
|
||||
p.type = (data[0] >> 0) & 0xFF;
|
||||
p.binpt = (data[0] >> 8) & 0xFF;
|
||||
|
||||
e = list_lookup(parameters, p.name);
|
||||
e = list_lookup(parameters, p->name);
|
||||
if (e)
|
||||
model_param_update(e, &p);
|
||||
model_param_update(e, p);
|
||||
else
|
||||
list_push(parameters, memdup(&p, sizeof(p)));
|
||||
list_push(parameters, p);
|
||||
break;
|
||||
|
||||
case XSG_BLOCK_INFO:
|
||||
|
@ -137,7 +136,6 @@ static int model_xsg_map_read(uint32_t *map, size_t len, void *baseaddr)
|
|||
int model_parse(struct fpga_ip *c)
|
||||
{
|
||||
struct model *m = c->_vd;
|
||||
struct model_param p;
|
||||
|
||||
config_setting_t *cfg_params, *cfg_param;
|
||||
|
||||
|
@ -153,12 +151,12 @@ int model_parse(struct fpga_ip *c)
|
|||
for (int i = 0; i < config_setting_length(cfg_params); i++) {
|
||||
cfg_param = config_setting_get_elem(cfg_params, i);
|
||||
|
||||
memset(&p, 0, sizeof(p));
|
||||
struct model_param *p = alloc(sizeof(struct model_param));
|
||||
|
||||
p.name = config_setting_name(cfg_param);
|
||||
p.default_value.flt = config_setting_get_float(cfg_param);
|
||||
p->name = config_setting_name(cfg_param);
|
||||
p->default_value.flt = config_setting_get_float(cfg_param);
|
||||
|
||||
list_push(&m->parameters, memdup(&p, sizeof(p)));
|
||||
list_push(&m->parameters, p);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -107,33 +107,34 @@ int switch_parse(struct fpga_ip *c)
|
|||
for (int i = 0; i < config_setting_length(cfg_sw); i++) {
|
||||
cfg_path = config_setting_get_elem(cfg_sw, i);
|
||||
|
||||
struct sw_path path;
|
||||
struct sw_path *p = alloc(sizeof(struct sw_path));
|
||||
int reverse;
|
||||
|
||||
if (!config_setting_lookup_bool(cfg_path, "reverse", &reverse))
|
||||
reverse = 0;
|
||||
|
||||
if (!config_setting_lookup_string(cfg_path, "in", &path.in) &&
|
||||
!config_setting_lookup_string(cfg_path, "from", &path.in) &&
|
||||
!config_setting_lookup_string(cfg_path, "src", &path.in) &&
|
||||
!config_setting_lookup_string(cfg_path, "source", &path.in))
|
||||
if (!config_setting_lookup_string(cfg_path, "in", &p->in) &&
|
||||
!config_setting_lookup_string(cfg_path, "from", &p->in) &&
|
||||
!config_setting_lookup_string(cfg_path, "src", &p->in) &&
|
||||
!config_setting_lookup_string(cfg_path, "source", &p->in))
|
||||
cerror(cfg_path, "Path is missing 'in' setting");
|
||||
|
||||
if (!config_setting_lookup_string(cfg_path, "out", &path.out) &&
|
||||
!config_setting_lookup_string(cfg_path, "to", &path.out) &&
|
||||
!config_setting_lookup_string(cfg_path, "dst", &path.out) &&
|
||||
!config_setting_lookup_string(cfg_path, "dest", &path.out) &&
|
||||
!config_setting_lookup_string(cfg_path, "sink", &path.out))
|
||||
if (!config_setting_lookup_string(cfg_path, "out", &p->out) &&
|
||||
!config_setting_lookup_string(cfg_path, "to", &p->out) &&
|
||||
!config_setting_lookup_string(cfg_path, "dst", &p->out) &&
|
||||
!config_setting_lookup_string(cfg_path, "dest", &p->out) &&
|
||||
!config_setting_lookup_string(cfg_path, "sink", &p->out))
|
||||
cerror(cfg_path, "Path is missing 'out' setting");
|
||||
|
||||
list_push(&sw->paths, memdup(&path, sizeof(path)));
|
||||
list_push(&sw->paths, p);
|
||||
|
||||
if (reverse) {
|
||||
const char *tmp = path.in;
|
||||
path.in = path.out;
|
||||
path.out = tmp;
|
||||
struct sw_path *r = memdup(p, sizeof(struct sw_path));
|
||||
|
||||
r->in = p->out;
|
||||
r->out = p->in;
|
||||
|
||||
list_push(&sw->paths, memdup(&path, sizeof(path)));
|
||||
list_push(&sw->paths, r);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
10
lib/hook.c
10
lib/hook.c
|
@ -183,17 +183,17 @@ int hook_parse_list(struct list *list, config_setting_t *cfg, struct path *o)
|
|||
if (!p)
|
||||
continue; /* We ignore all non hook settings in this libconfig object setting */
|
||||
|
||||
struct hook h = { .state = STATE_DESTROYED };
|
||||
|
||||
ret = hook_init(&h, &p->hook, o);
|
||||
struct hook *h = alloc(sizeof(struct hook));
|
||||
|
||||
ret = hook_init(h, &p->hook, o);
|
||||
if (ret)
|
||||
continue;
|
||||
|
||||
ret = hook_parse(&h, cfg_hook);
|
||||
ret = hook_parse(h, cfg_hook);
|
||||
if (ret)
|
||||
continue;
|
||||
|
||||
list_push(list, memdup(&h, sizeof(h)));
|
||||
list_push(list, h);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
int pci_init(struct pci *p)
|
||||
{
|
||||
struct dirent *entry;
|
||||
struct dirent *e;
|
||||
DIR *dp;
|
||||
FILE *f;
|
||||
char path[PATH_MAX];
|
||||
|
@ -32,17 +32,17 @@ int pci_init(struct pci *p)
|
|||
return -1;
|
||||
}
|
||||
|
||||
while ((entry = readdir(dp))) {
|
||||
struct pci_device d;
|
||||
while ((e = readdir(dp))) {
|
||||
struct pci_device *d = alloc(sizeof(struct pci_device));
|
||||
|
||||
struct { const char *s; int *p; } map[] = {
|
||||
{ "vendor", &d.id.vendor },
|
||||
{ "device", &d.id.device }
|
||||
{ "vendor", &d->id.vendor },
|
||||
{ "device", &d->id.device }
|
||||
};
|
||||
|
||||
/* Read vendor & device id */
|
||||
for (int i = 0; i < 2; i++) {
|
||||
snprintf(path, sizeof(path), "%s/bus/pci/devices/%s/%s", SYSFS_PATH, entry->d_name, map[i].s);
|
||||
snprintf(path, sizeof(path), "%s/bus/pci/devices/%s/%s", SYSFS_PATH, e->d_name, map[i].s);
|
||||
|
||||
f = fopen(path, "r");
|
||||
if (!f)
|
||||
|
@ -56,11 +56,11 @@ int pci_init(struct pci *p)
|
|||
}
|
||||
|
||||
/* Get slot id */
|
||||
ret = sscanf(entry->d_name, "%4x:%2x:%2x.%u", &d.slot.domain, &d.slot.bus, &d.slot.device, &d.slot.function);
|
||||
ret = sscanf(e->d_name, "%4x:%2x:%2x.%u", &d->slot.domain, &d->slot.bus, &d->slot.device, &d->slot.function);
|
||||
if (ret != 4)
|
||||
error("Failed to parse PCI slot number: %s", entry->d_name);
|
||||
error("Failed to parse PCI slot number: %s", e->d_name);
|
||||
|
||||
list_push(&p->devices, memdup(&d, sizeof(d)));
|
||||
list_push(&p->devices, d);
|
||||
}
|
||||
|
||||
closedir(dp);
|
||||
|
|
|
@ -204,20 +204,21 @@ int mapping_parse(struct mapping *m, config_setting_t *cfg)
|
|||
m->real_length = 0;
|
||||
|
||||
for (int i = 0; i < config_setting_length(cfg); i++) {
|
||||
struct mapping_entry e;
|
||||
config_setting_t *cfg_mapping;
|
||||
|
||||
cfg_mapping = config_setting_get_elem(cfg, i);
|
||||
if (!cfg_mapping)
|
||||
return -1;
|
||||
|
||||
ret = mapping_entry_parse(&e, cfg_mapping);
|
||||
struct mapping_entry *e = alloc(sizeof(struct mapping_entry));
|
||||
|
||||
ret = mapping_entry_parse(e, cfg_mapping);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
list_push(&m->entries, memdup(&e, sizeof(e)));
|
||||
list_push(&m->entries, e);
|
||||
|
||||
m->real_length += e.length;
|
||||
m->real_length += e->length;
|
||||
}
|
||||
|
||||
m->state = STATE_PARSED;
|
||||
|
|
|
@ -204,48 +204,49 @@ static int ngsi_parse_mapping(struct list *mapping, config_setting_t *cfg)
|
|||
|
||||
list_init(mapping);
|
||||
|
||||
for (int j = 0; j < config_setting_length(cfg); j++) { INDENT
|
||||
for (int j = 0; j < config_setting_length(cfg); j++) {
|
||||
const char *token = config_setting_get_string_elem(cfg, j);
|
||||
if (!token)
|
||||
return -2;
|
||||
|
||||
struct ngsi_attribute map = {
|
||||
.index = j
|
||||
};
|
||||
struct ngsi_attribute *a = alloc(sizeof(struct ngsi_attribute));
|
||||
|
||||
a->index = j;
|
||||
|
||||
/* Parse Attribute: AttributeName(AttributeType) */
|
||||
int bytes;
|
||||
if (sscanf(token, "%m[^(](%m[^)])%n", &map.name, &map.type, &bytes) != 2)
|
||||
if (sscanf(token, "%m[^(](%m[^)])%n", &a->name, &a->type, &bytes) != 2)
|
||||
cerror(cfg, "Invalid mapping token: '%s'", token);
|
||||
|
||||
token += bytes;
|
||||
|
||||
/* MetadataName(MetadataType)=MetadataValue */
|
||||
list_init(&map.metadata);
|
||||
struct ngsi_metadata meta;
|
||||
while (sscanf(token, " %m[^(](%m[^)])=%ms%n", &meta.name, &meta.type, &meta.value, &bytes) == 3) { INDENT
|
||||
list_push(&map.metadata, memdup(&meta, sizeof(meta)));
|
||||
list_init(&a->metadata);
|
||||
|
||||
struct ngsi_metadata m;
|
||||
while (sscanf(token, " %m[^(](%m[^)])=%ms%n", &m.name, &m.type, &m.value, &bytes) == 3) {
|
||||
list_push(&a->metadata, memdup(&m, sizeof(m)));
|
||||
token += bytes;
|
||||
}
|
||||
|
||||
/* Static metadata */
|
||||
struct ngsi_metadata source = {
|
||||
/* Metadata: source(string)=name */
|
||||
struct ngsi_metadata s = {
|
||||
.name = "source",
|
||||
.type = "string",
|
||||
.value = name,
|
||||
.value = name
|
||||
};
|
||||
|
||||
struct ngsi_metadata index = {
|
||||
/* Metadata: index(integer)=j */
|
||||
struct ngsi_metadata i = {
|
||||
.name = "index",
|
||||
.type = "integer",
|
||||
.value = alloc(11)
|
||||
.type = "integer"
|
||||
};
|
||||
snprintf(index.value, 11, "%u", j);
|
||||
asprintf(&i.value, "%u", j);
|
||||
|
||||
list_push(&map.metadata, memdup(&index, sizeof(index)));
|
||||
list_push(&map.metadata, memdup(&source, sizeof(source)));
|
||||
list_push(&a->metadata, memdup(&s, sizeof(s)));
|
||||
list_push(&a->metadata, memdup(&i, sizeof(i)));
|
||||
|
||||
list_push(mapping, memdup(&map, sizeof(map)));
|
||||
list_push(mapping, a);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -78,13 +78,12 @@ int socket_init(struct super_node *sn)
|
|||
}
|
||||
|
||||
/* If not found, create a new interface */
|
||||
struct interface j = { .sockets.state = STATE_DESTROYED };
|
||||
i = alloc(sizeof(struct interface));
|
||||
|
||||
ret = if_init(&j, link);
|
||||
ret = if_init(i, link);
|
||||
if (ret)
|
||||
continue;
|
||||
|
||||
i = memdup(&j, sizeof(j));
|
||||
list_push(&interfaces, i);
|
||||
|
||||
found: list_push(&i->sockets, s);
|
||||
|
|
|
@ -533,28 +533,26 @@ int websocket_parse(struct node *n, config_setting_t *cfg)
|
|||
if (!uri)
|
||||
cerror(cfg_dests, "The 'destinations' setting must be an array of URLs");
|
||||
|
||||
struct websocket_destination d;
|
||||
struct websocket_destination *d = alloc(sizeof(struct websocket_destination));
|
||||
|
||||
memset(&d, 0, sizeof(d));
|
||||
|
||||
d.uri = strdup(uri);
|
||||
if (!d.uri)
|
||||
d->uri = strdup(uri);
|
||||
if (!d->uri)
|
||||
serror("Failed to allocate memory");
|
||||
|
||||
ret = lws_parse_uri(d.uri, &prot, &ads, &d.info.port, &path);
|
||||
ret = lws_parse_uri(d->uri, &prot, &ads, &d->info.port, &path);
|
||||
if (ret)
|
||||
cerror(cfg_dests, "Failed to parse websocket URI: '%s'", uri);
|
||||
|
||||
d.info.ssl_connection = !strcmp(prot, "https");
|
||||
d.info.address = strdup(ads);
|
||||
d.info.host = d.info.address;
|
||||
d.info.origin = d.info.address;
|
||||
d.info.ietf_version_or_minus_one = -1;
|
||||
d.info.protocol = "live";
|
||||
d->info.ssl_connection = !strcmp(prot, "https");
|
||||
d->info.address = strdup(ads);
|
||||
d->info.host = d->info.address;
|
||||
d->info.origin = d->info.address;
|
||||
d->info.ietf_version_or_minus_one = -1;
|
||||
d->info.protocol = "live";
|
||||
|
||||
ret = asprintf((char **) &d.info.path, "/%s", path);
|
||||
ret = asprintf((char **) &d->info.path, "/%s", path);
|
||||
|
||||
list_push(&w->destinations, memdup(&d, sizeof(d)));
|
||||
list_push(&w->destinations, d);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
27
lib/path.c
27
lib/path.c
|
@ -243,12 +243,12 @@ int path_parse(struct path *p, config_setting_t *cfg, struct list *nodes)
|
|||
for (size_t i = 0; i < list_length(&destinations); i++) {
|
||||
struct node *n = list_at(&destinations, i);
|
||||
|
||||
struct path_destination pd = {
|
||||
.node = n,
|
||||
.queuelen = p->queuelen
|
||||
};
|
||||
struct path_destination *pd = alloc(sizeof(struct path_destination));
|
||||
|
||||
pd->node = n;
|
||||
pd->queuelen = p->queuelen;
|
||||
|
||||
list_push(&p->destinations, memdup(&pd, sizeof(pd)));
|
||||
list_push(&p->destinations, pd);
|
||||
}
|
||||
|
||||
list_destroy(&destinations, NULL, false);
|
||||
|
@ -286,15 +286,18 @@ int path_init2(struct path *p)
|
|||
struct plugin *q = list_at(&plugins, i);
|
||||
|
||||
if (q->type == PLUGIN_TYPE_HOOK) {
|
||||
struct hook h = { .state = STATE_DESTROYED };
|
||||
struct hook_type *vt = &q->hook;
|
||||
|
||||
if (vt->builtin) {
|
||||
ret = hook_init(&h, vt, p);
|
||||
if (ret)
|
||||
struct hook *h = alloc(sizeof(struct hook));
|
||||
|
||||
ret = hook_init(h, vt, p);
|
||||
if (ret) {
|
||||
free(h);
|
||||
return ret;
|
||||
}
|
||||
|
||||
list_push(&p->hooks, memdup(&h, sizeof(h)));
|
||||
list_push(&p->hooks, h);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -461,13 +464,13 @@ int path_reverse(struct path *p, struct path *r)
|
|||
|
||||
for (size_t i = 0; i < list_length(&p->hooks); i++) {
|
||||
struct hook *h = list_at(&p->hooks, i);
|
||||
struct hook hc = { .state = STATE_DESTROYED };
|
||||
struct hook *g = alloc(sizeof(struct hook));
|
||||
|
||||
ret = hook_init(&hc, h->_vt, p);
|
||||
ret = hook_init(g, h->_vt, r);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
list_push(&r->hooks, memdup(&hc, sizeof(hc)));
|
||||
list_push(&r->hooks, g);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -213,17 +213,17 @@ int super_node_parse(struct super_node *sn, config_setting_t *cfg)
|
|||
for (int i = 0; i < config_setting_length(cfg_plugins); i++) {
|
||||
struct config_setting_t *cfg_plugin = config_setting_get_elem(cfg_plugins, i);
|
||||
|
||||
struct plugin plugin = { .state = STATE_DESTROYED };
|
||||
struct plugin *p = alloc(sizeof(struct plugin));
|
||||
|
||||
ret = plugin_init(&plugin);
|
||||
ret = plugin_init(p);
|
||||
if (ret)
|
||||
cerror(cfg_plugin, "Failed to initialize plugin");
|
||||
|
||||
ret = plugin_parse(&plugin, cfg_plugin);
|
||||
ret = plugin_parse(p, cfg_plugin);
|
||||
if (ret)
|
||||
cerror(cfg_plugin, "Failed to parse plugin");
|
||||
|
||||
list_push(&sn->plugins, memdup(&plugin, sizeof(plugin)));
|
||||
list_push(&sn->plugins, p);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -272,30 +272,30 @@ int super_node_parse(struct super_node *sn, config_setting_t *cfg)
|
|||
for (int i = 0; i < config_setting_length(cfg_paths); i++) {
|
||||
config_setting_t *cfg_path = config_setting_get_elem(cfg_paths, i);
|
||||
|
||||
struct path p = { .state = STATE_DESTROYED };
|
||||
struct path *p = alloc(sizeof(struct path));
|
||||
|
||||
ret = path_init(&p, sn);
|
||||
ret = path_init(p, sn);
|
||||
if (ret)
|
||||
cerror(cfg_path, "Failed to init path");
|
||||
|
||||
ret = path_parse(&p, cfg_path, &sn->nodes);
|
||||
ret = path_parse(p, cfg_path, &sn->nodes);
|
||||
if (ret)
|
||||
cerror(cfg_path, "Failed to parse path");
|
||||
|
||||
list_push(&sn->paths, memdup(&p, sizeof(p)));
|
||||
list_push(&sn->paths, p);
|
||||
|
||||
if (p.reverse) {
|
||||
struct path r = { .state = STATE_DESTROYED };
|
||||
if (p->reverse) {
|
||||
struct path *r = alloc(sizeof(struct path));
|
||||
|
||||
ret = path_init(&r, sn);
|
||||
ret = path_init(r, sn);
|
||||
if (ret)
|
||||
cerror(cfg_path, "Failed to init path");
|
||||
|
||||
ret = path_reverse(&p, &r);
|
||||
ret = path_reverse(p, r);
|
||||
if (ret)
|
||||
cerror(cfg_path, "Failed to reverse path %s", path_name(&p));
|
||||
cerror(cfg_path, "Failed to reverse path %s", path_name(p));
|
||||
|
||||
list_push(&sn->paths, memdup(&r, sizeof(p)));
|
||||
list_push(&sn->paths, r);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue