summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2021-03-07 12:08:06 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2021-03-07 12:08:06 +0100
commit60d9c4f3b972ce70dfadc0a3f1a478a056c2ea7a (patch)
tree336ec5af4ca755fc4205e9649ab707e4167528c1
parente3790c148072b32891e5bfa4ee71418f275d67bd (diff)
downloadsystemd-60d9c4f3b972ce70dfadc0a3f1a478a056c2ea7a.tar.gz
journal-remote: check return value from MHD_add_response_header
Sadly, the API does not allow us to distinguish oom from invalid settings. If the call fails, let's assume oom happened. Coverity CID#1444714.
-rw-r--r--src/journal-remote/journal-gatewayd.c22
-rw-r--r--src/journal-remote/microhttpd-util.c3
2 files changed, 18 insertions, 7 deletions
diff --git a/src/journal-remote/journal-gatewayd.c b/src/journal-remote/journal-gatewayd.c
index bd1edb1797..86df022b64 100644
--- a/src/journal-remote/journal-gatewayd.c
+++ b/src/journal-remote/journal-gatewayd.c
@@ -501,7 +501,9 @@ static int request_handler_entries(
if (!response)
return respond_oom(connection);
- MHD_add_response_header(response, "Content-Type", mime_types[m->mode]);
+ if (MHD_add_response_header(response, "Content-Type", mime_types[m->mode]) == MHD_NO)
+ return respond_oom(connection);
+
return MHD_queue_response(connection, MHD_HTTP_OK, response);
}
@@ -629,7 +631,9 @@ static int request_handler_fields(
if (!response)
return respond_oom(connection);
- MHD_add_response_header(response, "Content-Type", mime_types[m->mode == OUTPUT_JSON ? OUTPUT_JSON : OUTPUT_SHORT]);
+ if (MHD_add_response_header(response, "Content-Type", mime_types[m->mode == OUTPUT_JSON ? OUTPUT_JSON : OUTPUT_SHORT]) == MHD_NO)
+ return respond_oom(connection);
+
return MHD_queue_response(connection, MHD_HTTP_OK, response);
}
@@ -652,8 +656,10 @@ static int request_handler_redirect(
return respond_oom(connection);
}
- MHD_add_response_header(response, "Content-Type", "text/html");
- MHD_add_response_header(response, "Location", target);
+ if (MHD_add_response_header(response, "Content-Type", "text/html") == MHD_NO ||
+ MHD_add_response_header(response, "Location", target) == MHD_NO)
+ return respond_oom(connection);
+
return MHD_queue_response(connection, MHD_HTTP_MOVED_PERMANENTLY, response);
}
@@ -682,7 +688,9 @@ static int request_handler_file(
return respond_oom(connection);
TAKE_FD(fd);
- MHD_add_response_header(response, "Content-Type", mime_type);
+ if (MHD_add_response_header(response, "Content-Type", mime_type) == MHD_NO)
+ return respond_oom(connection);
+
return MHD_queue_response(connection, MHD_HTTP_OK, response);
}
@@ -783,7 +791,9 @@ static int request_handler_machine(
return respond_oom(connection);
TAKE_PTR(json);
- MHD_add_response_header(response, "Content-Type", "application/json");
+ if (MHD_add_response_header(response, "Content-Type", "application/json") == MHD_NO)
+ return respond_oom(connection);
+
return MHD_queue_response(connection, MHD_HTTP_OK, response);
}
diff --git a/src/journal-remote/microhttpd-util.c b/src/journal-remote/microhttpd-util.c
index d3fb0b8b19..e6a8254491 100644
--- a/src/journal-remote/microhttpd-util.c
+++ b/src/journal-remote/microhttpd-util.c
@@ -39,7 +39,8 @@ static int mhd_respond_internal(struct MHD_Connection *connection,
return MHD_NO;
log_debug("Queueing response %u: %s", code, buffer);
- MHD_add_response_header(response, "Content-Type", "text/plain");
+ if (MHD_add_response_header(response, "Content-Type", "text/plain") == MHD_NO)
+ return MHD_NO;
return MHD_queue_response(connection, code, response);
}