Browse Source

TT#28300 fix missing strdup for multi homed interfaces

Change-Id: Ifaac7f85a5ab3515d95e72b6ee640c9e865cf219
changes/62/40962/1
Richard Fuchs 6 years ago
parent
commit
3c3729f81c
2 changed files with 14 additions and 3 deletions
  1. +3
    -3
      daemon/main.c
  2. +11
    -0
      lib/str.h

+ 3
- 3
daemon/main.c View File

@ -161,11 +161,11 @@ static int if_addr_parse(GQueue *q, char *s, struct ifaddrs *ifas) {
c = strchr(s, '/');
if (c) {
*c++ = 0;
str_init_dup(&name, s);
str_init(&name, s);
s = c;
}
else
str_init_dup(&name, "default");
str_init(&name, "default");
/* advertised address */
c = strchr(s, '!');
@ -229,7 +229,7 @@ static int if_addr_parse(GQueue *q, char *s, struct ifaddrs *ifas) {
while ((addr = g_queue_pop_head(&addrs))) {
ifa = g_slice_alloc0(sizeof(*ifa));
ifa->name = name;
str_init_dup_str(&ifa->name, &name);
ifa->local_address.addr = *addr;
ifa->local_address.type = socktype_udp;
ifa->advertised_address.addr = adv;


+ 11
- 0
lib/str.h View File

@ -62,6 +62,7 @@ INLINE str *str_init_len_assert_len(str *out, char *s, int buflen, int len);
#define str_init_len_assert(out, s, len) str_init_len_assert_len(out, s, sizeof(s), len)
/* inits a str object from a regular string and duplicates the contents. returns out */
INLINE str *str_init_dup(str *out, char *s);
INLINE str *str_init_dup_str(str *out, const str *s);
INLINE void str_free_dup(str *out);
/* returns new str object with uninitialized buffer large enough to hold `len` characters (+1 for null byte) */
INLINE str *str_alloc(int len);
@ -236,6 +237,16 @@ INLINE str *str_init_dup(str *out, char *s) {
out->len = s ? strlen(s) : 0;
return out;
}
INLINE str *str_init_dup_str(str *out, const str *s) {
if (!s || !s->len) {
*out = STR_NULL;
return out;
}
out->s = malloc(s->len + 1);
memcpy(out->s, s->s, s->len);
out->s[s->len] = '\0';
return out;
}
INLINE void str_free_dup(str *out) {
if (!out)
return ;


Loading…
Cancel
Save