From 9ba1a1598549148fdc9bd7e1b6b7c3b12b2ea958 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 31 Jan 2012 20:53:34 +0100 Subject: [PATCH] load-fragment: properly parse size values denoted in bytes --- src/conf-parser.c | 66 ++++++++++++++++---------------- src/conf-parser.h | 4 +- src/journal/journald-gperf.gperf | 30 +++++++-------- src/load-fragment-gperf.gperf.m4 | 6 +-- src/load-fragment.c | 2 +- 5 files changed, 54 insertions(+), 54 deletions(-) diff --git a/src/conf-parser.c b/src/conf-parser.c index ac8d9f5ac..c7dd01aa1 100644 --- a/src/conf-parser.c +++ b/src/conf-parser.c @@ -454,7 +454,7 @@ int config_parse_unsigned( return 0; } -int config_parse_size( +int config_parse_bytes_size( const char *filename, unsigned line, const char *section, @@ -465,20 +465,47 @@ int config_parse_size( void *userdata) { size_t *sz = data; - unsigned u; - int r; + off_t o; assert(filename); assert(lvalue); assert(rvalue); assert(data); - if ((r = safe_atou(rvalue, &u)) < 0) { - log_error("[%s:%u] Failed to parse numeric value, ignoring: %s", filename, line, rvalue); + if (parse_bytes(rvalue, &o) < 0 || (off_t) (size_t) o != o) { + log_error("[%s:%u] Failed to parse byte value, ignoring: %s", filename, line, rvalue); + return 0; + } + + *sz = (size_t) o; + return 0; +} + + +int config_parse_bytes_off( + const char *filename, + unsigned line, + const char *section, + const char *lvalue, + int ltype, + const char *rvalue, + void *data, + void *userdata) { + + off_t *bytes = data; + + assert(filename); + assert(lvalue); + assert(rvalue); + assert(data); + + assert_cc(sizeof(off_t) == sizeof(uint64_t)); + + if (parse_bytes(rvalue, bytes) < 0) { + log_error("[%s:%u] Failed to parse bytes value, ignoring: %s", filename, line, rvalue); return 0; } - *sz = (size_t) u; return 0; } @@ -782,30 +809,3 @@ int config_parse_mode( *m = (mode_t) l; return 0; } - -int config_parse_bytes( - const char *filename, - unsigned line, - const char *section, - const char *lvalue, - int ltype, - const char *rvalue, - void *data, - void *userdata) { - - off_t *bytes = data; - - assert(filename); - assert(lvalue); - assert(rvalue); - assert(data); - - assert_cc(sizeof(off_t) == sizeof(uint64_t)); - - if (parse_bytes(rvalue, bytes) < 0) { - log_error("[%s:%u] Failed to parse bytes value, ignoring: %s", filename, line, rvalue); - return 0; - } - - return 0; -} diff --git a/src/conf-parser.h b/src/conf-parser.h index 35edcb63a..be7d70817 100644 --- a/src/conf-parser.h +++ b/src/conf-parser.h @@ -93,7 +93,8 @@ int config_parse_int(const char *filename, unsigned line, const char *section, c int config_parse_unsigned(const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); int config_parse_long(const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); int config_parse_uint64(const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); -int config_parse_size(const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); +int config_parse_bytes_size(const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); +int config_parse_bytes_off(const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); int config_parse_bool(const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); int config_parse_tristate(const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); int config_parse_string(const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); @@ -102,7 +103,6 @@ int config_parse_strv(const char *filename, unsigned line, const char *section, int config_parse_path_strv(const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); int config_parse_usec(const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); int config_parse_mode(const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); -int config_parse_bytes(const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); #define DEFINE_CONFIG_PARSE_ENUM(function,name,type,msg) \ int function( \ diff --git a/src/journal/journald-gperf.gperf b/src/journal/journald-gperf.gperf index e25ba2c72..a56f6d966 100644 --- a/src/journal/journald-gperf.gperf +++ b/src/journal/journald-gperf.gperf @@ -14,18 +14,18 @@ struct ConfigPerfItem; %struct-type %includes %% -Journal.RateLimitInterval, config_parse_usec, 0, offsetof(Server, rate_limit_interval) -Journal.RateLimitBurst, config_parse_unsigned, 0, offsetof(Server, rate_limit_burst) -Journal.Compress, config_parse_bool, 0, offsetof(Server, compress) -Journal.SystemMaxUse, config_parse_bytes, 0, offsetof(Server, system_metrics.max_use) -Journal.SystemMaxFileSize, config_parse_bytes, 0, offsetof(Server, system_metrics.max_size) -Journal.SystemMinFileSize, config_parse_bytes, 0, offsetof(Server, system_metrics.min_size) -Journal.SystemKeepFree, config_parse_bytes, 0, offsetof(Server, system_metrics.keep_free) -Journal.RuntimeMaxUse, config_parse_bytes, 0, offsetof(Server, runtime_metrics.max_use) -Journal.RuntimeMaxFileSize, config_parse_bytes, 0, offsetof(Server, runtime_metrics.max_size) -Journal.RuntimeMinFileSize, config_parse_bytes, 0, offsetof(Server, runtime_metrics.min_size) -Journal.RuntimeKeepFree, config_parse_bytes, 0, offsetof(Server, runtime_metrics.keep_free) -Journal.ForwardToSyslog, config_parse_bool, 0, offsetof(Server, forward_to_syslog) -Journal.ForwardToKMsg, config_parse_bool, 0, offsetof(Server, forward_to_kmsg) -Journal.ForwardToConsole, config_parse_bool, 0, offsetof(Server, forward_to_console) -Journal.ImportKernel, config_parse_bool, 0, offsetof(Server, import_proc_kmsg) +Journal.RateLimitInterval, config_parse_usec, 0, offsetof(Server, rate_limit_interval) +Journal.RateLimitBurst, config_parse_unsigned, 0, offsetof(Server, rate_limit_burst) +Journal.Compress, config_parse_bool, 0, offsetof(Server, compress) +Journal.SystemMaxUse, config_parse_bytes_off, 0, offsetof(Server, system_metrics.max_use) +Journal.SystemMaxFileSize, config_parse_bytes_off, 0, offsetof(Server, system_metrics.max_size) +Journal.SystemMinFileSize, config_parse_bytes_off, 0, offsetof(Server, system_metrics.min_size) +Journal.SystemKeepFree, config_parse_bytes_off, 0, offsetof(Server, system_metrics.keep_free) +Journal.RuntimeMaxUse, config_parse_bytes_off, 0, offsetof(Server, runtime_metrics.max_use) +Journal.RuntimeMaxFileSize, config_parse_bytes_off, 0, offsetof(Server, runtime_metrics.max_size) +Journal.RuntimeMinFileSize, config_parse_bytes_off, 0, offsetof(Server, runtime_metrics.min_size) +Journal.RuntimeKeepFree, config_parse_bytes_off, 0, offsetof(Server, runtime_metrics.keep_free) +Journal.ForwardToSyslog, config_parse_bool, 0, offsetof(Server, forward_to_syslog) +Journal.ForwardToKMsg, config_parse_bool, 0, offsetof(Server, forward_to_kmsg) +Journal.ForwardToConsole, config_parse_bool, 0, offsetof(Server, forward_to_console) +Journal.ImportKernel, config_parse_bool, 0, offsetof(Server, import_proc_kmsg) diff --git a/src/load-fragment-gperf.gperf.m4 b/src/load-fragment-gperf.gperf.m4 index 8ca799ef2..14c060616 100644 --- a/src/load-fragment-gperf.gperf.m4 +++ b/src/load-fragment-gperf.gperf.m4 @@ -171,12 +171,12 @@ Socket.Accept, config_parse_bool, 0, Socket.MaxConnections, config_parse_unsigned, 0, offsetof(Socket, max_connections) Socket.KeepAlive, config_parse_bool, 0, offsetof(Socket, keep_alive) Socket.Priority, config_parse_int, 0, offsetof(Socket, priority) -Socket.ReceiveBuffer, config_parse_size, 0, offsetof(Socket, receive_buffer) -Socket.SendBuffer, config_parse_size, 0, offsetof(Socket, send_buffer) +Socket.ReceiveBuffer, config_parse_bytes_size, 0, offsetof(Socket, receive_buffer) +Socket.SendBuffer, config_parse_bytes_size, 0, offsetof(Socket, send_buffer) Socket.IPTOS, config_parse_ip_tos, 0, offsetof(Socket, ip_tos) Socket.IPTTL, config_parse_int, 0, offsetof(Socket, ip_ttl) Socket.Mark, config_parse_int, 0, offsetof(Socket, mark) -Socket.PipeSize, config_parse_size, 0, offsetof(Socket, pipe_size) +Socket.PipeSize, config_parse_bytes_size, 0, offsetof(Socket, pipe_size) Socket.FreeBind, config_parse_bool, 0, offsetof(Socket, free_bind) Socket.Transparent, config_parse_bool, 0, offsetof(Socket, transparent) Socket.Broadcast, config_parse_bool, 0, offsetof(Socket, broadcast) diff --git a/src/load-fragment.c b/src/load-fragment.c index deae2dc0a..b2d43fb73 100644 --- a/src/load-fragment.c +++ b/src/load-fragment.c @@ -2337,7 +2337,7 @@ void unit_dump_config_items(FILE *f) { } table[] = { { config_parse_int, "INTEGER" }, { config_parse_unsigned, "UNSIGNED" }, - { config_parse_size, "SIZE" }, + { config_parse_bytes_size, "SIZE" }, { config_parse_bool, "BOOLEAN" }, { config_parse_string, "STRING" }, { config_parse_path, "PATH" }, -- 2.30.2