diff options
author | OpenGnSys Support Team <soporte-og@soleta.eu> | 2019-08-27 12:01:23 +0200 |
---|---|---|
committer | OpenGnSys Support Team <soporte-og@soleta.eu> | 2019-08-27 12:02:57 +0200 |
commit | fbc30b26690fc6883c9a04d4143fb433c94e598b (patch) | |
tree | 2de61711b6f0165b84a57b55ecbd4f79082beb46 /sources/ogAdmServer.cpp | |
parent | 0524f69bfebc8e461490404b3e4eb034b4f76a56 (diff) |
#915 internal error response if reply is too long
In case reply is too long, return 501 internal server error.
Diffstat (limited to 'sources/ogAdmServer.cpp')
-rw-r--r-- | sources/ogAdmServer.cpp | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/sources/ogAdmServer.cpp b/sources/ogAdmServer.cpp index 0efa2a5..5dd42f3 100644 --- a/sources/ogAdmServer.cpp +++ b/sources/ogAdmServer.cpp @@ -3941,13 +3941,20 @@ static int og_client_not_authorized(struct og_client *cli) static int og_client_ok(struct og_client *cli, char *buf_reply) { char buf[4096] = {}; + int err = 0, len; - sprintf(buf, "HTTP/1.1 200 OK\r\nContent-Length: %ld\r\n\r\n%s", - strlen(buf_reply), buf_reply); + 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)) { + snprintf(buf, sizeof(buf), + "HTTP/1.1 500 Internal Server Error\r\nContent-Length: 0\r\n\r\n"); + err = -1; + } send(og_client_socket(cli), buf, strlen(buf), 0); - return 0; + return err; } enum og_rest_method { @@ -4107,7 +4114,7 @@ static int og_client_state_process_payload_rest(struct og_client *cli) json_decref(root); if (!err) - og_client_ok(cli, buf_reply); + err = og_client_ok(cli, buf_reply); return err; } |