diff options
author | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2022-04-25 15:43:26 +0300 |
---|---|---|
committer | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2022-04-25 16:05:15 +0300 |
commit | 2d367411484fcc96012e7756481e597052f0bcd4 (patch) | |
tree | e1bf7a4119512c81067d4240c73798e2049ccd23 | |
parent | 9c7c06d8b8e8beb7f45107e51ed19c1be816c762 (diff) | |
download | libmicrohttpd-2d367411484fcc96012e7756481e597052f0bcd4.tar.gz libmicrohttpd-2d367411484fcc96012e7756481e597052f0bcd4.zip |
MHD_get_daemon_info(): fixed unaligned memory access
-rw-r--r-- | src/include/microhttpd.h | 5 | ||||
-rw-r--r-- | src/microhttpd/daemon.c | 21 | ||||
-rw-r--r-- | src/microhttpd/internal.h | 28 | ||||
-rw-r--r-- | src/microhttpd/test_upgrade.c | 17 | ||||
-rw-r--r-- | src/microhttpd/test_upgrade_large.c | 17 |
5 files changed, 55 insertions, 33 deletions
diff --git a/src/include/microhttpd.h b/src/include/microhttpd.h index cf8216d0..b4bc85e3 100644 --- a/src/include/microhttpd.h +++ b/src/include/microhttpd.h | |||
@@ -4529,8 +4529,9 @@ union MHD_DaemonInfo | |||
4529 | 4529 | ||
4530 | 4530 | ||
4531 | /** | 4531 | /** |
4532 | * Obtain information about the given daemon | 4532 | * Obtain information about the given daemon. |
4533 | * (not fully implemented!). | 4533 | * The returned pointer is invalidated with the next call of this function or |
4534 | * when the daemon is stopped. | ||
4534 | * | 4535 | * |
4535 | * @param daemon what daemon to get information about | 4536 | * @param daemon what daemon to get information about |
4536 | * @param info_type what information is desired? | 4537 | * @param info_type what information is desired? |
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c index 6cbd9ad5..35708b27 100644 --- a/src/microhttpd/daemon.c +++ b/src/microhttpd/daemon.c | |||
@@ -7813,8 +7813,9 @@ MHD_stop_daemon (struct MHD_Daemon *daemon) | |||
7813 | 7813 | ||
7814 | 7814 | ||
7815 | /** | 7815 | /** |
7816 | * Obtain information about the given daemon | 7816 | * Obtain information about the given daemon. |
7817 | * (not fully implemented!). | 7817 | * The returned pointer is invalidated with the next call of this function or |
7818 | * when the daemon is stopped. | ||
7818 | * | 7819 | * |
7819 | * @param daemon what daemon to get information about | 7820 | * @param daemon what daemon to get information about |
7820 | * @param info_type what information is desired? | 7821 | * @param info_type what information is desired? |
@@ -7837,10 +7838,12 @@ MHD_get_daemon_info (struct MHD_Daemon *daemon, | |||
7837 | case MHD_DAEMON_INFO_MAC_KEY_SIZE: | 7838 | case MHD_DAEMON_INFO_MAC_KEY_SIZE: |
7838 | return NULL; /* no longer supported */ | 7839 | return NULL; /* no longer supported */ |
7839 | case MHD_DAEMON_INFO_LISTEN_FD: | 7840 | case MHD_DAEMON_INFO_LISTEN_FD: |
7840 | return (const union MHD_DaemonInfo *) &daemon->listen_fd; | 7841 | daemon->daemon_info_dummy_listen_fd.listen_fd = daemon->listen_fd; |
7842 | return &daemon->daemon_info_dummy_listen_fd; | ||
7841 | #ifdef EPOLL_SUPPORT | 7843 | #ifdef EPOLL_SUPPORT |
7842 | case MHD_DAEMON_INFO_EPOLL_FD: | 7844 | case MHD_DAEMON_INFO_EPOLL_FD: |
7843 | return (const union MHD_DaemonInfo *) &daemon->epoll_fd; | 7845 | daemon->daemon_info_dummy_epoll_fd.epoll_fd = daemon->epoll_fd; |
7846 | return &daemon->daemon_info_dummy_epoll_fd; | ||
7844 | #endif | 7847 | #endif |
7845 | case MHD_DAEMON_INFO_CURRENT_CONNECTIONS: | 7848 | case MHD_DAEMON_INFO_CURRENT_CONNECTIONS: |
7846 | if (0 == (daemon->options & MHD_USE_INTERNAL_POLLING_THREAD)) | 7849 | if (0 == (daemon->options & MHD_USE_INTERNAL_POLLING_THREAD)) |
@@ -7862,11 +7865,15 @@ MHD_get_daemon_info (struct MHD_Daemon *daemon, | |||
7862 | } | 7865 | } |
7863 | } | 7866 | } |
7864 | #endif | 7867 | #endif |
7865 | return (const union MHD_DaemonInfo *) &daemon->connections; | 7868 | daemon->daemon_info_dummy_num_connections.num_connections |
7869 | = daemon->connections; | ||
7870 | return &daemon->daemon_info_dummy_num_connections; | ||
7866 | case MHD_DAEMON_INFO_FLAGS: | 7871 | case MHD_DAEMON_INFO_FLAGS: |
7867 | return (const union MHD_DaemonInfo *) &daemon->options; | 7872 | daemon->daemon_info_dummy_flags.flags = daemon->options; |
7873 | return &daemon->daemon_info_dummy_flags; | ||
7868 | case MHD_DAEMON_INFO_BIND_PORT: | 7874 | case MHD_DAEMON_INFO_BIND_PORT: |
7869 | return (const union MHD_DaemonInfo *) &daemon->port; | 7875 | daemon->daemon_info_dummy_port.port = daemon->port; |
7876 | return &daemon->daemon_info_dummy_port; | ||
7870 | default: | 7877 | default: |
7871 | return NULL; | 7878 | return NULL; |
7872 | } | 7879 | } |
diff --git a/src/microhttpd/internal.h b/src/microhttpd/internal.h index 094c26ba..fc8ec0c6 100644 --- a/src/microhttpd/internal.h +++ b/src/microhttpd/internal.h | |||
@@ -2164,6 +2164,34 @@ struct MHD_Daemon | |||
2164 | * #MHD_OPTION_ARRAY are counted. | 2164 | * #MHD_OPTION_ARRAY are counted. |
2165 | */ | 2165 | */ |
2166 | size_t num_opts; | 2166 | size_t num_opts; |
2167 | |||
2168 | /* TODO: replace with a single member */ | ||
2169 | /** | ||
2170 | * The value to be returned by #MHD_get_daemon_info() | ||
2171 | */ | ||
2172 | union MHD_DaemonInfo daemon_info_dummy_listen_fd; | ||
2173 | |||
2174 | #ifdef EPOLL_SUPPORT | ||
2175 | /** | ||
2176 | * The value to be returned by #MHD_get_daemon_info() | ||
2177 | */ | ||
2178 | union MHD_DaemonInfo daemon_info_dummy_epoll_fd; | ||
2179 | #endif /* EPOLL_SUPPORT */ | ||
2180 | |||
2181 | /** | ||
2182 | * The value to be returned by #MHD_get_daemon_info() | ||
2183 | */ | ||
2184 | union MHD_DaemonInfo daemon_info_dummy_num_connections; | ||
2185 | |||
2186 | /** | ||
2187 | * The value to be returned by #MHD_get_daemon_info() | ||
2188 | */ | ||
2189 | union MHD_DaemonInfo daemon_info_dummy_flags; | ||
2190 | |||
2191 | /** | ||
2192 | * The value to be returned by #MHD_get_daemon_info() | ||
2193 | */ | ||
2194 | union MHD_DaemonInfo daemon_info_dummy_port; | ||
2167 | }; | 2195 | }; |
2168 | 2196 | ||
2169 | 2197 | ||
diff --git a/src/microhttpd/test_upgrade.c b/src/microhttpd/test_upgrade.c index acaecf9f..d4b97718 100644 --- a/src/microhttpd/test_upgrade.c +++ b/src/microhttpd/test_upgrade.c | |||
@@ -1257,7 +1257,7 @@ test_upgrade (int flags, | |||
1257 | struct MHD_Daemon *d = NULL; | 1257 | struct MHD_Daemon *d = NULL; |
1258 | struct wr_socket *sock; | 1258 | struct wr_socket *sock; |
1259 | struct sockaddr_in sa; | 1259 | struct sockaddr_in sa; |
1260 | const union MHD_DaemonInfo *real_flags; | 1260 | enum MHD_FLAG used_flags; |
1261 | const union MHD_DaemonInfo *dinfo; | 1261 | const union MHD_DaemonInfo *dinfo; |
1262 | #if defined(HTTPS_SUPPORT) && defined(HAVE_FORK) && defined(HAVE_WAITPID) | 1262 | #if defined(HTTPS_SUPPORT) && defined(HAVE_FORK) && defined(HAVE_WAITPID) |
1263 | pid_t pid = -1; | 1263 | pid_t pid = -1; |
@@ -1296,10 +1296,11 @@ test_upgrade (int flags, | |||
1296 | #endif /* HTTPS_SUPPORT */ | 1296 | #endif /* HTTPS_SUPPORT */ |
1297 | if (NULL == d) | 1297 | if (NULL == d) |
1298 | mhdErrorExitDesc ("MHD_start_daemon() failed"); | 1298 | mhdErrorExitDesc ("MHD_start_daemon() failed"); |
1299 | real_flags = MHD_get_daemon_info (d, | 1299 | dinfo = MHD_get_daemon_info (d, |
1300 | MHD_DAEMON_INFO_FLAGS); | 1300 | MHD_DAEMON_INFO_FLAGS); |
1301 | if (NULL == real_flags) | 1301 | if (NULL == dinfo) |
1302 | mhdErrorExitDesc ("MHD_get_daemon_info() failed"); | 1302 | mhdErrorExitDesc ("MHD_get_daemon_info() failed"); |
1303 | used_flags = dinfo->flags; | ||
1303 | dinfo = MHD_get_daemon_info (d, | 1304 | dinfo = MHD_get_daemon_info (d, |
1304 | MHD_DAEMON_INFO_BIND_PORT); | 1305 | MHD_DAEMON_INFO_BIND_PORT); |
1305 | if ( (NULL == dinfo) || | 1306 | if ( (NULL == dinfo) || |
@@ -1347,15 +1348,7 @@ test_upgrade (int flags, | |||
1347 | sock)) | 1348 | sock)) |
1348 | externalErrorExitDesc ("pthread_create() failed"); | 1349 | externalErrorExitDesc ("pthread_create() failed"); |
1349 | if (0 == (flags & MHD_USE_INTERNAL_POLLING_THREAD) ) | 1350 | if (0 == (flags & MHD_USE_INTERNAL_POLLING_THREAD) ) |
1350 | { | ||
1351 | enum MHD_FLAG used_flags; | ||
1352 | |||
1353 | /* make address sanitizer happy */ | ||
1354 | memcpy (&used_flags, | ||
1355 | real_flags /* ->flags */, | ||
1356 | sizeof (used_flags)); | ||
1357 | run_mhd_loop (d, used_flags); | 1351 | run_mhd_loop (d, used_flags); |
1358 | } | ||
1359 | if (0 != pthread_join (pt_client, | 1352 | if (0 != pthread_join (pt_client, |
1360 | NULL)) | 1353 | NULL)) |
1361 | externalErrorExitDesc ("pthread_join() failed"); | 1354 | externalErrorExitDesc ("pthread_join() failed"); |
diff --git a/src/microhttpd/test_upgrade_large.c b/src/microhttpd/test_upgrade_large.c index e04e7ebf..477a0851 100644 --- a/src/microhttpd/test_upgrade_large.c +++ b/src/microhttpd/test_upgrade_large.c | |||
@@ -1445,7 +1445,7 @@ test_upgrade (int flags, | |||
1445 | struct MHD_Daemon *d = NULL; | 1445 | struct MHD_Daemon *d = NULL; |
1446 | struct wr_socket *sock; | 1446 | struct wr_socket *sock; |
1447 | struct sockaddr_in sa; | 1447 | struct sockaddr_in sa; |
1448 | const union MHD_DaemonInfo *real_flags; | 1448 | enum MHD_FLAG used_flags; |
1449 | const union MHD_DaemonInfo *dinfo; | 1449 | const union MHD_DaemonInfo *dinfo; |
1450 | #if defined(HTTPS_SUPPORT) && defined(HAVE_FORK) && defined(HAVE_WAITPID) | 1450 | #if defined(HTTPS_SUPPORT) && defined(HAVE_FORK) && defined(HAVE_WAITPID) |
1451 | pid_t pid = -1; | 1451 | pid_t pid = -1; |
@@ -1486,10 +1486,11 @@ test_upgrade (int flags, | |||
1486 | #endif /* HTTPS_SUPPORT */ | 1486 | #endif /* HTTPS_SUPPORT */ |
1487 | if (NULL == d) | 1487 | if (NULL == d) |
1488 | mhdErrorExitDesc ("MHD_start_daemon() failed"); | 1488 | mhdErrorExitDesc ("MHD_start_daemon() failed"); |
1489 | real_flags = MHD_get_daemon_info (d, | 1489 | dinfo = MHD_get_daemon_info (d, |
1490 | MHD_DAEMON_INFO_FLAGS); | 1490 | MHD_DAEMON_INFO_FLAGS); |
1491 | if (NULL == real_flags) | 1491 | if (NULL == dinfo) |
1492 | mhdErrorExitDesc ("MHD_get_daemon_info() failed"); | 1492 | mhdErrorExitDesc ("MHD_get_daemon_info() failed"); |
1493 | used_flags = dinfo->flags; | ||
1493 | dinfo = MHD_get_daemon_info (d, | 1494 | dinfo = MHD_get_daemon_info (d, |
1494 | MHD_DAEMON_INFO_BIND_PORT); | 1495 | MHD_DAEMON_INFO_BIND_PORT); |
1495 | if ( (NULL == dinfo) || | 1496 | if ( (NULL == dinfo) || |
@@ -1543,15 +1544,7 @@ test_upgrade (int flags, | |||
1543 | sock)) | 1544 | sock)) |
1544 | externalErrorExitDesc ("pthread_create() failed"); | 1545 | externalErrorExitDesc ("pthread_create() failed"); |
1545 | if (0 == (flags & MHD_USE_INTERNAL_POLLING_THREAD) ) | 1546 | if (0 == (flags & MHD_USE_INTERNAL_POLLING_THREAD) ) |
1546 | { | ||
1547 | enum MHD_FLAG used_flags; | ||
1548 | |||
1549 | /* make address sanitizer happy */ | ||
1550 | memcpy (&used_flags, | ||
1551 | real_flags /* ->flags */, | ||
1552 | sizeof (used_flags)); | ||
1553 | run_mhd_loop (d, used_flags); | 1547 | run_mhd_loop (d, used_flags); |
1554 | } | ||
1555 | if (0 != pthread_join (pt_client, | 1548 | if (0 != pthread_join (pt_client, |
1556 | NULL)) | 1549 | NULL)) |
1557 | externalErrorExitDesc ("pthread_join() failed"); | 1550 | externalErrorExitDesc ("pthread_join() failed"); |