Skip to content

Commit 730ba5b

Browse files
committed
Add --memory option
1 parent 51a5838 commit 730ba5b

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

doc/vulnix.1.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ should not be reported.
3131
Scans the current system defined as transitive closure of
3232
_/run/current-system_.
3333

34+
* `-M`, `--memory`:
35+
Scans currently-running processes.
36+
3437
* `-G`, `--gc-roots`:
3538
Scans all active garbage collection roots. This option is of limited use since
3639
the scan will include all old system generations.

src/vulnix/main.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,12 @@ def init_logging(verbose):
5050
logging.basicConfig(level=logging.WARNING)
5151

5252

53-
def populate_store(store, gc_roots, paths, requisites=True):
53+
def populate_store(store, gc_roots, memory, paths, requisites=True):
5454
"""Load derivations from nix store depending on cmdline invocation."""
5555
if gc_roots:
5656
store.add_gc_roots()
57+
if memory:
58+
store.add_memory_roots()
5759
for path in paths:
5860
store.add_path(path)
5961
return store
@@ -74,6 +76,8 @@ def run(nvd, store):
7476
# what to scan
7577
@click.option('-S', '--system', is_flag=True,
7678
help='Scan the current system.')
79+
@click.option('-M', '--memory', is_flag=True,
80+
help='Scan currently-running process.')
7781
@click.option('-G', '--gc-roots', is_flag=True,
7882
help='Scan all active GC roots (including old ones).')
7983
@click.option('-f', '--from-file', type=click.File(mode='r'),
@@ -108,14 +112,14 @@ def run(nvd, store):
108112
help='(obsolete; kept for compatibility reasons)')
109113
@click.option('-F', '--notfixed', is_flag=True,
110114
help='(obsolete; kept for compatibility reasons)')
111-
def main(verbose, gc_roots, system, from_file, path, mirror, cache_dir,
115+
def main(verbose, gc_roots, memory, system, from_file, path, mirror, cache_dir,
112116
requisites, whitelist, write_whitelist, version, json,
113117
show_whitelisted, default_whitelist, notfixed):
114118
if version:
115119
print('vulnix ' + pkg_resources.get_distribution('vulnix').version)
116120
sys.exit(0)
117121

118-
if not (gc_roots or system or path or from_file):
122+
if not (gc_roots or memory or system or path or from_file):
119123
howto()
120124
sys.exit(3)
121125

@@ -141,7 +145,7 @@ def main(verbose, gc_roots, system, from_file, path, mirror, cache_dir,
141145
for drv in from_file.readlines():
142146
paths.append(drv.strip())
143147
if paths:
144-
populate_store(store, gc_roots, paths, requisites)
148+
populate_store(store, gc_roots, memory, paths, requisites)
145149
with NVD(mirror, cache_dir) as nvd:
146150
with Timer('Update NVD data'):
147151
nvd.update()

src/vulnix/nix.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ def add_gc_roots(self):
2222
for d in call(['nix-store', '--gc', '--print-live']).splitlines():
2323
self.update(d)
2424

25+
def add_memory_roots(self):
26+
"""Add derivations found in currently-running processes."""
27+
_log.debug('loading derivations from currently-running processes')
28+
for line in call(['nix-store', '--gc', '--print-roots']).splitlines():
29+
source, path = line.split(' -> ', 1)
30+
if (source.startswith('/proc/') or source.startswith('{temp:')
31+
or source == '{lsof}' or source == '{censored}'):
32+
self.add_path(path)
33+
2534
def add_path(self, path):
2635
"""Add the closure of all derivations referenced by a store path."""
2736
if not p.exists(path):

0 commit comments

Comments
 (0)