Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/netstat netstat/bpf.c: Don't print garbage for stale...



details:   https://anonhg.NetBSD.org/src/rev/4c2860e5cbe9
branches:  trunk
changeset: 372372:4c2860e5cbe9
user:      yamt <yamt%NetBSD.org@localhost>
date:      Sat Nov 19 08:56:20 2022 +0000

description:
netstat/bpf.c: Don't print garbage for stale pid

diffstat:

 usr.bin/netstat/bpf.c |  9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)

diffs (24 lines):

diff -r 79d4b0f0a219 -r 4c2860e5cbe9 usr.bin/netstat/bpf.c
--- a/usr.bin/netstat/bpf.c     Sat Nov 19 08:53:06 2022 +0000
+++ b/usr.bin/netstat/bpf.c     Sat Nov 19 08:56:20 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bpf.c,v 1.16 2022/09/01 10:10:20 msaitoh Exp $ */
+/*     $NetBSD: bpf.c,v 1.17 2022/11/19 08:56:20 yamt Exp $    */
 
 /*
  * Copyright (c) 2005 The NetBSD Foundation, Inc.
@@ -162,8 +162,13 @@
                        name[namelen++] = szproc;
                        name[namelen++] = 1;
 
+                       /*
+                        * Note: The sysctl succeeds (returns 0) even if it failed
+                        * to find the process. The szproc check below is to detect
+                        * that case.
+                        */
                        if (prog_sysctl(&name[0], namelen, &p, &szproc,
-                           NULL, 0) == -1)
+                           NULL, 0) == -1 || szproc != sizeof(p))
                                printf("-\n");
                        else
                                printf("%s\n", p.p_comm);



Home | Main Index | Thread Index | Old Index