From: Masatake YAMATO Date: Wed, 26 Oct 2022 02:56:00 +0000 (+0900) Subject: lsfd: make the logic for verifying the initial line of /proc/net/{tcp,udp} more flexible X-Git-Tag: v2.39-rc1~448^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b49529f06f282b5c5e1e6da5c776f103d0db1d13;p=thirdparty%2Futil-linux.git lsfd: make the logic for verifying the initial line of /proc/net/{tcp,udp} more flexible The format of /proc/net/udp was changed in 6c25449e1a32 ("net: udp: fix alignment problem in udp4_seq_show()"). This kind of change can be applied to /proc/net/tcp, too. Co-Authored-by: Thomas Weißschuh Co-Authored-by: Masatake YAMATO --- diff --git a/misc-utils/lsfd-sock-xinfo.c b/misc-utils/lsfd-sock-xinfo.c index 1ef2f40b7c..263ffc36e9 100644 --- a/misc-utils/lsfd-sock-xinfo.c +++ b/misc-utils/lsfd-sock-xinfo.c @@ -654,10 +654,19 @@ static void load_xinfo_from_proc_inet_L3(ino_t netns_inode, const char *proc_fil static bool tcp_verify_initial_line(const char *line) { - return (line[0] == ' ' && line[1] == ' ' - && line[2] == 's' && line[3] == 'l'); + /* At least we expect two white spaces. */ + if (strncmp (line, " ", 2) != 0) + return false; + line += 2; + + /* Skip white spaces. */ + while (*line == ' ') + line++; + + return (strncmp(line, "sl", 2) == 0); } + static void load_xinfo_from_proc_tcp(ino_t netns_inode) { load_xinfo_from_proc_inet_L3(netns_inode, @@ -711,17 +720,10 @@ static struct sock_xinfo_class udp_xinfo_class = { .free = NULL, }; -static bool udp_verify_initial_line(const char *line) -{ - return (line[0] == ' ' && line[1] == ' ' && line[2] == ' ' - && line[3] == 's' && line[4] == 'l'); -} - - static void load_xinfo_from_proc_udp(ino_t netns_inode) { load_xinfo_from_proc_inet_L3(netns_inode, "/proc/net/udp", - udp_verify_initial_line, + tcp_verify_initial_line, &udp_xinfo_class); }