From 90eab8679625d4a6d5d32b3e4fae498a48a68145 Mon Sep 17 00:00:00 2001 From: Javier Sánchez Parra Date: Fri, 16 Apr 2021 13:31:44 +0200 Subject: #915 fix "response too large" error path Otherwise, ogServer sends "200 OK" after a "500 Internal Server Error error" response. --- src/rest.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/rest.c b/src/rest.c index d9b09d2..f778bc2 100644 --- a/src/rest.c +++ b/src/rest.c @@ -3976,17 +3976,21 @@ static int og_server_internal_error(struct og_client *cli) static int og_client_ok(struct og_client *cli, char *buf_reply) { char buf[OG_MSG_RESPONSE_MAXLEN] = {}; - int err = 0, len; + int len; len = snprintf(buf, sizeof(buf), "HTTP/1.1 200 OK\r\nContent-Length: %ld\r\n\r\n%s", strlen(buf_reply), buf_reply); - if (len >= (int)sizeof(buf)) - err = og_server_internal_error(cli); + if (len >= (int)sizeof(buf)) { + syslog(LOG_ERR, "HTTP response to %s:%hu is too large\n", + inet_ntoa(cli->addr.sin_addr), + ntohs(cli->addr.sin_port)); + return og_server_internal_error(cli); + } send(og_client_socket(cli), buf, strlen(buf), 0); - return err; + return 0; } int og_client_state_process_payload_rest(struct og_client *cli) @@ -4416,14 +4420,7 @@ int og_client_state_process_payload_rest(struct og_client *cli) if (err < 0) return og_client_bad_request(cli); - err = og_client_ok(cli, buf_reply); - if (err < 0) { - syslog(LOG_ERR, "HTTP response to %s:%hu is too large\n", - inet_ntoa(cli->addr.sin_addr), - ntohs(cli->addr.sin_port)); - } - - return err; + return og_client_ok(cli, buf_reply); err_process_rest_payload: json_decref(root); -- cgit v1.2.3-18-g5258