aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenis Kirjanov <kirjanov@gmail.com>2024-02-28 08:58:58 -0500
committerDavid Ahern <dsahern@kernel.org>2024-03-03 22:32:50 +0000
commitb69e1e0445ab3cf2a90738317507a29a483c26b3 (patch)
tree062743f0871e38f3d9310a8df04f80c1b0dae264
parent2f8b36e146a555fd6a96590bf191ac634e3b350b (diff)
downloadiproute2-b69e1e0445ab3cf2a90738317507a29a483c26b3.tar.gz
nstat: convert sprintf to snprintf
Use snprintf to print only valid data. That's the similar change done for ifstat. Signed-off-by: Denis Kirjanov <dkirjanov@suse.de> Signed-off-by: David Ahern <dsahern@kernel.org>
-rw-r--r--misc/nstat.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/misc/nstat.c b/misc/nstat.c
index ea96ccb03..7beb620b2 100644
--- a/misc/nstat.c
+++ b/misc/nstat.c
@@ -483,7 +483,7 @@ static void server_loop(int fd)
p.fd = fd;
p.events = p.revents = POLLIN;
- sprintf(info_source, "%d.%lu sampling_interval=%d time_const=%d",
+ snprintf(info_source, sizeof(info_source), "%d.%lu sampling_interval=%d time_const=%d",
getpid(), (unsigned long)random(), scan_interval/1000, time_constant/1000);
load_netstat();
@@ -636,7 +636,7 @@ int main(int argc, char *argv[])
sun.sun_family = AF_UNIX;
sun.sun_path[0] = 0;
- sprintf(sun.sun_path+1, "nstat%d", getuid());
+ snprintf(sun.sun_path + 1, sizeof(sun.sun_path) - 1, "nstat%d", getuid());
if (scan_interval > 0) {
if (time_constant == 0)