diff mbox series

[iproute2,3/3] nstat: convert sprintf to snprintf

Message ID 20240228135858.3258-3-dkirjanov@suse.de (mailing list archive)
State Accepted
Commit b69e1e0445ab3cf2a90738317507a29a483c26b3
Delegated to: David Ahern
Headers show
Series [iproute2,1/3] nstat: constify name argument in generic_proc_open | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch

Commit Message

Denis Kirjanov Feb. 28, 2024, 1:58 p.m. UTC
Use snprintf to print only valid data.
That's the similar change done for ifstat.

Signed-off-by: Denis Kirjanov <dkirjanov@suse.de>
---
 misc/nstat.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/misc/nstat.c b/misc/nstat.c
index ea96ccb0..7beb620b 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)