[PATCH] fix null pointer in mtrace
liqingqing
liqingqing3@huawei.com
Tue Nov 12 09:40:00 GMT 2019
On 2019/11/12 17:22, Liusirui wrote:
> In a multi-threaded program, some threads request or free memory and try to write trace info
> into file which "mallstream" points to. At the same time, another thread calls "muntrace" and
> set "mallstream" to NULL. This may cause a segmentation fault.
>
> The comment in malloc/mtrace.c says "We could be printing a NULL here; that's OK.". Although
> the functions mtrace/muntrace are used for debugging, program isn't expected to crash while using
> these functions.
>
> ---
> malloc/mtrace.c | 29 ++++++++++++++++-------------
> 1 file changed, 16 insertions(+), 13 deletions(-)
>
> diff --git a/malloc/mtrace.c b/malloc/mtrace.c
> index 707f998..33f01b4 100644
> --- a/malloc/mtrace.c
> +++ b/malloc/mtrace.c
> @@ -44,6 +44,10 @@
>
> #define TRACE_BUFFER_SIZE 512
>
> +#define mtrace_print(file, format, ...) do { \
> +if (file != NULL) mtrace_print(file, format,##__VA_ARGS__); \
> +} while(0)
> +
I had tested this scenario, it seems like that the fprintf and other file operation function do not check the invalid argument like the null pointer.
does any one knows why fprintf do not check the input? thanks
More information about the Libc-alpha
mailing list