Bug Summary

File:build-scan/../src/basic/journal-importer.c
Warning:line 194, column 26
1st function call argument is an uninitialized value

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name journal-importer.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=all -relaxed-aliasing -menable-no-infs -menable-no-nans -menable-unsafe-fp-math -fno-signed-zeros -mreassociate -freciprocal-math -fdenormal-fp-math=preserve-sign,preserve-sign -ffp-contract=fast -fno-rounding-math -ffast-math -ffinite-math-only -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /usr/lib64/clang/12.0.0 -include config.h -I src/basic/libbasic.a.p -I src/basic -I ../src/basic -I src/shared -I ../src/shared -I src/systemd -I ../src/systemd -I src/journal -I ../src/journal -I src/journal-remote -I ../src/journal-remote -I src/nspawn -I ../src/nspawn -I src/resolve -I ../src/resolve -I src/timesync -I ../src/timesync -I ../src/time-wait-sync -I src/login -I ../src/login -I src/udev -I ../src/udev -I src/libudev -I ../src/libudev -I src/core -I ../src/core -I ../src/libsystemd/sd-bus -I ../src/libsystemd/sd-device -I ../src/libsystemd/sd-hwdb -I ../src/libsystemd/sd-id128 -I ../src/libsystemd/sd-netlink -I ../src/libsystemd/sd-network -I src/libsystemd-network -I ../src/libsystemd-network -I . -I .. -I /usr/include/blkid -I /usr/include/libmount -D _FILE_OFFSET_BITS=64 -internal-isystem /usr/local/include -internal-isystem /usr/lib64/clang/12.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -Wwrite-strings -Wno-unused-parameter -Wno-missing-field-initializers -Wno-unused-result -Wno-format-signedness -Wno-error=nonnull -std=gnu99 -fconst-strings -fdebug-compilation-dir /home/mrc0mmand/repos/@redhat-plumbers/systemd-rhel8/build-scan -ferror-limit 19 -fvisibility default -stack-protector 2 -fgnuc-version=4.2.1 -fcolor-diagnostics -analyzer-output=html -faddrsig -o /tmp/scan-build-2021-07-16-221226-1465241-1 -x c ../src/basic/journal-importer.c
1/* SPDX-License-Identifier: LGPL-2.1+ */
2
3#include <errno(*__errno_location ()).h>
4#include <unistd.h>
5
6#include "alloc-util.h"
7#include "escape.h"
8#include "fd-util.h"
9#include "io-util.h"
10#include "journal-file.h"
11#include "journal-importer.h"
12#include "journal-util.h"
13#include "parse-util.h"
14#include "string-util.h"
15#include "unaligned.h"
16
17enum {
18 IMPORTER_STATE_LINE = 0, /* waiting to read, or reading line */
19 IMPORTER_STATE_DATA_START, /* reading binary data header */
20 IMPORTER_STATE_DATA, /* reading binary data */
21 IMPORTER_STATE_DATA_FINISH, /* expecting newline */
22 IMPORTER_STATE_EOF, /* done */
23};
24
25static int iovw_put(struct iovec_wrapper *iovw, void* data, size_t len) {
26 if (!GREEDY_REALLOC(iovw->iovec, iovw->size_bytes, iovw->count + 1)greedy_realloc((void**) &(iovw->iovec), &(iovw->
size_bytes), (iovw->count + 1), sizeof((iovw->iovec)[0]
))
)
27 return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/basic/journal-importer.c"
, 27, __func__)
;
28
29 iovw->iovec[iovw->count++] = IOVEC_MAKE(data, len)(struct iovec) { .iov_base = (data), .iov_len = (len) };
30 return 0;
31}
32
33static void iovw_free_contents(struct iovec_wrapper *iovw) {
34 iovw->iovec = mfree(iovw->iovec);
35 iovw->size_bytes = iovw->count = 0;
36}
37
38static void iovw_rebase(struct iovec_wrapper *iovw, char *old, char *new) {
39 size_t i;
40
41 for (i = 0; i < iovw->count; i++)
42 iovw->iovec[i].iov_base = (char*) iovw->iovec[i].iov_base - old + new;
43}
44
45size_t iovw_size(struct iovec_wrapper *iovw) {
46 size_t n = 0, i;
47
48 for (i = 0; i < iovw->count; i++)
49 n += iovw->iovec[i].iov_len;
50
51 return n;
52}
53
54void journal_importer_cleanup(JournalImporter *imp) {
55 if (imp->fd >= 0 && !imp->passive_fd) {
56 log_debug("Closing %s (fd=%d)", imp->name ?: "importer", imp->fd)({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/basic/journal-importer.c", 56, __func__, "Closing %s (fd=%d)"
, imp->name ?: "importer", imp->fd) : -abs(_e); })
;
57 safe_close(imp->fd);
58 }
59
60 free(imp->name);
61 free(imp->buf);
62 iovw_free_contents(&imp->iovw);
63}
64
65static char* realloc_buffer(JournalImporter *imp, size_t size) {
66 char *b, *old = imp->buf;
67
68 b = GREEDY_REALLOC(imp->buf, imp->size, size)greedy_realloc((void**) &(imp->buf), &(imp->size
), (size), sizeof((imp->buf)[0]))
;
69 if (!b)
70 return NULL((void*)0);
71
72 iovw_rebase(&imp->iovw, old, imp->buf);
73
74 return b;
75}
76
77static int get_line(JournalImporter *imp, char **line, size_t *size) {
78 ssize_t n;
79 char *c = NULL((void*)0);
80
81 assert(imp)do { if ((__builtin_expect(!!(!(imp)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("imp"), "../src/basic/journal-importer.c"
, 81, __PRETTY_FUNCTION__); } while (0)
;
82 assert(imp->state == IMPORTER_STATE_LINE)do { if ((__builtin_expect(!!(!(imp->state == IMPORTER_STATE_LINE
)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("imp->state == IMPORTER_STATE_LINE"
), "../src/basic/journal-importer.c", 82, __PRETTY_FUNCTION__
); } while (0)
;
83 assert(imp->offset <= imp->filled)do { if ((__builtin_expect(!!(!(imp->offset <= imp->
filled)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("imp->offset <= imp->filled"
), "../src/basic/journal-importer.c", 83, __PRETTY_FUNCTION__
); } while (0)
;
84 assert(imp->filled <= imp->size)do { if ((__builtin_expect(!!(!(imp->filled <= imp->
size)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("imp->filled <= imp->size"
), "../src/basic/journal-importer.c", 84, __PRETTY_FUNCTION__
); } while (0)
;
85 assert(!imp->buf || imp->size > 0)do { if ((__builtin_expect(!!(!(!imp->buf || imp->size >
0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("!imp->buf || imp->size > 0"
), "../src/basic/journal-importer.c", 85, __PRETTY_FUNCTION__
); } while (0)
;
86 assert(imp->fd >= 0)do { if ((__builtin_expect(!!(!(imp->fd >= 0)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("imp->fd >= 0"), "../src/basic/journal-importer.c"
, 86, __PRETTY_FUNCTION__); } while (0)
;
87
88 for (;;) {
89 if (imp->buf) {
90 size_t start = MAX(imp->scanned, imp->offset)__extension__ ({ const typeof((imp->scanned)) __unique_prefix_A15
= ((imp->scanned)); const typeof((imp->offset)) __unique_prefix_B16
= ((imp->offset)); __unique_prefix_A15 > __unique_prefix_B16
? __unique_prefix_A15 : __unique_prefix_B16; })
;
91
92 c = memchr(imp->buf + start, '\n',
93 imp->filled - start);
94 if (c != NULL((void*)0))
95 break;
96 }
97
98 imp->scanned = imp->filled;
99 if (imp->scanned >= DATA_SIZE_MAX(1024*1024*768u)) {
100 log_error("Entry is bigger than %u bytes.", DATA_SIZE_MAX)({ int _level = (((3))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/basic/journal-importer.c", 100, __func__, "Entry is bigger than %u bytes."
, (1024*1024*768u)) : -abs(_e); })
;
101 return -E2BIG7;
102 }
103
104 if (imp->passive_fd)
105 /* we have to wait for some data to come to us */
106 return -EAGAIN11;
107
108 /* We know that imp->filled is at most DATA_SIZE_MAX, so if
109 we reallocate it, we'll increase the size at least a bit. */
110 assert_cc(DATA_SIZE_MAX < ENTRY_SIZE_MAX)GCC diagnostic push ; GCC diagnostic ignored "-Wdeclaration-after-statement"
; struct _assert_struct_17 { char x[((1024*1024*768u) < (
1024*1024*770u)) ? 0 : -1]; }; GCC diagnostic pop
;
111 if (imp->size - imp->filled < LINE_CHUNK8*1024u &&
112 !realloc_buffer(imp, MIN(imp->filled + LINE_CHUNK, ENTRY_SIZE_MAX)__extension__ ({ const typeof((imp->filled + 8*1024u)) __unique_prefix_A18
= ((imp->filled + 8*1024u)); const typeof(((1024*1024*770u
))) __unique_prefix_B19 = (((1024*1024*770u))); __unique_prefix_A18
< __unique_prefix_B19 ? __unique_prefix_A18 : __unique_prefix_B19
; })
))
113 return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/basic/journal-importer.c"
, 113, __func__)
;
114
115 assert(imp->buf)do { if ((__builtin_expect(!!(!(imp->buf)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("imp->buf"), "../src/basic/journal-importer.c"
, 115, __PRETTY_FUNCTION__); } while (0)
;
116 assert(imp->size - imp->filled >= LINE_CHUNK ||do { if ((__builtin_expect(!!(!(imp->size - imp->filled
>= 8*1024u || imp->size == (1024*1024*770u))),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("imp->size - imp->filled >= LINE_CHUNK || imp->size == ENTRY_SIZE_MAX"
), "../src/basic/journal-importer.c", 117, __PRETTY_FUNCTION__
); } while (0)
117 imp->size == ENTRY_SIZE_MAX)do { if ((__builtin_expect(!!(!(imp->size - imp->filled
>= 8*1024u || imp->size == (1024*1024*770u))),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("imp->size - imp->filled >= LINE_CHUNK || imp->size == ENTRY_SIZE_MAX"
), "../src/basic/journal-importer.c", 117, __PRETTY_FUNCTION__
); } while (0)
;
118
119 n = read(imp->fd,
120 imp->buf + imp->filled,
121 imp->size - imp->filled);
122 if (n < 0) {
123 if (errno(*__errno_location ()) != EAGAIN11)
124 log_error_errno(errno, "read(%d, ..., %zu): %m",({ int _level = ((3)), _e = (((*__errno_location ()))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/basic/journal-importer.c", 126, __func__
, "read(%d, ..., %zu): %m", imp->fd, imp->size - imp->
filled) : -abs(_e); })
125 imp->fd,({ int _level = ((3)), _e = (((*__errno_location ()))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/basic/journal-importer.c", 126, __func__
, "read(%d, ..., %zu): %m", imp->fd, imp->size - imp->
filled) : -abs(_e); })
126 imp->size - imp->filled)({ int _level = ((3)), _e = (((*__errno_location ()))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/basic/journal-importer.c", 126, __func__
, "read(%d, ..., %zu): %m", imp->fd, imp->size - imp->
filled) : -abs(_e); })
;
127 return -errno(*__errno_location ());
128 } else if (n == 0)
129 return 0;
130
131 imp->filled += n;
132 }
133
134 *line = imp->buf + imp->offset;
135 *size = c + 1 - imp->buf - imp->offset;
136 imp->offset += *size;
137
138 return 1;
139}
140
141static int fill_fixed_size(JournalImporter *imp, void **data, size_t size) {
142
143 assert(imp)do { if ((__builtin_expect(!!(!(imp)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("imp"), "../src/basic/journal-importer.c"
, 143, __PRETTY_FUNCTION__); } while (0)
;
14
Taking false branch
15
Loop condition is false. Exiting loop
144 assert(IN_SET(imp->state, IMPORTER_STATE_DATA_START, IMPORTER_STATE_DATA, IMPORTER_STATE_DATA_FINISH))do { if ((__builtin_expect(!!(!(({ _Bool _found = 0; static __attribute__
((unused)) char _static_assert__macros_need_to_be_extended[20
- sizeof((int[]){IMPORTER_STATE_DATA_START, IMPORTER_STATE_DATA
, IMPORTER_STATE_DATA_FINISH})/sizeof(int)]; switch(imp->state
) { case IMPORTER_STATE_DATA_START: case IMPORTER_STATE_DATA:
case IMPORTER_STATE_DATA_FINISH: _found = 1; break; default:
break; } _found; }))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("IN_SET(imp->state, IMPORTER_STATE_DATA_START, IMPORTER_STATE_DATA, IMPORTER_STATE_DATA_FINISH)"
), "../src/basic/journal-importer.c", 144, __PRETTY_FUNCTION__
); } while (0)
;
16
Control jumps to 'case IMPORTER_STATE_DATA_START:' at line 144
17
Execution continues on line 144
18
Taking false branch
19
Loop condition is false. Exiting loop
145 assert(size <= DATA_SIZE_MAX)do { if ((__builtin_expect(!!(!(size <= (1024*1024*768u)))
,0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("size <= DATA_SIZE_MAX"
), "../src/basic/journal-importer.c", 145, __PRETTY_FUNCTION__
); } while (0)
;
20
Taking false branch
21
Loop condition is false. Exiting loop
146 assert(imp->offset <= imp->filled)do { if ((__builtin_expect(!!(!(imp->offset <= imp->
filled)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("imp->offset <= imp->filled"
), "../src/basic/journal-importer.c", 146, __PRETTY_FUNCTION__
); } while (0)
;
22
Assuming field 'offset' is <= field 'filled'
23
Taking false branch
24
Loop condition is false. Exiting loop
147 assert(imp->filled <= imp->size)do { if ((__builtin_expect(!!(!(imp->filled <= imp->
size)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("imp->filled <= imp->size"
), "../src/basic/journal-importer.c", 147, __PRETTY_FUNCTION__
); } while (0)
;
25
Assuming field 'filled' is <= field 'size'
26
Taking false branch
27
Loop condition is false. Exiting loop
148 assert(imp->buf || imp->size == 0)do { if ((__builtin_expect(!!(!(imp->buf || imp->size ==
0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("imp->buf || imp->size == 0"
), "../src/basic/journal-importer.c", 148, __PRETTY_FUNCTION__
); } while (0)
;
28
Assuming field 'buf' is null
29
Assuming field 'size' is equal to 0
30
Taking false branch
31
Loop condition is false. Exiting loop
149 assert(!imp->buf || imp->size > 0)do { if ((__builtin_expect(!!(!(!imp->buf || imp->size >
0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("!imp->buf || imp->size > 0"
), "../src/basic/journal-importer.c", 149, __PRETTY_FUNCTION__
); } while (0)
;
32
Taking false branch
33
Loop condition is false. Exiting loop
150 assert(imp->fd >= 0)do { if ((__builtin_expect(!!(!(imp->fd >= 0)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("imp->fd >= 0"), "../src/basic/journal-importer.c"
, 150, __PRETTY_FUNCTION__); } while (0)
;
34
Assuming field 'fd' is >= 0
35
Taking false branch
36
Loop condition is false. Exiting loop
151 assert(data)do { if ((__builtin_expect(!!(!(data)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("data"), "../src/basic/journal-importer.c"
, 151, __PRETTY_FUNCTION__); } while (0)
;
37
Taking false branch
38
Loop condition is false. Exiting loop
152
153 while (imp->filled - imp->offset < size) {
39
Assuming the condition is true
40
Loop condition is true. Entering loop body
154 int n;
155
156 if (imp->passive_fd)
41
Assuming field 'passive_fd' is false
42
Taking false branch
157 /* we have to wait for some data to come to us */
158 return -EAGAIN11;
159
160 if (!realloc_buffer(imp, imp->offset + size))
43
Taking true branch
161 return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/basic/journal-importer.c"
, 161, __func__)
;
44
Returning without writing to '*data'
162
163 n = read(imp->fd, imp->buf + imp->filled,
164 imp->size - imp->filled);
165 if (n < 0) {
166 if (errno(*__errno_location ()) != EAGAIN11)
167 log_error_errno(errno, "read(%d, ..., %zu): %m", imp->fd,({ int _level = ((3)), _e = (((*__errno_location ()))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/basic/journal-importer.c", 168, __func__
, "read(%d, ..., %zu): %m", imp->fd, imp->size - imp->
filled) : -abs(_e); })
168 imp->size - imp->filled)({ int _level = ((3)), _e = (((*__errno_location ()))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/basic/journal-importer.c", 168, __func__
, "read(%d, ..., %zu): %m", imp->fd, imp->size - imp->
filled) : -abs(_e); })
;
169 return -errno(*__errno_location ());
170 } else if (n == 0)
171 return 0;
172
173 imp->filled += n;
174 }
175
176 *data = imp->buf + imp->offset;
177 imp->offset += size;
178
179 return 1;
180}
181
182static int get_data_size(JournalImporter *imp) {
183 int r;
184 void *data;
6
'data' declared without an initial value
185
186 assert(imp)do { if ((__builtin_expect(!!(!(imp)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("imp"), "../src/basic/journal-importer.c"
, 186, __PRETTY_FUNCTION__); } while (0)
;
7
Taking false branch
8
Loop condition is false. Exiting loop
187 assert(imp->state == IMPORTER_STATE_DATA_START)do { if ((__builtin_expect(!!(!(imp->state == IMPORTER_STATE_DATA_START
)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("imp->state == IMPORTER_STATE_DATA_START"
), "../src/basic/journal-importer.c", 187, __PRETTY_FUNCTION__
); } while (0)
;
9
Taking false branch
10
Loop condition is false. Exiting loop
188 assert(imp->data_size == 0)do { if ((__builtin_expect(!!(!(imp->data_size == 0)),0)))
log_assert_failed_realm(LOG_REALM_SYSTEMD, ("imp->data_size == 0"
), "../src/basic/journal-importer.c", 188, __PRETTY_FUNCTION__
); } while (0)
;
11
Taking false branch
12
Loop condition is false. Exiting loop
189
190 r = fill_fixed_size(imp, &data, sizeof(uint64_t));
13
Calling 'fill_fixed_size'
45
Returning from 'fill_fixed_size'
191 if (r <= 0)
46
Assuming 'r' is > 0
47
Taking false branch
192 return r;
193
194 imp->data_size = unaligned_read_le64(data);
48
1st function call argument is an uninitialized value
195 if (imp->data_size > DATA_SIZE_MAX(1024*1024*768u)) {
196 log_error("Stream declares field with size %zu > DATA_SIZE_MAX = %u",({ int _level = (((3))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/basic/journal-importer.c", 197, __func__, "Stream declares field with size %zu > DATA_SIZE_MAX = %u"
, imp->data_size, (1024*1024*768u)) : -abs(_e); })
197 imp->data_size, DATA_SIZE_MAX)({ int _level = (((3))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/basic/journal-importer.c", 197, __func__, "Stream declares field with size %zu > DATA_SIZE_MAX = %u"
, imp->data_size, (1024*1024*768u)) : -abs(_e); })
;
198 return -EINVAL22;
199 }
200 if (imp->data_size == 0)
201 log_warning("Binary field with zero length")({ int _level = (((4))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/basic/journal-importer.c", 201, __func__, "Binary field with zero length"
) : -abs(_e); })
;
202
203 return 1;
204}
205
206static int get_data_data(JournalImporter *imp, void **data) {
207 int r;
208
209 assert(imp)do { if ((__builtin_expect(!!(!(imp)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("imp"), "../src/basic/journal-importer.c"
, 209, __PRETTY_FUNCTION__); } while (0)
;
210 assert(data)do { if ((__builtin_expect(!!(!(data)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("data"), "../src/basic/journal-importer.c"
, 210, __PRETTY_FUNCTION__); } while (0)
;
211 assert(imp->state == IMPORTER_STATE_DATA)do { if ((__builtin_expect(!!(!(imp->state == IMPORTER_STATE_DATA
)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("imp->state == IMPORTER_STATE_DATA"
), "../src/basic/journal-importer.c", 211, __PRETTY_FUNCTION__
); } while (0)
;
212
213 r = fill_fixed_size(imp, data, imp->data_size);
214 if (r <= 0)
215 return r;
216
217 return 1;
218}
219
220static int get_data_newline(JournalImporter *imp) {
221 int r;
222 char *data;
223
224 assert(imp)do { if ((__builtin_expect(!!(!(imp)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("imp"), "../src/basic/journal-importer.c"
, 224, __PRETTY_FUNCTION__); } while (0)
;
225 assert(imp->state == IMPORTER_STATE_DATA_FINISH)do { if ((__builtin_expect(!!(!(imp->state == IMPORTER_STATE_DATA_FINISH
)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("imp->state == IMPORTER_STATE_DATA_FINISH"
), "../src/basic/journal-importer.c", 225, __PRETTY_FUNCTION__
); } while (0)
;
226
227 r = fill_fixed_size(imp, (void**) &data, 1);
228 if (r <= 0)
229 return r;
230
231 assert(data)do { if ((__builtin_expect(!!(!(data)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("data"), "../src/basic/journal-importer.c"
, 231, __PRETTY_FUNCTION__); } while (0)
;
232 if (*data != '\n') {
233 char buf[4];
234 int l;
235
236 l = cescape_char(*data, buf);
237 log_error("Expected newline, got '%.*s'", l, buf)({ int _level = (((3))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/basic/journal-importer.c", 237, __func__, "Expected newline, got '%.*s'"
, l, buf) : -abs(_e); })
;
238 return -EINVAL22;
239 }
240
241 return 1;
242}
243
244static int process_special_field(JournalImporter *imp, char *line) {
245 const char *value;
246 char buf[CELLESCAPE_DEFAULT_LENGTH64];
247 int r;
248
249 assert(line)do { if ((__builtin_expect(!!(!(line)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("line"), "../src/basic/journal-importer.c"
, 249, __PRETTY_FUNCTION__); } while (0)
;
250
251 value = startswith(line, "__CURSOR=");
252 if (value)
253 /* ignore __CURSOR */
254 return 1;
255
256 value = startswith(line, "__REALTIME_TIMESTAMP=");
257 if (value) {
258 uint64_t x;
259
260 r = safe_atou64(value, &x);
261 if (r < 0)
262 return log_warning_errno(r, "Failed to parse __REALTIME_TIMESTAMP '%s': %m",({ int _level = ((4)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/basic/journal-importer.c", 263, __func__, "Failed to parse __REALTIME_TIMESTAMP '%s': %m"
, cellescape(buf, sizeof buf, value)) : -abs(_e); })
263 cellescape(buf, sizeof buf, value))({ int _level = ((4)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/basic/journal-importer.c", 263, __func__, "Failed to parse __REALTIME_TIMESTAMP '%s': %m"
, cellescape(buf, sizeof buf, value)) : -abs(_e); })
;
264 else if (!VALID_REALTIME(x)) {
265 log_warning("__REALTIME_TIMESTAMP out of range, ignoring: %"PRIu64, x)({ int _level = (((4))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/basic/journal-importer.c", 265, __func__, "__REALTIME_TIMESTAMP out of range, ignoring: %"
"l" "u", x) : -abs(_e); })
;
266 return -ERANGE34;
267 }
268
269 imp->ts.realtime = x;
270 return 1;
271 }
272
273 value = startswith(line, "__MONOTONIC_TIMESTAMP=");
274 if (value) {
275 uint64_t x;
276
277 r = safe_atou64(value, &x);
278 if (r < 0)
279 return log_warning_errno(r, "Failed to parse __MONOTONIC_TIMESTAMP '%s': %m",({ int _level = ((4)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/basic/journal-importer.c", 280, __func__, "Failed to parse __MONOTONIC_TIMESTAMP '%s': %m"
, cellescape(buf, sizeof buf, value)) : -abs(_e); })
280 cellescape(buf, sizeof buf, value))({ int _level = ((4)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/basic/journal-importer.c", 280, __func__, "Failed to parse __MONOTONIC_TIMESTAMP '%s': %m"
, cellescape(buf, sizeof buf, value)) : -abs(_e); })
;
281 else if (!VALID_MONOTONIC(x)) {
282 log_warning("__MONOTONIC_TIMESTAMP out of range, ignoring: %"PRIu64, x)({ int _level = (((4))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/basic/journal-importer.c", 282, __func__, "__MONOTONIC_TIMESTAMP out of range, ignoring: %"
"l" "u", x) : -abs(_e); })
;
283 return -ERANGE34;
284 }
285
286 imp->ts.monotonic = x;
287 return 1;
288 }
289
290 /* Just a single underline, but it needs special treatment too. */
291 value = startswith(line, "_BOOT_ID=");
292 if (value) {
293 r = sd_id128_from_string(value, &imp->boot_id);
294 if (r < 0)
295 return log_warning_errno(r, "Failed to parse _BOOT_ID '%s': %m",({ int _level = ((4)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/basic/journal-importer.c", 296, __func__, "Failed to parse _BOOT_ID '%s': %m"
, cellescape(buf, sizeof buf, value)) : -abs(_e); })
296 cellescape(buf, sizeof buf, value))({ int _level = ((4)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/basic/journal-importer.c", 296, __func__, "Failed to parse _BOOT_ID '%s': %m"
, cellescape(buf, sizeof buf, value)) : -abs(_e); })
;
297
298 /* store the field in the usual fashion too */
299 return 0;
300 }
301
302 value = startswith(line, "__");
303 if (value) {
304 log_notice("Unknown dunder line __%s, ignoring.", cellescape(buf, sizeof buf, value))({ int _level = (((5))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/basic/journal-importer.c", 304, __func__, "Unknown dunder line __%s, ignoring."
, cellescape(buf, sizeof buf, value)) : -abs(_e); })
;
305 return 1;
306 }
307
308 /* no dunder */
309 return 0;
310}
311
312int journal_importer_process_data(JournalImporter *imp) {
313 int r;
314
315 switch(imp->state) {
1
Control jumps to 'case IMPORTER_STATE_DATA_START:' at line 380
316 case IMPORTER_STATE_LINE: {
317 char *line, *sep;
318 size_t n = 0;
319
320 assert(imp->data_size == 0)do { if ((__builtin_expect(!!(!(imp->data_size == 0)),0)))
log_assert_failed_realm(LOG_REALM_SYSTEMD, ("imp->data_size == 0"
), "../src/basic/journal-importer.c", 320, __PRETTY_FUNCTION__
); } while (0)
;
321
322 r = get_line(imp, &line, &n);
323 if (r < 0)
324 return r;
325 if (r == 0) {
326 imp->state = IMPORTER_STATE_EOF;
327 return 0;
328 }
329 assert(n > 0)do { if ((__builtin_expect(!!(!(n > 0)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("n > 0"), "../src/basic/journal-importer.c"
, 329, __PRETTY_FUNCTION__); } while (0)
;
330 assert(line[n-1] == '\n')do { if ((__builtin_expect(!!(!(line[n-1] == '\n')),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("line[n-1] == '\\n'"), "../src/basic/journal-importer.c"
, 330, __PRETTY_FUNCTION__); } while (0)
;
331
332 if (n == 1) {
333 log_trace("Received empty line, event is ready")({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/basic/journal-importer.c", 333, __func__, "Received empty line, event is ready"
) : -abs(_e); })
;
334 return 1;
335 }
336
337 /* MESSAGE=xxx\n
338 or
339 COREDUMP\n
340 LLLLLLLL0011223344...\n
341 */
342 sep = memchr(line, '=', n);
343 if (sep) {
344 /* chomp newline */
345 n--;
346
347 if (!journal_field_valid(line, sep - line, true1)) {
348 char buf[64], *t;
349
350 t = strndupa(line, sep - line)(__extension__ ({ const char *__old = (line); size_t __len = strnlen
(__old, (sep - line)); char *__new = (char *) __builtin_alloca
(__len + 1); __new[__len] = '\0'; (char *) memcpy (__new, __old
, __len); }))
;
351 log_debug("Ignoring invalid field: \"%s\"",({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/basic/journal-importer.c", 352, __func__, "Ignoring invalid field: \"%s\""
, cellescape(buf, sizeof buf, t)) : -abs(_e); })
352 cellescape(buf, sizeof buf, t))({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/basic/journal-importer.c", 352, __func__, "Ignoring invalid field: \"%s\""
, cellescape(buf, sizeof buf, t)) : -abs(_e); })
;
353
354 return 0;
355 }
356
357 line[n] = '\0';
358 r = process_special_field(imp, line);
359 if (r != 0)
360 return r < 0 ? r : 0;
361
362 r = iovw_put(&imp->iovw, line, n);
363 if (r < 0)
364 return r;
365 } else {
366 /* replace \n with = */
367 line[n-1] = '=';
368
369 imp->field_len = n;
370 imp->state = IMPORTER_STATE_DATA_START;
371
372 /* we cannot put the field in iovec until we have all data */
373 }
374
375 log_trace("Received: %.*s (%s)", (int) n, line, sep ? "text" : "binary")({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/basic/journal-importer.c", 375, __func__, "Received: %.*s (%s)"
, (int) n, line, sep ? "text" : "binary") : -abs(_e); })
;
376
377 return 0; /* continue */
378 }
379
380 case IMPORTER_STATE_DATA_START:
381 assert(imp->data_size == 0)do { if ((__builtin_expect(!!(!(imp->data_size == 0)),0)))
log_assert_failed_realm(LOG_REALM_SYSTEMD, ("imp->data_size == 0"
), "../src/basic/journal-importer.c", 381, __PRETTY_FUNCTION__
); } while (0)
;
2
Assuming field 'data_size' is equal to 0
3
Taking false branch
4
Loop condition is false. Exiting loop
382
383 r = get_data_size(imp);
5
Calling 'get_data_size'
384 // log_debug("get_data_size() -> %d", r);
385 if (r < 0)
386 return r;
387 if (r == 0) {
388 imp->state = IMPORTER_STATE_EOF;
389 return 0;
390 }
391
392 imp->state = imp->data_size > 0 ?
393 IMPORTER_STATE_DATA : IMPORTER_STATE_DATA_FINISH;
394
395 return 0; /* continue */
396
397 case IMPORTER_STATE_DATA: {
398 void *data;
399 char *field;
400
401 assert(imp->data_size > 0)do { if ((__builtin_expect(!!(!(imp->data_size > 0)),0)
)) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("imp->data_size > 0"
), "../src/basic/journal-importer.c", 401, __PRETTY_FUNCTION__
); } while (0)
;
402
403 r = get_data_data(imp, &data);
404 // log_debug("get_data_data() -> %d", r);
405 if (r < 0)
406 return r;
407 if (r == 0) {
408 imp->state = IMPORTER_STATE_EOF;
409 return 0;
410 }
411
412 assert(data)do { if ((__builtin_expect(!!(!(data)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("data"), "../src/basic/journal-importer.c"
, 412, __PRETTY_FUNCTION__); } while (0)
;
413
414 field = (char*) data - sizeof(uint64_t) - imp->field_len;
415 memmove(field + sizeof(uint64_t), field, imp->field_len);
416
417 r = iovw_put(&imp->iovw, field + sizeof(uint64_t), imp->field_len + imp->data_size);
418 if (r < 0)
419 return r;
420
421 imp->state = IMPORTER_STATE_DATA_FINISH;
422
423 return 0; /* continue */
424 }
425
426 case IMPORTER_STATE_DATA_FINISH:
427 r = get_data_newline(imp);
428 // log_debug("get_data_newline() -> %d", r);
429 if (r < 0)
430 return r;
431 if (r == 0) {
432 imp->state = IMPORTER_STATE_EOF;
433 return 0;
434 }
435
436 imp->data_size = 0;
437 imp->state = IMPORTER_STATE_LINE;
438
439 return 0; /* continue */
440 default:
441 assert_not_reached("wtf?")do { log_assert_failed_unreachable_realm(LOG_REALM_SYSTEMD, (
"wtf?"), "../src/basic/journal-importer.c", 441, __PRETTY_FUNCTION__
); } while (0)
;
442 }
443}
444
445int journal_importer_push_data(JournalImporter *imp, const char *data, size_t size) {
446 assert(imp)do { if ((__builtin_expect(!!(!(imp)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("imp"), "../src/basic/journal-importer.c"
, 446, __PRETTY_FUNCTION__); } while (0)
;
447 assert(imp->state != IMPORTER_STATE_EOF)do { if ((__builtin_expect(!!(!(imp->state != IMPORTER_STATE_EOF
)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("imp->state != IMPORTER_STATE_EOF"
), "../src/basic/journal-importer.c", 447, __PRETTY_FUNCTION__
); } while (0)
;
448
449 if (!realloc_buffer(imp, imp->filled + size)) {
450 log_error("Failed to store received data of size %zu "({ int _level = (((3))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/basic/journal-importer.c", 452, __func__, "Failed to store received data of size %zu "
"(in addition to existing %zu bytes with %zu filled): %s", size
, imp->size, imp->filled, strerror(12)) : -abs(_e); })
451 "(in addition to existing %zu bytes with %zu filled): %s",({ int _level = (((3))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/basic/journal-importer.c", 452, __func__, "Failed to store received data of size %zu "
"(in addition to existing %zu bytes with %zu filled): %s", size
, imp->size, imp->filled, strerror(12)) : -abs(_e); })
452 size, imp->size, imp->filled, strerror(ENOMEM))({ int _level = (((3))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/basic/journal-importer.c", 452, __func__, "Failed to store received data of size %zu "
"(in addition to existing %zu bytes with %zu filled): %s", size
, imp->size, imp->filled, strerror(12)) : -abs(_e); })
;
453 return -ENOMEM12;
454 }
455
456 memcpy(imp->buf + imp->filled, data, size);
457 imp->filled += size;
458
459 return 0;
460}
461
462void journal_importer_drop_iovw(JournalImporter *imp) {
463 size_t remain, target;
464
465 /* This function drops processed data that along with the iovw that points at it */
466
467 iovw_free_contents(&imp->iovw);
468
469 /* possibly reset buffer position */
470 remain = imp->filled - imp->offset;
471
472 if (remain == 0) /* no brainer */
473 imp->offset = imp->scanned = imp->filled = 0;
474 else if (imp->offset > imp->size - imp->filled &&
475 imp->offset > remain) {
476 memcpy(imp->buf, imp->buf + imp->offset, remain);
477 imp->offset = imp->scanned = 0;
478 imp->filled = remain;
479 }
480
481 target = imp->size;
482 while (target > 16 * LINE_CHUNK8*1024u && imp->filled < target / 2)
483 target /= 2;
484 if (target < imp->size) {
485 char *tmp;
486
487 tmp = realloc(imp->buf, target);
488 if (!tmp)
489 log_warning("Failed to reallocate buffer to (smaller) size %zu",({ int _level = (((4))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/basic/journal-importer.c", 490, __func__, "Failed to reallocate buffer to (smaller) size %zu"
, target) : -abs(_e); })
490 target)({ int _level = (((4))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/basic/journal-importer.c", 490, __func__, "Failed to reallocate buffer to (smaller) size %zu"
, target) : -abs(_e); })
;
491 else {
492 log_debug("Reallocated buffer from %zu to %zu bytes",({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/basic/journal-importer.c", 493, __func__, "Reallocated buffer from %zu to %zu bytes"
, imp->size, target) : -abs(_e); })
493 imp->size, target)({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/basic/journal-importer.c", 493, __func__, "Reallocated buffer from %zu to %zu bytes"
, imp->size, target) : -abs(_e); })
;
494 imp->buf = tmp;
495 imp->size = target;
496 }
497 }
498}
499
500bool_Bool journal_importer_eof(const JournalImporter *imp) {
501 return imp->state == IMPORTER_STATE_EOF;
502}