This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] fix null pointer in mtrace


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]