Skip to content

StackBufferOverflow: a callee's write past the end of its caller's stack array is not reported #266

Closed

Description

@SizzleUnrlsd

StackBufferOverflow does not report a write that a callee makes through a pointer past the end of its caller's stack array.

Two separate changes affect the example below. Do not confuse them:

Passing &buf[8] directly as the argument has never been reported, before #264 or after.

Example

callee-write.c:

void leaf(char* p) { *p = 42; }

void bridge(char* p)
{
    char* q = p;
    leaf(q);
}

void caller(void)
{
    char buf[8] = {0};
    char* p = &buf[8];
    bridge(p);
}

Before and after

Version Diagnostic
c59f696, before #264 One warning, on line 12 (char* p = &buf[8];). It is misplaced: no write happens there.
276a0d6, head of #264 None
f79fcce, head of #265 None

Output on c59f696:

$ stack_usage_analyzer callee-write.c --warnings-only
Function: caller
	at line 12, column 11
	[ !!Warn ] potential stack buffer overflow on variable 'buf' (size 8)
		 ↳ alias path: buf
		 ↳ constant index 8 is out of bounds (0..7)
		 ↳ (this is a write access)

On f79fcce, the result is also empty with --smt=on, and when the three functions are in three files analyzed together.

Expected

The report should be on the write in leaf, and should name buf and the call that passes it: leaf writes 1 byte at offset 8 of buf, which holds 8 bytes. The line that forms the address should not be reported.

Each case must give the same result whether its functions are in one file or in several:

Case Expected
buf + 8 passed to the callee, never dereferenced no report
1-byte write through buf + 7 no report
1-byte write through buf + 8 overflow
the same write after several pointer copies and calls overflow
the pointer reassigned to a large enough object before the call no report
the write behind a guard in the callee that excludes the overflow no report

Related

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions