Skip to content

Commit 8156dc2

Browse files
redsun82Copilot
andcommitted
CWE-770: correct GlobalAlloc sink MISSING comment
The prior comment claimed the blanket impl methods have no canonical path. They now do (`<_ as ..::GlobalAlloc>::alloc`); the accurate reason is the type-parameter `Self`, so the path-keyed sink model misses them. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 890cb55d-0437-4bd7-9268-87b8897ada01
1 parent 5b67e28 commit 8156dc2

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

  • rust/ql/test/query-tests/security/CWE-770

rust/ql/test/query-tests/security/CWE-770/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,8 @@ unsafe fn test_system_alloc(v: usize) {
190190
let _ = std::alloc::Global.allocate_zeroed(l1).unwrap();
191191

192192
let l2 = std::alloc::Layout::array::<u8>(v).unwrap();
193-
// `GlobalAlloc` is a legacy trait, blanket-implemented for `GlobalAllocator` types, so these
194-
// resolve to the blanket impl whose methods have no canonical path; the sink models miss them.
193+
// These resolve to the blanket `impl GlobalAlloc for A` in `core`, so the target's canonical
194+
// path has a type-parameter `Self` (`<_ as ..::GlobalAlloc>::alloc`); the sink model misses it.
195195
let _ = std::alloc::System.alloc(l2); // $ MISSING: Alert[rust/uncontrolled-allocation-size]=arg1
196196
let _ = std::alloc::System.alloc_zeroed(l2); // $ MISSING: Alert[rust/uncontrolled-allocation-size]=arg1
197197
let _ = std::alloc::System.allocate(l2).unwrap(); // $ Alert[rust/uncontrolled-allocation-size]=arg1
@@ -201,7 +201,7 @@ unsafe fn test_system_alloc(v: usize) {
201201

202202
let l3 = std::alloc::Layout::array::<u8>(10).unwrap();
203203
let m3 = std::alloc::System.alloc(l3);
204-
// `System.realloc` resolves to that same `GlobalAlloc` blanket impl (see above); MISSING.
204+
// `System.realloc` resolves to that same blanket `GlobalAlloc` impl (see above); MISSING.
205205
let _ = std::alloc::System.realloc(m3, l3, v); // $ MISSING: Alert[rust/uncontrolled-allocation-size]=arg1
206206

207207
let l4 = std::alloc::Layout::array::<u8>(10).unwrap();

0 commit comments

Comments
 (0)