about summary refs log tree commit diff
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
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 '')
-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;
9e22f1f13378bc1909071d35d7e13c42&follow=1'>Use curl error bufferJune McEnroe 2019-09-10Set Accept-Encoding in titleJune McEnroe 2019-09-08Set title User-AgentJune McEnroe 2019-09-07Add -x flag to titleJune McEnroe 2019-09-07Ignore SIGPIPE in relayJune McEnroe 2019-09-07Add A Memory Called EmpireJune McEnroe 2019-09-05Handle lack of Content-TypeJune McEnroe 2019-09-05Use CURLINFO_CONTENT_TYPEJune McEnroe 2019-09-05Decode entities in titlesJune McEnroe 2019-09-05Print title as soon as it's availableJune McEnroe 2019-09-05Use CURL_PREFIX to set flagsJune McEnroe 2019-09-05Add titleJune McEnroe 2019-09-04Add Avorter n'est pas tuerJune McEnroe 2019-08-29Unset executable on shell scriptsJune McEnroe 2019-08-29Add long-missing setopt to bin.7June McEnroe 2019-08-29Add editJune McEnroe