#915 fix "response too large" error path

Otherwise, ogServer sends "200 OK" after a "500 Internal Server Error
error" response.
master
Javier Sánchez Parra 2021-04-16 13:31:44 +02:00 committed by OpenGnSys Support Team
parent 2c6cef71d8
commit 90eab86796
1 changed files with 9 additions and 12 deletions

View File

@ -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) static int og_client_ok(struct og_client *cli, char *buf_reply)
{ {
char buf[OG_MSG_RESPONSE_MAXLEN] = {}; char buf[OG_MSG_RESPONSE_MAXLEN] = {};
int err = 0, len; int len;
len = snprintf(buf, sizeof(buf), len = snprintf(buf, sizeof(buf),
"HTTP/1.1 200 OK\r\nContent-Length: %ld\r\n\r\n%s", "HTTP/1.1 200 OK\r\nContent-Length: %ld\r\n\r\n%s",
strlen(buf_reply), buf_reply); strlen(buf_reply), buf_reply);
if (len >= (int)sizeof(buf)) if (len >= (int)sizeof(buf)) {
err = og_server_internal_error(cli); 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); send(og_client_socket(cli), buf, strlen(buf), 0);
return err; return 0;
} }
int og_client_state_process_payload_rest(struct og_client *cli) 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) if (err < 0)
return og_client_bad_request(cli); return og_client_bad_request(cli);
err = og_client_ok(cli, buf_reply); return 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;
err_process_rest_payload: err_process_rest_payload:
json_decref(root); json_decref(root);