From ba6a96f02c8a867e0baaa10c4174fd073dccda25 Mon Sep 17 00:00:00 2001 From: Mark Syms Date: Mon, 19 Mar 2018 15:10:53 +0000 Subject: [PATCH] CA-277346: Fix flawed parsing of /proc//cmdline, split on NUL Signed-off-by: Mark Syms Reviewed-by: Stefano Panella --- drivers/util.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/util.py b/drivers/util.py index 523639ccf..c69fe48f3 100755 --- a/drivers/util.py +++ b/drivers/util.py @@ -1262,6 +1262,9 @@ def findRunningProcessOrOpenFile(name, process = True): f = None f = open(os.path.join('/proc', pid, 'cmdline'), 'rb') prog = f.read()[:-1] + if prog: + # Just want the process name + prog = prog[:prog.find('\x00')] except IOError, e: if e.errno in (errno.ENOENT, errno.ESRCH): SMlog("ERROR %s reading %s, ignore" % (e.errno, pid)) @@ -1286,9 +1289,10 @@ def findRunningProcessOrOpenFile(name, process = True): link = os.readlink(os.path.join(fd_dir, file)) except OSError: continue - - if process and name == prog: - links.append(link) + + if process: + if name == prog: + links.append(link) else: # need to return process name and pid tuples if link == name: