Debian Codegraph @

debian/patches/prevent-path-traversal-in-wince.patch

raw
1 Description: Prevent path traversal in WinCE extraction plugin
2 The WinCE extraction plugin trusted filenames supplied by the input
3 image and used them directly to construct output paths. A crafted
4 WinCE image could therefore cause files to be written outside the
5 extraction directory.
6 .
7 Resolve the extraction paths and ensure they remain below the
8 extraction directory before writing files.
9 .
10 CVE-2026-7179
11 Bug-Debian: https://bugs.debian.org/1136010
12 Forwarded: not-needed
13 Author: Fukui Daichi <[email protected]>
14 Reviewed-by: Sven Geuer <[email protected]>
15 Last-Update: 2026-08-26
16 --- a/src/binwalk/plugins/winceextract.py
17 +++ b/src/binwalk/plugins/winceextract.py
18 @@ -1,4 +1,5 @@
19 import binwalk.core.plugin
20 +from binwalk.core.common import warning
21 import re
22 import os
23
24 @@ -38,1 +38,11 @@
25 - def extractor(self, fname):
26 + def _safe_output_path(self, indir, filename):
27 + indir = os.path.realpath(indir)
28 + output_path = os.path.realpath(os.path.join(indir, filename))
29 +
30 + if os.path.commonpath([indir, output_path]) != indir:
31 + warning("Path traversal blocked: %s" % filename)
32 + return None
33 +
34 + return output_path
35 +
36 + def extractor(self, fname):
37 @@ -52,8 +62,14 @@
38 with open(infile, 'r+b') as f:
39 with WinCEExtractor(f, 0) as extractor:
40 for module in extractor.modules:
41 - with open(os.path.join(indir, module.file_name), 'w+b') as module_file:
42 + output_path = self._safe_output_path(indir, module.file_name)
43 + if output_path is None:
44 + continue
45 + with open(output_path, 'w+b') as module_file:
46 module.write_to(module_file)
47 for file_e in extractor.files:
48 - with open(os.path.join(indir, file_e.file_name), 'w+b') as file_file:
49 + output_path = self._safe_output_path(indir, file_e.file_name)
50 + if output_path is None:
51 + continue
52 + with open(output_path, 'w+b') as file_file:
53 file_e.write_to(file_file)