Bugfix: API: Report errors from poolpriority command
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
diff --git a/api.c b/api.c
index 86de3c8..4e1da9a 100644
--- a/api.c
+++ b/api.c
@@ -2139,7 +2139,7 @@ static void poolpriority(__maybe_unused SOCKETTYPE c, char *param, bool isjson,
SETUP_STRTOK_TS;
int total_pools_ = total_pools; // Keep a local copy, to be more threadsafe
char *a;
- int i, prio = 0;
+ int i, prio = 0, e = -1;
if (total_pools_ == 0) {
strcpy(io_buffer, message(MSG_NOPOOL, 0, NULL, isjson));
@@ -2152,7 +2152,11 @@ static void poolpriority(__maybe_unused SOCKETTYPE c, char *param, bool isjson,
a = strtok_ts(param, ",");
do {
- i = atoi(a);
+ i = strtol(a, &a, 10);
+ if (unlikely(*a > 0x20 || i < 0 || i >= total_pools)) {
+ e = (*a > 0x20) ? -2 : i;
+ continue;
+ }
pools[i]->prio = prio++;
pools_changed[i] = true;
} while ( (a = strtok_ts(NULL, ",")) );
@@ -2164,6 +2168,14 @@ static void poolpriority(__maybe_unused SOCKETTYPE c, char *param, bool isjson,
if (current_pool()->prio)
switch_pools(NULL);
+ if (e != -1) {
+ if (e == -2)
+ strcpy(io_buffer, message(MSG_MISPID, 0, NULL, isjson));
+ else
+ strcpy(io_buffer, message(MSG_INVPID, e, NULL, isjson));
+ return;
+ }
+
strcpy(io_buffer, message(MSG_POOLPRIO, 0, NULL, isjson));
}