summary refs log tree commit diff
path: root/extra
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2022-06-17 23:08:13 -0400
committerJune McEnroe <june@causal.agency>2022-06-17 23:08:13 -0400
commit48d4c180355258edf63b72e566846e9c5a8c7f32 (patch)
tree0e4e4b87e27e670fd6833264ccdc313ecf763abf /extra
parentFix uninit read when checking if bindPath is a directory (diff)
downloadpounce-48d4c180355258edf63b72e566846e9c5a8c7f32.tar.gz
pounce-48d4c180355258edf63b72e566846e9c5a8c7f32.zip
edit: Validate size is power of two
Diffstat (limited to 'extra')
-rw-r--r--extra/edit/edit.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/extra/edit/edit.c b/extra/edit/edit.c
index 51c913c..793e413 100644
--- a/extra/edit/edit.c
+++ b/extra/edit/edit.c
@@ -236,7 +236,6 @@ static const char *Boolean[] = {
 	"no-names", "no-sts", "palaver", "sasl-external", "verbose",
 };
 
-// FIXME: size needs to be validated for power of two
 static const char *Integer[] = {
 	"local-port", "port", "queue-interval", "size",
 };
@@ -290,8 +289,12 @@ static const char *validate(const char *name, const char *value) {
 		if (!safe(name)) return "cannot be set";
 		if (!value) return "requires a value";
 		char *end;
-		strtoul(value, &end, 10);
-		return (!*value || *end ? "must be an integer" : NULL);
+		size_t n = strtoull(value, &end, 10);
+		if (!*value || *end) return "must be an integer";
+		if (!strcmp(name, "size") && (!n || n & (n-1))) {
+			return "must be a power of two";
+		}
+		return NULL;
 	}
 	for (size_t i = 0; i < ARRAY_LEN(String); ++i) {
 		if (strcmp(String[i], name)) continue;