Commit 858b05c
Fix TSA #2816217: suppress Flawfinder false positive on Cython JoinPyUnicode memcpy (#2029)
* Fix TSA #2816217: suppress Flawfinder false positive on Cython JoinPyUnicode memcpy
Flawfinder's buffer/memcpy rule (CWE-120) fires on any memcpy() call by
default. The flagged call sits inside the Cython 3.x string-join helper
__Pyx_PyUnicode_Join:
memcpy((char *)result_udata + (char_pos << kind_shift),
udata,
(size_t) (ulength << kind_shift));
It is provably safe:
* result_uval was just allocated via PyUnicode_New(result_ulength, max_char)
and result_udata = PyUnicode_DATA(result_uval) points into that buffer.
* The immediately preceding check
(PY_SSIZE_T_MAX >> kind_shift) - ulength < char_pos
guards against char_pos+ulength overflow before the memcpy executes.
* result_ulength is computed by the caller as the sum of input lengths,
so char_pos + ulength <= result_ulength after each iteration. The byte
count `ulength << kind_shift` is bounded by the allocated buffer.
Add an inline /* Flawfinder: ignore */ annotation on the flagged line in
the Cython-generated _pydevd_sys_monitoring_cython.c and extend the
existing post-processing block in setup_pydevd_cython.py so the annotation
is re-applied automatically whenever Cython regenerates the .c files.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* Fix SyntaxError: add missing closing paren on JoinPyUnicode .replace() call
The merge from main inadvertently dropped the closing ')' of the new
JoinPyUnicode '.replace(...)' call, so the subsequent 'read<end'
'.replace(...)' block was being parsed as continued arguments. Add the
missing ')' (and a blank line) to separate the two calls cleanly.
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent f0c34f1 commit 858b05c
2 files changed
Lines changed: 12 additions & 1 deletion
File tree
- src/debugpy/_vendored/pydevd
- _pydevd_sys_monitoring
Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
177 | 177 | | |
178 | 178 | | |
179 | 179 | | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
180 | 191 | | |
181 | 192 | | |
182 | 193 | | |
| |||
0 commit comments