Commit 57a8db77 authored by Jukka Rissanen's avatar Jukka Rissanen
Browse files

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: default avatarJukka Rissanen <jukka.rissanen@linux.intel.com>
parent d67414e9
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -494,7 +494,7 @@ static int query_get(struct coap_resource *resource,
		memcpy(str, options[i].value, options[i].len);
		str[options[i].len] = '\0';

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

	NET_INFO("*******\n");
+7 −6
Original line number Diff line number Diff line
@@ -41,18 +41,19 @@ static void handler(struct net_mgmt_event_callback *cb,
		}

		NET_INFO("Your address: %s",
			 net_addr_ntop(AF_INET,
			 log_strdup(net_addr_ntop(AF_INET,
			    &iface->config.ip.ipv4->unicast[i].address.in_addr,
				       buf, sizeof(buf)));
						  buf, sizeof(buf))));
		NET_INFO("Lease time: %u seconds",
			 iface->config.dhcpv4.lease_time);
		NET_INFO("Subnet: %s",
			 net_addr_ntop(AF_INET,
			 log_strdup(net_addr_ntop(AF_INET,
				       &iface->config.ip.ipv4->netmask,
				       buf, sizeof(buf)));
				       buf, sizeof(buf))));
		NET_INFO("Router: %s",
			 net_addr_ntop(AF_INET, &iface->config.ip.ipv4->gw,
				       buf, sizeof(buf)));
			 log_strdup(net_addr_ntop(AF_INET,
						  &iface->config.ip.ipv4->gw,
						  buf, sizeof(buf))));
	}
}

+19 −14
Original line number Diff line number Diff line
@@ -83,9 +83,10 @@ void dns_result_cb(enum dns_resolve_status status,
		return;
	}

	NET_INFO("%s %s address: %s", user_data ? (char *)user_data : "<null>", hr_family,
		 net_addr_ntop(info->ai_family, addr,
			       hr_addr, sizeof(hr_addr)));
	NET_INFO("%s %s address: %s", user_data ? (char *)user_data : "<null>",
		 hr_family,
		 log_strdup(net_addr_ntop(info->ai_family, addr,
					  hr_addr, sizeof(hr_addr))));
}

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

	NET_INFO("%s %s address: %s", user_data ? (char *)user_data : "<null>", hr_family,
		 net_addr_ntop(info->ai_family, addr,
			       hr_addr, sizeof(hr_addr)));
	NET_INFO("%s %s address: %s", user_data ? (char *)user_data : "<null>",
		 hr_family,
		 log_strdup(net_addr_ntop(info->ai_family, addr,
					  hr_addr, sizeof(hr_addr))));
}

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

		NET_INFO("IPv4 address: %s",
			 net_addr_ntop(AF_INET, &if_addr->address.in_addr,
				       hr_addr, NET_IPV4_ADDR_LEN));
			 log_strdup(net_addr_ntop(AF_INET,
					       &if_addr->address.in_addr,
					       hr_addr, NET_IPV4_ADDR_LEN)));
		NET_INFO("Lease time: %u seconds",
			 iface->config.dhcpv4.lease_time);
		NET_INFO("Subnet: %s",
			 net_addr_ntop(AF_INET,
			 log_strdup(net_addr_ntop(AF_INET,
					       &iface->config.ip.ipv4->netmask,
				       hr_addr, NET_IPV4_ADDR_LEN));
					       hr_addr, NET_IPV4_ADDR_LEN)));
		NET_INFO("Router: %s",
			 net_addr_ntop(AF_INET, &iface->config.ip.ipv4->gw,
				       hr_addr, NET_IPV4_ADDR_LEN));
			 log_strdup(net_addr_ntop(AF_INET,
					       &iface->config.ip.ipv4->gw,
					       hr_addr, NET_IPV4_ADDR_LEN)));
		break;
	}

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

	NET_INFO("IPv4 address: %s",
		 net_addr_ntop(AF_INET, &addr, hr_addr, NET_IPV4_ADDR_LEN));
		 log_strdup(net_addr_ntop(AF_INET, &addr, hr_addr,
					  NET_IPV4_ADDR_LEN)));

	ret = dns_get_addr_info(query,
				DNS_QUERY_TYPE_A,
+2 −2
Original line number Diff line number Diff line
@@ -135,8 +135,8 @@ static void gptp_phase_dis_cb(u8_t *gm_identity,
		memcpy(id, gm_identity, sizeof(id));

		NET_DBG("GM %s last phase %d.%lld",
			gptp_sprint_clock_id(gm_identity, output,
					     sizeof(output)),
			log_strdup(gptp_sprint_clock_id(gm_identity, output,
							sizeof(output))),
			last_gm_ph_change->high,
			last_gm_ph_change->low);
	}
+3 −3
Original line number Diff line number Diff line
@@ -46,9 +46,9 @@ static void handler(struct net_mgmt_event_callback *cb,
		}

		NET_INFO("Your address: %s",
			 net_addr_ntop(AF_INET,
			 log_strdup(net_addr_ntop(AF_INET,
				    &cfg->ip.ipv4->unicast[i].address.in_addr,
				     buf, sizeof(buf)));
				    buf, sizeof(buf))));
	}
}

Loading