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:
@@ -0,0 +1,23 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
#pragma once
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "fdset.h"
|
||||
#include "macro.h"
|
||||
|
||||
int serialize_item(FILE *f, const char *key, const char *value);
|
||||
int serialize_item_escaped(FILE *f, const char *key, const char *value);
|
||||
int serialize_item_format(FILE *f, const char *key, const char *value, ...) _printf_(3,4);
|
||||
int serialize_fd(FILE *f, FDSet *fds, const char *key, int fd);
|
||||
int serialize_usec(FILE *f, const char *key, usec_t usec);
|
||||
int serialize_dual_timestamp(FILE *f, const char *key, const dual_timestamp *t);
|
||||
int serialize_strv(FILE *f, const char *key, char **l);
|
||||
|
||||
static inline int serialize_bool(FILE *f, const char *key, bool b) {
|
||||
return serialize_item(f, key, yes_no(b));
|
||||
}
|
||||
|
||||
int deserialize_usec(const char *value, usec_t *timestamp);
|
||||
int deserialize_dual_timestamp(const char *value, dual_timestamp *t);
|
||||
int deserialize_environment(const char *value, char ***environment);
|
||||
Reference in New Issue
Block a user