Skip to content

Commit 57a8db7

Browse files
committed
net: Use log_strdup() when printing debug strings
As the debugging print calls are async, all the strings that might be overwritten must use log_strdup() which will create a copy of the printable string. Signed-off-by: Jukka Rissanen <[email protected]>
1 parent d67414e commit 57a8db7

File tree

46 files changed

+513
-405
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+513
-405
lines changed

samples/net/coap_server/src/coap-server.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ static int query_get(struct coap_resource *resource,
494494
memcpy(str, options[i].value, options[i].len);
495495
str[options[i].len] = '\0';
496496

497-
NET_INFO("query[%d]: %s\n", i + 1, str);
497+
NET_INFO("query[%d]: %s\n", i + 1, log_strdup(str));
498498
}
499499

500500
NET_INFO("*******\n");

samples/net/dhcpv4_client/src/main.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,19 @@ static void handler(struct net_mgmt_event_callback *cb,
4141
}
4242

4343
NET_INFO("Your address: %s",
44-
net_addr_ntop(AF_INET,
44+
log_strdup(net_addr_ntop(AF_INET,
4545
&iface->config.ip.ipv4->unicast[i].address.in_addr,
46-
buf, sizeof(buf)));
46+
buf, sizeof(buf))));
4747
NET_INFO("Lease time: %u seconds",
4848
iface->config.dhcpv4.lease_time);
4949
NET_INFO("Subnet: %s",
50-
net_addr_ntop(AF_INET,
50+
log_strdup(net_addr_ntop(AF_INET,
5151
&iface->config.ip.ipv4->netmask,
52-
buf, sizeof(buf)));
52+
buf, sizeof(buf))));
5353
NET_INFO("Router: %s",
54-
net_addr_ntop(AF_INET, &iface->config.ip.ipv4->gw,
55-
buf, sizeof(buf)));
54+
log_strdup(net_addr_ntop(AF_INET,
55+
&iface->config.ip.ipv4->gw,
56+
buf, sizeof(buf))));
5657
}
5758
}
5859

samples/net/dns_resolve/src/main.c

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,10 @@ void dns_result_cb(enum dns_resolve_status status,
8383
return;
8484
}
8585

86-
NET_INFO("%s %s address: %s", user_data ? (char *)user_data : "<null>", hr_family,
87-
net_addr_ntop(info->ai_family, addr,
88-
hr_addr, sizeof(hr_addr)));
86+
NET_INFO("%s %s address: %s", user_data ? (char *)user_data : "<null>",
87+
hr_family,
88+
log_strdup(net_addr_ntop(info->ai_family, addr,
89+
hr_addr, sizeof(hr_addr))));
8990
}
9091

9192
void mdns_result_cb(enum dns_resolve_status status,
@@ -131,9 +132,10 @@ void mdns_result_cb(enum dns_resolve_status status,
131132
return;
132133
}
133134

134-
NET_INFO("%s %s address: %s", user_data ? (char *)user_data : "<null>", hr_family,
135-
net_addr_ntop(info->ai_family, addr,
136-
hr_addr, sizeof(hr_addr)));
135+
NET_INFO("%s %s address: %s", user_data ? (char *)user_data : "<null>",
136+
hr_family,
137+
log_strdup(net_addr_ntop(info->ai_family, addr,
138+
hr_addr, sizeof(hr_addr))));
137139
}
138140

139141
#if defined(CONFIG_NET_DHCPV4)
@@ -180,17 +182,19 @@ static void ipv4_addr_add_handler(struct net_mgmt_event_callback *cb,
180182
}
181183

182184
NET_INFO("IPv4 address: %s",
183-
net_addr_ntop(AF_INET, &if_addr->address.in_addr,
184-
hr_addr, NET_IPV4_ADDR_LEN));
185+
log_strdup(net_addr_ntop(AF_INET,
186+
&if_addr->address.in_addr,
187+
hr_addr, NET_IPV4_ADDR_LEN)));
185188
NET_INFO("Lease time: %u seconds",
186189
iface->config.dhcpv4.lease_time);
187190
NET_INFO("Subnet: %s",
188-
net_addr_ntop(AF_INET,
189-
&iface->config.ip.ipv4->netmask,
190-
hr_addr, NET_IPV4_ADDR_LEN));
191+
log_strdup(net_addr_ntop(AF_INET,
192+
&iface->config.ip.ipv4->netmask,
193+
hr_addr, NET_IPV4_ADDR_LEN)));
191194
NET_INFO("Router: %s",
192-
net_addr_ntop(AF_INET, &iface->config.ip.ipv4->gw,
193-
hr_addr, NET_IPV4_ADDR_LEN));
195+
log_strdup(net_addr_ntop(AF_INET,
196+
&iface->config.ip.ipv4->gw,
197+
hr_addr, NET_IPV4_ADDR_LEN)));
194198
break;
195199
}
196200

@@ -265,7 +269,8 @@ static void setup_ipv4(struct net_if *iface)
265269
net_if_ipv4_addr_add(iface, &addr, NET_ADDR_MANUAL, 0);
266270

267271
NET_INFO("IPv4 address: %s",
268-
net_addr_ntop(AF_INET, &addr, hr_addr, NET_IPV4_ADDR_LEN));
272+
log_strdup(net_addr_ntop(AF_INET, &addr, hr_addr,
273+
NET_IPV4_ADDR_LEN)));
269274

270275
ret = dns_get_addr_info(query,
271276
DNS_QUERY_TYPE_A,

samples/net/gptp/src/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ static void gptp_phase_dis_cb(u8_t *gm_identity,
135135
memcpy(id, gm_identity, sizeof(id));
136136

137137
NET_DBG("GM %s last phase %d.%lld",
138-
gptp_sprint_clock_id(gm_identity, output,
139-
sizeof(output)),
138+
log_strdup(gptp_sprint_clock_id(gm_identity, output,
139+
sizeof(output))),
140140
last_gm_ph_change->high,
141141
last_gm_ph_change->low);
142142
}

samples/net/ipv4_autoconf/src/main.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ static void handler(struct net_mgmt_event_callback *cb,
4646
}
4747

4848
NET_INFO("Your address: %s",
49-
net_addr_ntop(AF_INET,
50-
&cfg->ip.ipv4->unicast[i].address.in_addr,
51-
buf, sizeof(buf)));
49+
log_strdup(net_addr_ntop(AF_INET,
50+
&cfg->ip.ipv4->unicast[i].address.in_addr,
51+
buf, sizeof(buf))));
5252
}
5353
}
5454

samples/net/nats/src/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ static int in_addr_set(sa_family_t family,
106106
}
107107

108108
if (rc < 0) {
109-
NET_ERR("Invalid IP address: %s", ip_addr);
109+
NET_ERR("Invalid IP address: %s", log_strdup(ip_addr));
110110
return -EINVAL;
111111
}
112112
}

samples/net/promiscuous_mode/src/main.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,20 +115,24 @@ static void print_info(struct net_pkt *pkt)
115115
if (family == AF_INET) {
116116
if (next_hdr == IPPROTO_TCP || next_hdr == IPPROTO_UDP) {
117117
NET_INFO("%s %s (%zd) %s:%u -> %s:%u",
118-
"IPv4", proto, len, src_addr, src_port,
119-
dst_addr, dst_port);
118+
"IPv4", proto, len,
119+
log_strdup(src_addr), src_port,
120+
log_strdup(dst_addr), dst_port);
120121
} else {
121122
NET_INFO("%s %s (%zd) %s -> %s", "IPv4", proto,
122-
len, src_addr, dst_addr);
123+
len, log_strdup(src_addr),
124+
log_strdup(dst_addr));
123125
}
124126
} else {
125127
if (next_hdr == IPPROTO_TCP || next_hdr == IPPROTO_UDP) {
126128
NET_INFO("%s %s (%zd) [%s]:%u -> [%s]:%u",
127-
"IPv6", proto, len, src_addr, src_port,
128-
dst_addr, dst_port);
129+
"IPv6", proto, len,
130+
log_strdup(src_addr), src_port,
131+
log_strdup(dst_addr), dst_port);
129132
} else {
130133
NET_INFO("%s %s (%zd) %s -> %s", "IPv6", proto,
131-
len, src_addr, dst_addr);
134+
len, log_strdup(src_addr),
135+
log_strdup(dst_addr));
132136
}
133137
}
134138
}

samples/net/rpl_border_router/src/http.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1798,7 +1798,8 @@ static void mgmt_cb(struct net_mgmt_event_callback *cb,
17981798
return;
17991799
}
18001800

1801-
NET_DBG("NBR add %s", net_sprint_ipv6_addr(&nbr_info->addr));
1801+
NET_DBG("NBR add %s",
1802+
log_strdup(net_sprint_ipv6_addr(&nbr_info->addr)));
18021803

18031804
ret = send_ipv6_neighbors(&http_ctx, ws_dst, nbr);
18041805
if (ret < 0) {
@@ -1812,7 +1813,8 @@ static void mgmt_cb(struct net_mgmt_event_callback *cb,
18121813
return;
18131814
}
18141815

1815-
NET_DBG("NBR del %s", net_sprint_ipv6_addr(&nbr_info->addr));
1816+
NET_DBG("NBR del %s",
1817+
log_strdup(net_sprint_ipv6_addr(&nbr_info->addr)));
18161818

18171819
ret = send_ipv6_neighbor_deletion(&http_ctx, ws_dst, iface,
18181820
&nbr_info->addr);
@@ -1834,11 +1836,12 @@ static void mgmt_cb(struct net_mgmt_event_callback *cb,
18341836
}
18351837

18361838
NET_DBG("ROUTE add addr %s/%d",
1837-
net_sprint_ipv6_addr(&route_info->addr),
1839+
log_strdup(net_sprint_ipv6_addr(&route_info->addr)),
18381840
route_info->prefix_len);
18391841
{
18401842
NET_DBG("ROUTE add nexthop %s",
1841-
net_sprint_ipv6_addr(&route_info->nexthop));
1843+
log_strdup(net_sprint_ipv6_addr(
1844+
&route_info->nexthop)));
18421845

18431846
}
18441847

@@ -1858,13 +1861,11 @@ static void mgmt_cb(struct net_mgmt_event_callback *cb,
18581861
}
18591862

18601863
NET_DBG("ROUTE del addr %s/%d",
1861-
net_sprint_ipv6_addr(&route_info->addr),
1864+
log_strdup(net_sprint_ipv6_addr(&route_info->addr)),
18621865
route_info->prefix_len);
1863-
{
1864-
NET_DBG("ROUTE del nexthop %s",
1865-
net_sprint_ipv6_addr(&route_info->nexthop));
1866-
1867-
}
1866+
NET_DBG("ROUTE del nexthop %s",
1867+
log_strdup(net_sprint_ipv6_addr(
1868+
&route_info->nexthop)));
18681869

18691870
ret = send_ipv6_route_deletion(&http_ctx, ws_dst, iface,
18701871
route_info);

samples/net/rpl_border_router/src/rpl.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ static bool br_join_dag(struct net_rpl_dio *dio)
5353

5454
NET_DBG("Other root %s, me %s, "
5555
"DIO version %d instance %d",
56-
other, me,
56+
log_strdup(other), log_strdup(me),
5757
dio->version, dio->instance_id);
5858
}
5959
}
@@ -84,12 +84,12 @@ bool setup_rpl(struct net_if *iface, const char *addr_prefix)
8484
}
8585

8686
if (rpl.prefix_len == 0) {
87-
NET_ERR("Invalid prefix length %s", slash + 1);
87+
NET_ERR("Invalid prefix length %s", log_strdup(slash + 1));
8888
return false;
8989
}
9090

9191
if (net_addr_pton(AF_INET6, prefix, &rpl.prefix) < 0) {
92-
NET_ERR("Invalid IPv6 prefix %s", prefix);
92+
NET_ERR("Invalid IPv6 prefix %s", log_strdup(prefix));
9393
return false;
9494
}
9595

@@ -114,7 +114,8 @@ bool setup_rpl(struct net_if *iface, const char *addr_prefix)
114114

115115
ret = net_rpl_set_prefix(iface, dag, &rpl.prefix, rpl.prefix_len);
116116
if (!ret) {
117-
NET_ERR("Cannot set prefix %s/%d", prefix, rpl.prefix_len);
117+
NET_ERR("Cannot set prefix %s/%d", log_strdup(prefix),
118+
rpl.prefix_len);
118119
return false;
119120
}
120121

@@ -125,10 +126,11 @@ bool setup_rpl(struct net_if *iface, const char *addr_prefix)
125126
NET_IPV6_ADDR_LEN)) {
126127
if (rpl.dag_has_version) {
127128
NET_DBG("New RPL dag %s/%d version %u created",
128-
out, rpl.prefix_len,
129+
log_strdup(out), rpl.prefix_len,
129130
rpl.dag_init_version);
130131
} else {
131-
NET_DBG("New RPL dag %s/%d created", out,
132+
NET_DBG("New RPL dag %s/%d created",
133+
log_strdup(out),
132134
rpl.prefix_len);
133135
}
134136
}

samples/net/rpl_node/src/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ static int append_rpl_parent(struct coap_packet *response)
236236
parent = net_rpl_get_parent_addr(net_pkt_iface(response->pkt),
237237
rpl->current_dag->preferred_parent);
238238
pos = snprintk(&out[out_len], sizeof(out), "%s",
239-
net_sprint_ipv6_addr(parent));
239+
log_strdup(net_sprint_ipv6_addr(parent)));
240240
out_len += pos;
241241
}
242242

0 commit comments

Comments
 (0)