libmicrohttpd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [libmicrohttpd] Bug in MHD_itc_destroy_(itc) and MHD_fd_close_chk_(f


From: Christian Grothoff
Subject: Re: [libmicrohttpd] Bug in MHD_itc_destroy_(itc) and MHD_fd_close_chk_(fd)
Date: Mon, 8 Apr 2019 15:54:13 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1

Hi Michael,

You are right, I've pushed your proposed fix to Git master now.

Best,

Christian

On 4/8/19 2:01 PM, Michael Kaufmann wrote:
> Hi,
> 
> after updating from libmicrohttpd 0.9.59 to 0.9.63, I get these core dumps:
> 
> #0  0x00007f7c281c6207 in raise () from /lib64/libc.so.6
> #1  0x00007f7c281c78f8 in abort () from /lib64/libc.so.6
> #2  0x00007f7c298dbacf in mhd_panic_std (cls=<optimized out>,
> file=<optimized out>, line=<optimized out>, reason=<optimized out>) at
> daemon.c:149
> #3  0x00007f7c298dfa1a in MHD_stop_daemon (daemon=0x55ec397c61e0) at
> daemon.c:6654
> ...
> 
> I think there is a bug in MHD_itc_destroy_(itc) in the files
> src/microhttpd/mhd_itc.h and src/lib/mhd_itc.h.
> 
> Current code:
> #define MHD_itc_destroy_(itc) ((0 != close ((itc).fd)) || (EBADF != errno))
> 
> So if close() succeeds, it returns 0, and errno is checked in that case.
> If errno happens to be EBADF, mhd_panic_std() is called. errno should
> only be checked if the close() call failed.
> 
> Proposed bugfix:
> #define MHD_itc_destroy_(itc) ((0 == close ((itc).fd)) || (EBADF != errno))
> 
> 
> There is also a bug in MHD_fd_close_chk_(fd), in the files
> src/microhttpd/internal.h and src/lib/internal.h:
> 
> #define MHD_fd_close_chk_(fd) do {             \
>     if (0 == close ((fd)) && (EBADF == errno)) \
>       MHD_PANIC(_("Failed to close FD.\n"));   \
>   } while(0)
> 
> 
> This should be changed to:
> 
> #define MHD_fd_close_chk_(fd) do {             \
>     if (0 != close ((fd)) && (EBADF == errno)) \
>       MHD_PANIC(_("Failed to close FD.\n"));   \
>   } while(0)
> 
> 
> See also https://bugs.gnunet.org/view.php?id=3926
> 
> Regards,
> Michael
> 
> 

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]