aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeny Grin (Karlson2k) <k2k@narod.ru>2017-03-15 00:45:57 +0300
committerEvgeny Grin (Karlson2k) <k2k@narod.ru>2017-03-15 00:53:08 +0300
commit244ef608698473115faa36d56cb2c2dae4202de8 (patch)
treebbaf70757da7cd2a2c073b7f6fbaa3cdb25c2533
parent4c219bf5c0d4685cb00fd7ce19dd871348b67833 (diff)
downloadlibmicrohttpd-244ef608698473115faa36d56cb2c2dae4202de8.tar.gz
libmicrohttpd-244ef608698473115faa36d56cb2c2dae4202de8.zip
Prevent run of MHD_run_from_select() for daemon started with wrong flags.
Maintain backward compatibility with except_fd_set set to NULL.
-rw-r--r--src/include/microhttpd.h5
-rw-r--r--src/microhttpd/daemon.c89
2 files changed, 74 insertions, 20 deletions
diff --git a/src/include/microhttpd.h b/src/include/microhttpd.h
index 027e4513..c1461988 100644
--- a/src/include/microhttpd.h
+++ b/src/include/microhttpd.h
@@ -2289,10 +2289,13 @@ MHD_run (struct MHD_Daemon *daemon);
2289 * not have to call `select()` again to determine which operations are 2289 * not have to call `select()` again to determine which operations are
2290 * ready. 2290 * ready.
2291 * 2291 *
2292 * This function cannot be used with daemon started with
2293 * MHD_USE_INTERNAL_POLLING_THREAD flag.
2294 *
2292 * @param daemon daemon to run select loop for 2295 * @param daemon daemon to run select loop for
2293 * @param read_fd_set read set 2296 * @param read_fd_set read set
2294 * @param write_fd_set write set 2297 * @param write_fd_set write set
2295 * @param except_fd_set except set (not used, can be NULL) 2298 * @param except_fd_set except set
2296 * @return #MHD_NO on serious errors, #MHD_YES on success 2299 * @return #MHD_NO on serious errors, #MHD_YES on success
2297 * @ingroup event 2300 * @ingroup event
2298 */ 2301 */
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
index e5384c59..23310faf 100644
--- a/src/microhttpd/daemon.c
+++ b/src/microhttpd/daemon.c
@@ -3288,16 +3288,7 @@ MHD_get_timeout (struct MHD_Daemon *daemon,
3288 3288
3289 3289
3290/** 3290/**
3291 * Run webserver operations. This method should be called by clients 3291 * Internal version of #MHD_run_from_select().
3292 * in combination with #MHD_get_fdset if the client-controlled select
3293 * method is used.
3294 *
3295 * You can use this function instead of #MHD_run if you called
3296 * `select()` on the result from #MHD_get_fdset. File descriptors in
3297 * the sets that are not controlled by MHD will be ignored. Calling
3298 * this function instead of #MHD_run is more efficient as MHD will
3299 * not have to call `select()` again to determine which operations are
3300 * ready.
3301 * 3292 *
3302 * @param daemon daemon to run select loop for 3293 * @param daemon daemon to run select loop for
3303 * @param read_fd_set read set 3294 * @param read_fd_set read set
@@ -3307,10 +3298,10 @@ MHD_get_timeout (struct MHD_Daemon *daemon,
3307 * @ingroup event 3298 * @ingroup event
3308 */ 3299 */
3309int 3300int
3310MHD_run_from_select (struct MHD_Daemon *daemon, 3301internal_run_from_select (struct MHD_Daemon *daemon,
3311 const fd_set *read_fd_set, 3302 const fd_set *read_fd_set,
3312 const fd_set *write_fd_set, 3303 const fd_set *write_fd_set,
3313 const fd_set *except_fd_set) 3304 const fd_set *except_fd_set)
3314{ 3305{
3315 MHD_socket ds; 3306 MHD_socket ds;
3316 struct MHD_Connection *pos; 3307 struct MHD_Connection *pos;
@@ -3411,8 +3402,68 @@ MHD_run_from_select (struct MHD_Daemon *daemon,
3411 3402
3412 3403
3413/** 3404/**
3405 * Run webserver operations. This method should be called by clients
3406 * in combination with #MHD_get_fdset if the client-controlled select
3407 * method is used.
3408 *
3409 * You can use this function instead of #MHD_run if you called
3410 * `select()` on the result from #MHD_get_fdset. File descriptors in
3411 * the sets that are not controlled by MHD will be ignored. Calling
3412 * this function instead of #MHD_run is more efficient as MHD will
3413 * not have to call `select()` again to determine which operations are
3414 * ready.
3415 *
3416 * This function cannot be used with daemon started with
3417 * MHD_USE_INTERNAL_POLLING_THREAD flag.
3418 *
3419 * @param daemon daemon to run select loop for
3420 * @param read_fd_set read set
3421 * @param write_fd_set write set
3422 * @param except_fd_set except set
3423 * @return #MHD_NO on serious errors, #MHD_YES on success
3424 * @ingroup event
3425 */
3426int
3427MHD_run_from_select (struct MHD_Daemon *daemon,
3428 const fd_set *read_fd_set,
3429 const fd_set *write_fd_set,
3430 const fd_set *except_fd_set)
3431{
3432 fd_set es;
3433 if (0 != (daemon->options &
3434 (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_POLL)) )
3435 return MHD_NO;
3436 if (NULL == read_fd_set || NULL == write_fd_set)
3437 return MHD_NO;
3438 if (NULL == except_fd_set)
3439 { /* Workaround to maintain backward compatibility. */
3440#ifdef HAVE_MESSAGES
3441 MHD_DLOG (daemon,
3442 _("MHD_run_from_select() called with except_fd_set "
3443 "set to NULL. Such behavior is deprecated.\n"));
3444#endif
3445 except_fd_set = es;
3446 FD_ZERO(except_fd_set);
3447 }
3448 if (0 != (daemon->options & MHD_USE_EPOLL))
3449 {
3450#ifdef EPOLL_SUPPORT
3451 int ret;
3452 ret = MHD_epoll (daemon, MHD_NO);
3453 MHD_cleanup_connections (daemon);
3454 return ret;
3455#else /* ! EPOLL_SUPPORT */
3456 return MHD_NO;
3457#endif /* ! EPOLL_SUPPORT */
3458 }
3459 return internal_run_from_select (daemon, read_fd_set,
3460 write_fd_set, except_fd_set);
3461}
3462
3463
3464/**
3414 * Main internal select() call. Will compute select sets, call select() 3465 * Main internal select() call. Will compute select sets, call select()
3415 * and then #MHD_run_from_select with the result. 3466 * and then #internal_run_from_select with the result.
3416 * 3467 *
3417 * @param daemon daemon to run select() loop for 3468 * @param daemon daemon to run select() loop for
3418 * @param may_block #MHD_YES if blocking, #MHD_NO if non-blocking 3469 * @param may_block #MHD_YES if blocking, #MHD_NO if non-blocking
@@ -3566,10 +3617,10 @@ MHD_select (struct MHD_Daemon *daemon,
3566#endif 3617#endif
3567 return MHD_NO; 3618 return MHD_NO;
3568 } 3619 }
3569 if (MHD_YES == MHD_run_from_select (daemon, 3620 if (MHD_YES == internal_run_from_select (daemon,
3570 &rs, 3621 &rs,
3571 &ws, 3622 &ws,
3572 &es)) 3623 &es))
3573 return (MHD_NO == err_state) ? MHD_YES : MHD_NO; 3624 return (MHD_NO == err_state) ? MHD_YES : MHD_NO;
3574 return MHD_NO; 3625 return MHD_NO;
3575} 3626}