Repository navigation
Commit 191b277
committed
ffi: No interior NULs (part 1)
Interior NULs is a security hazard for C-style strings. A NUL byte
truncates a string which can lead the caller and callee to see two
different strings. It can cause path traversal attacks where a path in
Python looks complete but it is interpreted differently through FFI.
RustPython needs to handle this for some of its C-API as well as raw
libc or Windows calls. Both Rust's standard library as well as Rustix
handle interior NULs for us with CStrings, so this mostly affects
a handful of Windows functions or areas where we have raw bytes that
weren't checked by CString.
Finally, this PR is non-exhaustive. I will have to rely heavily on
CodeRabbit to help lint it to ensure that interior NUL checks are only
introduced for FFI and not outside of it. Most of RustPython seems to
handle interior NULs already due to CString as well as WideCString.
**Sources:**
* https://owasp.org/www-community/attacks/Embedding_Null_Code
* python/cpython#116561 parent 81df1ff commit 191b277
20 files changed
Lines changed: 475 additions & 520 deletions
File tree
- crates
- host_env/src
- stdlib/src
- vm/src
- stdlib
- _ctypes
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
37 | | - | |
| 36 | + | |
38 | 37 | | |
39 | 38 | | |
40 | 39 | | |
| |||
1091 | 1090 | | |
1092 | 1091 | | |
1093 | 1092 | | |
| 1093 | + | |
| 1094 | + | |
| 1095 | + | |
1094 | 1096 | | |
1095 | | - | |
1096 | | - | |
1097 | | - | |
| 1097 | + | |
| 1098 | + | |
| 1099 | + | |
| 1100 | + | |
| 1101 | + | |
1098 | 1102 | | |
1099 | 1103 | | |
1100 | 1104 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
21 | 20 | | |
22 | 21 | | |
23 | 22 | | |
| 23 | + | |
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| |||
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
85 | 79 | | |
86 | 80 | | |
87 | 81 | | |
| |||
288 | 282 | | |
289 | 283 | | |
290 | 284 | | |
291 | | - | |
| 285 | + | |
292 | 286 | | |
293 | 287 | | |
294 | 288 | | |
| |||
329 | 323 | | |
330 | 324 | | |
331 | 325 | | |
332 | | - | |
333 | 326 | | |
334 | 327 | | |
335 | 328 | | |
| |||
0 commit comments