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]
Date:   Tue,  5 Sep 2017 02:24:31 +0200
From:   Daniel Borkmann <daniel@...earbox.net>
To:     stephen@...workplumber.org
Cc:     ast@...com, netdev@...r.kernel.org,
        Daniel Borkmann <daniel@...earbox.net>
Subject: [PATCH iproute2 master 1/2] bpf: minor cleanups for bpf_trace_pipe

Just minor nits, e.g. no need to fflush() and instead of returning
right away, just break and close the fd.

Signed-off-by: Daniel Borkmann <daniel@...earbox.net>
---
 lib/bpf.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/lib/bpf.c b/lib/bpf.c
index 5fd4928..7463fdc 100644
--- a/lib/bpf.c
+++ b/lib/bpf.c
@@ -569,9 +569,9 @@ int bpf_trace_pipe(void)
 		"/trace",
 		0,
 	};
+	int fd_in, fd_out = STDERR_FILENO;
 	char tpipe[PATH_MAX];
 	const char *mnt;
-	int fd;
 
 	mnt = bpf_find_mntpt("tracefs", TRACEFS_MAGIC, tracefs_mnt,
 			     sizeof(tracefs_mnt), tracefs_known_mnts);
@@ -582,8 +582,8 @@ int bpf_trace_pipe(void)
 
 	snprintf(tpipe, sizeof(tpipe), "%s/trace_pipe", mnt);
 
-	fd = open(tpipe, O_RDONLY);
-	if (fd < 0)
+	fd_in = open(tpipe, O_RDONLY);
+	if (fd_in < 0)
 		return -1;
 
 	fprintf(stderr, "Running! Hang up with ^C!\n\n");
@@ -591,15 +591,14 @@ int bpf_trace_pipe(void)
 		static char buff[4096];
 		ssize_t ret;
 
-		ret = read(fd, buff, sizeof(buff) - 1);
-		if (ret > 0) {
-			if (write(STDERR_FILENO, buff, ret) != ret)
-				return -1;
-			fflush(stderr);
-		}
+		ret = read(fd_in, buff, sizeof(buff));
+		if (ret > 0 && write(fd_out, buff, ret) == ret)
+			continue;
+		break;
 	}
 
-	return 0;
+	close(fd_in);
+	return -1;
 }
 
 static int bpf_gen_global(const char *bpf_sub_dir)
-- 
1.9.3

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ