]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
res_realtime: Fix 'realtime update2' argument handling
authorSean Bright <sean.bright@gmail.com>
Mon, 13 Jan 2020 22:37:00 +0000 (17:37 -0500)
committerSean Bright <sean.bright@gmail.com>
Tue, 14 Jan 2020 16:07:06 +0000 (10:07 -0600)
The change in 9b99ef50b5d01ee8111d26efa7b926bdfaf3f980 updated the
syntax of the 'realtime update2' CLI command but did not correctly
update the calls to ast_update2_realtime().

The issue this addresses was originally opened because we aren't
allowing a SQL NULL to be set as part of the update, but this is a
limitation of the Realtime API and is not a bug.

Additionally, this patch:

* Corrects the example in the command documentation to reflect
  'update2' instead of 'update.'

* Fixes the leading spacing of the command documentation.

* Checks that the required 'NULL' literal argument is present where we
  expect it to be.

ASTERISK-21794 #close
Reported by: Cédric Bassaget

Change-Id: Idda63a5dc50d5f9bcb34c27ea3238d90f733b2cd

res/res_realtime.c

index 9a8e6482c2421254ba5dc36dd55ff0a21d769b87..d57c2d8ccc75bfe9c179329c34c6ff315b1a0989 100644 (file)
@@ -122,32 +122,50 @@ static char *cli_realtime_update2(struct ast_cli_entry *e, int cmd, struct ast_c
                e->command = "realtime update2";
                e->usage =
                        "Usage: realtime update2 <family> <colmatch> <valuematch> [... <colmatch5> <valuematch5>] NULL <colupdate> <newvalue>\n"
-                       "   Update a single variable, requiring one or more fields to match using the\n"
-                       "   RealTime driver.  You must supply a family name, a column to update, a new\n"
-                       "   value, and at least one column and value to match.\n"
-                       "   Ex: realtime update sippeers name bobsphone ipaddr 127.0.0.1 NULL port 4343\n"
-                       "   will execute SQL as\n"
-                       "   UPDATE sippeers SET port='4343' WHERE name='bobsphone' and ipaddr='127.0.0.1'\n";
+                       "       Update a single variable, requiring one or more fields to match using the\n"
+                       "       RealTime driver. You must supply a family name, a column to update, a new\n"
+                       "       value, and at least one column and value to match.\n"
+                       "       Ex: realtime update2 sippeers name bobsphone ipaddr 127.0.0.1 NULL port 4343\n"
+                       "       will execute SQL as\n"
+                       "       UPDATE sippeers SET port='4343' WHERE name='bobsphone' and ipaddr='127.0.0.1'\n";
                return NULL;
        case CLI_GENERATE:
                return NULL;
        }
 
-       if (a->argc < 7)
+       /* Make sure we have the right number of arguments and that the required literal NULL
+          is present */
+       if (a->argc < 8 || a->argc > 16 || a->argc % 2
+          || strcmp(a->argv[a->argc - 3], "NULL")) {
                return CLI_SHOWUSAGE;
+       }
 
-       if (a->argc == 7) {
-               res = ast_update2_realtime(a->argv[2], a->argv[3], a->argv[4], SENTINEL, a->argv[5], a->argv[6], SENTINEL);
-       } else if (a->argc == 9) {
-               res = ast_update2_realtime(a->argv[2], a->argv[3], a->argv[4], a->argv[5], a->argv[6], SENTINEL, a->argv[7], a->argv[8], SENTINEL);
-       } else if (a->argc == 11) {
-               res = ast_update2_realtime(a->argv[2], a->argv[3], a->argv[4], a->argv[5], a->argv[6], a->argv[7], a->argv[8], SENTINEL, a->argv[9], a->argv[10], SENTINEL);
-       } else if (a->argc == 13) {
-               res = ast_update2_realtime(a->argv[2], a->argv[3], a->argv[4], a->argv[5], a->argv[6], a->argv[7], a->argv[8], a->argv[9], a->argv[10], SENTINEL, a->argv[11], a->argv[12], SENTINEL);
-       } else if (a->argc == 15) {
-               res = ast_update2_realtime(a->argv[2], a->argv[3], a->argv[4], a->argv[5], a->argv[6], a->argv[7], a->argv[8], a->argv[9], a->argv[10], a->argv[11], a->argv[12], SENTINEL, a->argv[13], a->argv[14], SENTINEL);
-       } else {
-               return CLI_SHOWUSAGE;
+       if (a->argc == 8) {
+               res = ast_update2_realtime(
+                       a->argv[2], a->argv[3], a->argv[4], SENTINEL,
+                       a->argv[6], a->argv[7], SENTINEL);
+       } else if (a->argc == 10) {
+               res = ast_update2_realtime(
+                       a->argv[2], a->argv[3], a->argv[4], a->argv[5],
+                       a->argv[6], SENTINEL,
+                       a->argv[8], a->argv[9], SENTINEL);
+       } else if (a->argc == 12) {
+               res = ast_update2_realtime(
+                       a->argv[2], a->argv[3], a->argv[4], a->argv[5],
+                       a->argv[6], a->argv[7], a->argv[8], SENTINEL,
+                       a->argv[10], a->argv[11], SENTINEL);
+       } else if (a->argc == 14) {
+               res = ast_update2_realtime(
+                       a->argv[2], a->argv[3], a->argv[4], a->argv[5],
+                       a->argv[6], a->argv[7], a->argv[8], a->argv[9],
+                       a->argv[10], SENTINEL,
+                       a->argv[12], a->argv[13], SENTINEL);
+       } else if (a->argc == 16) {
+               res = ast_update2_realtime(
+                       a->argv[2], a->argv[3], a->argv[4], a->argv[5],
+                       a->argv[6], a->argv[7], a->argv[8], a->argv[9],
+                       a->argv[10], a->argv[11], a->argv[12], SENTINEL,
+                       a->argv[14], a->argv[15], SENTINEL);
        }
 
        if (res < 0) {