View Issue Details

IDProjectCategoryView StatusLast Update
0007971libmicrohttpdbuild systempublic2023-12-02 12:11
Reportermscdex Assigned ToChristian Grothoff  
PriorityhighSeveritymajorReproducibilityalways
Status closedResolutionno change required 
PlatformLinuxOSLinuxOS Version6.2
Fixed in Version0.9.74 
Summary0007971: 0.9.77 MHD_start_daemon() fails with ASan enabled
DescriptionMHD_start_daemon() fails with messages like:

```
Invalid option 1390611539! (Did you terminate the list with MHD_OPTION_END?).
```

with the number given being different every time time the process is launched when ASan is enabled at compile time.
Steps To ReproduceI haven't tested other possible configurations, but I am compiling and linking with libmicrohttpd statically like so (see attached test program):

gcc -o microhttpd-bug -fsanitize=address -Ideps/libmicrohttpd/src/include microhttpd-bug.c deps/libmicrohttpd/src/microhttpd/.libs/libmicrohttpd.a

gcc is 12.3.0.
TagsNo tags attached.
Attached Files
microhttpd-bug.c (1,726 bytes)   
// Compile with: gcc -o microhttpd-bug -fsanitize=address -Ideps/libmicrohttpd/src/include microhttpd-bug.c deps/libmicrohttpd/src/microhttpd/.libs/libmicrohttpd.a
#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include <netinet/ip.h>

#define PORT 5050
#define INACTIVITY_TIMEOUT 15

#include <microhttpd.h>

static enum MHD_Result handle_request(void* cls,
                                      struct MHD_Connection* connection,
                                      const char* url,
                                      const char* method,
                                      const char* version,
                                      const char* upload_data,
                                      size_t* upload_data_size,
                                      void** ptr) {
  return MHD_NO;
}

static void request_completed(void* cls,
                              struct MHD_Connection* connection,
                              void** ptr,
                              enum MHD_RequestTerminationCode toe) {
  *ptr = NULL;
}

int main(int argc, char* argv[]) {
  struct sockaddr_in addr;
  socklen_t addrlen;
  memset(&addr, 0, sizeof(addr));
  addr.sin_family = AF_INET;
  addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
  addr.sin_port = htons(PORT);

  struct MHD_Daemon* d = MHD_start_daemon(
    MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_EPOLL | MHD_USE_ERROR_LOG,
    PORT,
    NULL,
    NULL,
    &handle_request,
    NULL,
    MHD_OPTION_SOCK_ADDR,
    &addr,
    MHD_OPTION_CONNECTION_TIMEOUT,
    INACTIVITY_TIMEOUT,
    MHD_OPTION_NOTIFY_COMPLETED,
    &request_completed,
    MHD_OPTION_END
  );
  if (d == NULL)
    return 1;

  (void)getc(stdin);

  MHD_stop_daemon(d);

  return 0;
}
microhttpd-bug.c (1,726 bytes)   

Activities

mscdex

2023-10-31 01:30

reporter   ~0020616

FWIW the category on this is labeled wrong, it should be the API or something similar instead. I can't seem to change/update it after the fact unfortunately.

mscdex

2023-10-31 02:58

reporter   ~0020617

This can be closed (I can't seem to do that myself either): I was missing the additional (user pointer) argument for the "request closed" callback option.

Christian Grothoff

2023-12-02 12:10

manager   ~0020702

:-)

Christian Grothoff

2023-12-02 12:11

manager   ~0020703

We will make such bugs harder/impossible with the MHD 2.0 API. :-)

Issue History

Date Modified Username Field Change
2023-10-31 00:46 mscdex New Issue
2023-10-31 00:46 mscdex File Added: microhttpd-bug.c
2023-10-31 01:30 mscdex Note Added: 0020616
2023-10-31 02:58 mscdex Note Added: 0020617
2023-12-02 12:10 Christian Grothoff Note Added: 0020702
2023-12-02 12:11 Christian Grothoff Note Added: 0020703
2023-12-02 12:11 Christian Grothoff Assigned To => Christian Grothoff
2023-12-02 12:11 Christian Grothoff Status new => closed
2023-12-02 12:11 Christian Grothoff Resolution open => no change required
2023-12-02 12:11 Christian Grothoff Fixed in Version => 0.9.74