Skip to content

Commit

Permalink
CA-277346: Fix flawed parsing of /proc/<pid>/cmdline, split on NUL
Browse files Browse the repository at this point in the history
Signed-off-by: Mark Syms <mark.syms@citrix.com>
Reviewed-by: Stefano Panella <stefano.panella@citrix.com>
  • Loading branch information
MarkSymsCtx committed Mar 19, 2018
1 parent 4c0695d commit ba6a96f
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions drivers/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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:
Expand Down

0 comments on commit ba6a96f

Please sign in to comment.