summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
7d48665)
Fix a bunch of needless memzero() calls, a bunch of use-after-free
regarding _cleanup_free_ and drop unused variables.
Hint: Do NOT use _cleanup_free_ for temporary strappend() helpers that are
freed multiple times. All you safe is the last free() call, which is
really not worth the trouble resetting it to NULL all the time.
}
int sd_lldp_save(sd_lldp *lldp, const char *lldp_file) {
}
int sd_lldp_save(sd_lldp *lldp, const char *lldp_file) {
- _cleanup_free_ char *s = NULL, *t = NULL, *k = NULL;
_cleanup_free_ char *temp_path = NULL;
_cleanup_fclose_ FILE *f = NULL;
uint8_t *mac, *port_id, type;
_cleanup_free_ char *temp_path = NULL;
_cleanup_fclose_ FILE *f = NULL;
uint8_t *mac, *port_id, type;
HASHMAP_FOREACH(c, lldp->neighbour_mib, i) {
LIST_FOREACH(port, p, c->ports) {
HASHMAP_FOREACH(c, lldp->neighbour_mib, i) {
LIST_FOREACH(port, p, c->ports) {
+ _cleanup_free_ char *s = NULL;
+ char *k, *t;
r = lldp_read_chassis_id(p->packet, &type, &length, &mac);
if (r < 0)
continue;
r = lldp_read_chassis_id(p->packet, &type, &length, &mac);
if (r < 0)
continue;
- memzero(buf, LINE_MAX);
-
sprintf(buf, "'_Chassis=%02x:%02x:%02x:%02x:%02x:%02x' '_CType=%d' ",
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5], type);
sprintf(buf, "'_Chassis=%02x:%02x:%02x:%02x:%02x:%02x' '_CType=%d' ",
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5], type);
return -ENOMEM;
r = lldp_read_port_id(p->packet, &type, &length, &port_id);
return -ENOMEM;
r = lldp_read_port_id(p->packet, &type, &length, &port_id);
- if (r < 0) {
- free(s);
- memzero(buf, LINE_MAX);
if (type != LLDP_PORT_SUBTYPE_MAC_ADDRESS) {
if (type != LLDP_PORT_SUBTYPE_MAC_ADDRESS) {
k = strndup((char *) port_id, length -1);
if (!k)
return -ENOMEM;
sprintf(buf, "'_Port=%s' '_PType=%d' ", k , type);
k = strndup((char *) port_id, length -1);
if (!k)
return -ENOMEM;
sprintf(buf, "'_Port=%s' '_PType=%d' ", k , type);
-
- t = strappend(s, buf);
-
sprintf(buf, "'_Port=%02x:%02x:%02x:%02x:%02x:%02x' '_PType=%d' ",
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5], type);
sprintf(buf, "'_Port=%02x:%02x:%02x:%02x:%02x:%02x' '_PType=%d' ",
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5], type);
-
- t = strappend(s, buf);
+ k = strappend(s, buf);
+ if (!k)
time = now(CLOCK_BOOTTIME);
/* Don't write expired packets */
time = now(CLOCK_BOOTTIME);
/* Don't write expired packets */
- if(time - p->until <= 0) {
- free(s);
+ if (time - p->until <= 0)
- memzero(buf, LINE_MAX);
sprintf(buf, "'_TTL=%lu' ", p->until);
sprintf(buf, "'_TTL=%lu' ", p->until);
- t = strappend(s, buf);
- if (!t)
+ k = strappend(s, buf);
+ if (!k)
r = lldp_read_system_name(p->packet, &length, &k);
if (r < 0)
r = lldp_read_system_name(p->packet, &length, &k);
if (r < 0)
return -ENOMEM;
k = strjoin(s, "'_NAME=", t, "' ", NULL);
return -ENOMEM;
k = strjoin(s, "'_NAME=", t, "' ", NULL);
- memzero(buf, LINE_MAX);
-
(void)lldp_read_system_capability(p->packet, &data);
sprintf(buf, "'_CAP=%x'", data);
(void)lldp_read_system_capability(p->packet, &data);
sprintf(buf, "'_CAP=%x'", data);
- t = strappend(s, buf);
- if (!t)
+ k = strappend(s, buf);
+ if (!k)
- fprintf(f, "%s\n", t);
-
+ s = k;
+
+ fprintf(f, "%s\n", s);
- s = NULL;
- t = NULL;
- k = NULL;
-
fflush(f);
if (ferror(f) || rename(temp_path, lldp_file) < 0) {
fflush(f);
if (ferror(f) || rename(temp_path, lldp_file) < 0) {