core: rework serialization

Let's be more careful with what we serialize: let's ensure we never
serialize strings that are longer than LONG_LINE_MAX, so that we know we
can read them back with read_line(…, LONG_LINE_MAX, …) safely.

In order to implement this all serialization functions are move to
serialize.[ch], and internally will do line size checks. We'd rather
skip a serialization line (with a loud warning) than write an overly
long line out. Of course, this is just a second level protection, after
all the data we serialize shouldn't be this long in the first place.

While we are at it also clean up logging: while serializing make sure to
always log about errors immediately. Also, (void)ify all calls we don't
expect errors in (or catch errors as part of the general
fflush_and_check() at the end.
This commit is contained in:
Lennart Poettering
2018-10-26 10:52:41 +02:00
parent cdd620e346
commit d68c645bd3
31 changed files with 519 additions and 462 deletions
+4 -3
View File
@@ -12,6 +12,7 @@
#include "io-util.h"
#include "parse-util.h"
#include "random-util.h"
#include "serialize.h"
#include "socket-util.h"
#include "stdio-util.h"
#include "string-util.h"
@@ -607,13 +608,13 @@ int dynamic_user_serialize(Manager *m, FILE *f, FDSet *fds) {
copy0 = fdset_put_dup(fds, d->storage_socket[0]);
if (copy0 < 0)
return copy0;
return log_error_errno(copy0, "Failed to add dynamic user storage fd to serialization: %m");
copy1 = fdset_put_dup(fds, d->storage_socket[1]);
if (copy1 < 0)
return copy1;
return log_error_errno(copy1, "Failed to add dynamic user storage fd to serialization: %m");
fprintf(f, "dynamic-user=%s %i %i\n", d->name, copy0, copy1);
(void) serialize_item_format(f, "dynamic-user", "%s %i %i", d->name, copy0, copy1);
}
return 0;