summaryrefslogtreecommitdiff
path: root/src/journal
diff options
context:
space:
mode:
Diffstat (limited to 'src/journal')
-rw-r--r--src/journal/coredump.c30
-rw-r--r--src/journal/journal-remote.c13
2 files changed, 19 insertions, 24 deletions
diff --git a/src/journal/coredump.c b/src/journal/coredump.c
index 29342de681..74b1dbd013 100644
--- a/src/journal/coredump.c
+++ b/src/journal/coredump.c
@@ -39,10 +39,10 @@
#include "journald-native.h"
/* Few programs have less than 3MiB resident */
-#define COREDUMP_MIN_START (3*1024*1024)
+#define COREDUMP_MIN_START (3*1024*1024u)
/* Make sure to not make this larger than the maximum journal entry
* size. See ENTRY_SIZE_MAX in journald-native.c. */
-#define COREDUMP_MAX (767*1024*1024)
+#define COREDUMP_MAX (767*1024*1024u)
assert_cc(COREDUMP_MAX <= ENTRY_SIZE_MAX);
enum {
@@ -107,7 +107,7 @@ int main(int argc, char* argv[]) {
uid_t uid;
gid_t gid;
struct iovec iovec[14];
- size_t coredump_bufsize, coredump_size;
+ size_t coredump_bufsize = 0, coredump_size = 0;
_cleanup_free_ char *core_pid = NULL, *core_uid = NULL, *core_gid = NULL, *core_signal = NULL,
*core_timestamp = NULL, *core_comm = NULL, *core_exe = NULL, *core_unit = NULL,
*core_session = NULL, *core_message = NULL, *core_cmdline = NULL, *coredump_data = NULL;
@@ -239,17 +239,18 @@ int main(int argc, char* argv[]) {
goto finish;
}
- coredump_bufsize = COREDUMP_MIN_START;
- coredump_data = malloc(coredump_bufsize);
- if (!coredump_data) {
- log_warning("Failed to allocate memory for core, core will not be stored.");
- goto finalize;
- }
+ for (;;) {
+ if (!GREEDY_REALLOC(coredump_data, coredump_bufsize,
+ MAX(coredump_size + 1, COREDUMP_MIN_START/2))) {
+ log_warning("Failed to allocate memory for core, core will not be stored.");
+ goto finalize;
+ }
- memcpy(coredump_data, "COREDUMP=", 9);
- coredump_size = 9;
+ if (coredump_size == 0) {
+ memcpy(coredump_data, "COREDUMP=", 9);
+ coredump_size = 9;
+ }
- for (;;) {
n = loop_read(STDIN_FILENO, coredump_data + coredump_size,
coredump_bufsize - coredump_size, false);
if (n < 0) {
@@ -265,11 +266,6 @@ int main(int argc, char* argv[]) {
log_error("Core too large, core will not be stored.");
goto finalize;
}
-
- if (!GREEDY_REALLOC(coredump_data, coredump_bufsize, coredump_size + 1)) {
- log_warning("Failed to allocate memory for core, core will not be stored.");
- goto finalize;
- }
}
iovec[j].iov_base = coredump_data;
diff --git a/src/journal/journal-remote.c b/src/journal/journal-remote.c
index 4ece14ee77..794298fe6f 100644
--- a/src/journal/journal-remote.c
+++ b/src/journal/journal-remote.c
@@ -226,8 +226,8 @@ typedef struct MHDDaemonWrapper {
typedef struct RemoteServer {
RemoteSource **sources;
- ssize_t sources_size;
- ssize_t active;
+ size_t sources_size;
+ size_t active;
sd_event *events;
sd_event_source *sigterm_event, *sigint_event, *listen_event;
@@ -257,7 +257,7 @@ static int get_source_for_fd(RemoteServer *s, int fd, RemoteSource **source) {
assert(fd >= 0);
assert(source);
- if (!GREEDY_REALLOC0_T(s->sources, s->sources_size, fd + 1))
+ if (!GREEDY_REALLOC0(s->sources, s->sources_size, fd + 1))
return log_oom();
if (s->sources[fd] == NULL) {
@@ -276,8 +276,7 @@ static int remove_source(RemoteServer *s, int fd) {
RemoteSource *source;
assert(s);
- assert(fd >= 0);
- assert(fd < s->sources_size);
+ assert(fd >= 0 && fd < (ssize_t) s->sources_size);
source = s->sources[fd];
if (source) {
@@ -837,7 +836,7 @@ static int remoteserver_init(RemoteServer *s) {
static int server_destroy(RemoteServer *s) {
int r;
- ssize_t i;
+ size_t i;
MHDDaemonWrapper *d;
r = writer_close(&s->writer);
@@ -879,7 +878,7 @@ static int dispatch_raw_source_event(sd_event_source *event,
RemoteSource *source;
int r;
- assert(fd < s->sources_size);
+ assert(fd >= 0 && fd < (ssize_t) s->sources_size);
source = s->sources[fd];
assert(source->fd == fd);