summaryrefslogtreecommitdiff
path: root/config.c
diff options
context:
space:
mode:
authormrb0nk500 <b0nk@b0nk.xyz>2021-06-11 19:38:57 -0400
committermrb0nk500 <b0nk@b0nk.xyz>2021-06-11 19:38:57 -0400
commitbfd3904c4439680060948402ed546ffa3532be67 (patch)
tree8569e086590165b50356530aed300a81cedb070c /config.c
parent27f41f410d78403abecbaf9264d8a9abbac39f32 (diff)
Change `port` from an int to a string, and move the
valid port check into the config parser.
Diffstat (limited to 'config.c')
-rw-r--r--config.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/config.c b/config.c
index 5f464d1..26ad023 100644
--- a/config.c
+++ b/config.c
@@ -2,6 +2,7 @@
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
+#include <syslog.h>
#include "config.h"
char *read_file(const char *filename, long *size) {
@@ -152,6 +153,16 @@ config *parse_config(const char *filename) {
/* Is the config option valid? */
if (opt->name != NULL) {
config_val val = parse_option_value(opt, value);
+ if (opt->offset == offsetof(config, port)) {
+ const int port = strtol(val.str, NULL, 0);
+ if (port <= 0 || port > 65535) {
+ syslog(LOG_ERR, "Invalid port %d. (Valid port must be between 1, and 65535.)", port);
+ cleanup_config(cfg);
+ free(line);
+ free(buf);
+ return NULL;
+ }
+ }
set_config_opt(cfg, opt->type, opt->offset, val);
}