ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
Bug (v4.099): possible buffer overflow in get_string() |
Posted: Thu Nov 05, 2009 7:40 pm |
|
|
For your info: A bug report on input.c I just filed.
Compiler: PCWH v4.099demo
Processor: all
The function get_string() in input.c has a few problems:
1) Information is missing on how to use it. Most importantly it should mention the 'max' parameter is including the terminating zero.
2) Even when the 'max' parameter does include the terminating zero it is possible to create a buffer overflow. The line:
should have '<' instead of '<='.
Note: this error is not present in the almost identical function bget_string from ex_zmd.c
3) A 'max' parameter 0 is not rejected and will effectively disable length checking, leading to possible memory corruption.
4) Code: | signed int16 get_int() {
char s[5]; <<-- should be equal to get_string (7)
...
get_string(s, 7); |
5) Code: | signed int32 get_long() {
char s[7]; <<-- should be equal to get_string (10)
...
get_string(s, 10); |
|
|