diff options
author | Christian Grothoff <grothoff@gnunet.org> | 2023-09-03 00:23:02 +0200 |
---|---|---|
committer | Christian Grothoff <grothoff@gnunet.org> | 2023-09-03 00:24:16 +0200 |
commit | eb21a977d2b41628c4228ca097b24168574850d9 (patch) | |
tree | 0a562ca3e99c1dfd7a638c6d71f3c32bb3c7305e | |
parent | 8586d91913dcbc728a90d7c1ec9c88cdc3b8258e (diff) | |
download | libmicrohttpd-eb21a977d2b41628c4228ca097b24168574850d9.tar.gz libmicrohttpd-eb21a977d2b41628c4228ca097b24168574850d9.zip |
fix #7757
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | src/microhttpd/connection.c | 13 | ||||
-rw-r--r-- | src/microhttpd/internal.h | 7 |
3 files changed, 23 insertions, 2 deletions
@@ -1,3 +1,8 @@ | |||
1 | Sun Sep 3 12:23:18 AM CEST 2023 | ||
2 | Prevent queueing of responses if connection is not currently in the | ||
3 | access handler callback (which was always not allowed per API spec, | ||
4 | but is now met with an appropriate error response). Fixes #7757. -CG | ||
5 | |||
1 | Web 29 Mar 2023 20:56:00 CEST | 6 | Web 29 Mar 2023 20:56:00 CEST |
2 | Bumped version as the hotfix was released based on the separate branch. -EG | 7 | Bumped version as the hotfix was released based on the separate branch. -EG |
3 | 8 | ||
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c index bfe5b820..b7a9a31a 100644 --- a/src/microhttpd/connection.c +++ b/src/microhttpd/connection.c | |||
@@ -3674,6 +3674,7 @@ call_connection_handler (struct MHD_Connection *connection) | |||
3674 | return; /* already queued a response */ | 3674 | return; /* already queued a response */ |
3675 | processed = 0; | 3675 | processed = 0; |
3676 | connection->rq.client_aware = true; | 3676 | connection->rq.client_aware = true; |
3677 | connection->in_access_handler = true; | ||
3677 | if (MHD_NO == | 3678 | if (MHD_NO == |
3678 | daemon->default_handler (daemon->default_handler_cls, | 3679 | daemon->default_handler (daemon->default_handler_cls, |
3679 | connection, | 3680 | connection, |
@@ -3684,12 +3685,14 @@ call_connection_handler (struct MHD_Connection *connection) | |||
3684 | &processed, | 3685 | &processed, |
3685 | &connection->rq.client_context)) | 3686 | &connection->rq.client_context)) |
3686 | { | 3687 | { |
3688 | connection->in_access_handler = false; | ||
3687 | /* serious internal error, close connection */ | 3689 | /* serious internal error, close connection */ |
3688 | CONNECTION_CLOSE_ERROR (connection, | 3690 | CONNECTION_CLOSE_ERROR (connection, |
3689 | _ ("Application reported internal error, " \ | 3691 | _ ("Application reported internal error, " \ |
3690 | "closing connection.")); | 3692 | "closing connection.")); |
3691 | return; | 3693 | return; |
3692 | } | 3694 | } |
3695 | connection->in_access_handler = false; | ||
3693 | } | 3696 | } |
3694 | 3697 | ||
3695 | 3698 | ||
@@ -3898,6 +3901,7 @@ process_request_body (struct MHD_Connection *connection) | |||
3898 | } | 3901 | } |
3899 | left_unprocessed = to_be_processed; | 3902 | left_unprocessed = to_be_processed; |
3900 | connection->rq.client_aware = true; | 3903 | connection->rq.client_aware = true; |
3904 | connection->in_access_handler = true; | ||
3901 | if (MHD_NO == | 3905 | if (MHD_NO == |
3902 | daemon->default_handler (daemon->default_handler_cls, | 3906 | daemon->default_handler (daemon->default_handler_cls, |
3903 | connection, | 3907 | connection, |
@@ -3908,12 +3912,15 @@ process_request_body (struct MHD_Connection *connection) | |||
3908 | &left_unprocessed, | 3912 | &left_unprocessed, |
3909 | &connection->rq.client_context)) | 3913 | &connection->rq.client_context)) |
3910 | { | 3914 | { |
3915 | connection->in_access_handler = false; | ||
3911 | /* serious internal error, close connection */ | 3916 | /* serious internal error, close connection */ |
3912 | CONNECTION_CLOSE_ERROR (connection, | 3917 | CONNECTION_CLOSE_ERROR (connection, |
3913 | _ ("Application reported internal error, " \ | 3918 | _ ("Application reported internal error, " \ |
3914 | "closing connection.")); | 3919 | "closing connection.")); |
3915 | return; | 3920 | return; |
3916 | } | 3921 | } |
3922 | connection->in_access_handler = false; | ||
3923 | |||
3917 | if (left_unprocessed > to_be_processed) | 3924 | if (left_unprocessed > to_be_processed) |
3918 | MHD_PANIC (_ ("libmicrohttpd API violation.\n")); | 3925 | MHD_PANIC (_ ("libmicrohttpd API violation.\n")); |
3919 | 3926 | ||
@@ -7102,10 +7109,12 @@ MHD_queue_response (struct MHD_Connection *connection, | |||
7102 | struct MHD_Daemon *daemon; | 7109 | struct MHD_Daemon *daemon; |
7103 | bool reply_icy; | 7110 | bool reply_icy; |
7104 | 7111 | ||
7105 | reply_icy = (0 != (status_code & MHD_ICY_FLAG)); | ||
7106 | status_code &= ~MHD_ICY_FLAG; | ||
7107 | if ((NULL == connection) || (NULL == response)) | 7112 | if ((NULL == connection) || (NULL == response)) |
7108 | return MHD_NO; | 7113 | return MHD_NO; |
7114 | if (! connection->in_access_handler) | ||
7115 | return MHD_NO; | ||
7116 | reply_icy = (0 != (status_code & MHD_ICY_FLAG)); | ||
7117 | status_code &= ~MHD_ICY_FLAG; | ||
7109 | 7118 | ||
7110 | daemon = connection->daemon; | 7119 | daemon = connection->daemon; |
7111 | 7120 | ||
diff --git a/src/microhttpd/internal.h b/src/microhttpd/internal.h index 581f6864..56657e19 100644 --- a/src/microhttpd/internal.h +++ b/src/microhttpd/internal.h | |||
@@ -1576,6 +1576,13 @@ struct MHD_Connection | |||
1576 | bool suspended; | 1576 | bool suspended; |
1577 | 1577 | ||
1578 | /** | 1578 | /** |
1579 | * Are we currently in the #MHD_AccessHandlerCallback | ||
1580 | * for this connection (and thus eligible to receive | ||
1581 | * calls to #MHD_queue_response()?). | ||
1582 | */ | ||
1583 | bool in_access_handler; | ||
1584 | |||
1585 | /** | ||
1579 | * Is the connection wanting to resume? | 1586 | * Is the connection wanting to resume? |
1580 | */ | 1587 | */ |
1581 | volatile bool resuming; | 1588 | volatile bool resuming; |