lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240228135858.3258-2-dkirjanov@suse.de>
Date: Wed, 28 Feb 2024 08:58:57 -0500
From: Denis Kirjanov <kirjanov@...il.com>
To: stephen@...workplumber.org
Cc: netdev@...r.kernel.org,
	Denis Kirjanov <dkirjanov@...e.de>
Subject: [PATCH iproute2 2/3] nstat: use stack space for history file name

as the name doesn't require a lot of storage put
it on the stack. Moreover the memory allocated via
malloc wasn't returned.

Signed-off-by: Denis Kirjanov <dkirjanov@...e.de>
---
 misc/nstat.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/misc/nstat.c b/misc/nstat.c
index 3a58885d..ea96ccb0 100644
--- a/misc/nstat.c
+++ b/misc/nstat.c
@@ -580,7 +580,7 @@ static const struct option longopts[] = {
 
 int main(int argc, char *argv[])
 {
-	char *hist_name;
+	char hist_name[128];
 	struct sockaddr_un sun;
 	FILE *hist_fp = NULL;
 	int ch;
@@ -668,10 +668,11 @@ int main(int argc, char *argv[])
 	patterns = argv;
 	npatterns = argc;
 
-	if ((hist_name = getenv("NSTAT_HISTORY")) == NULL) {
-		hist_name = malloc(128);
-		sprintf(hist_name, "/tmp/.nstat.u%d", getuid());
-	}
+	if (getenv("NSTAT_HISTORY"))
+		snprintf(hist_name, sizeof(hist_name),
+			 "%s", getenv("NSTAT_HISTORY"));
+	else
+		snprintf(hist_name, sizeof(hist_name), "/tmp/.nstat.u%d", getuid());
 
 	if (reset_history)
 		unlink(hist_name);
-- 
2.30.2


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ