]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Don't truncate database results at 255 chars.
authorTilghman Lesher <tilghman@meg.abyt.es>
Thu, 8 Jan 2009 22:08:56 +0000 (22:08 +0000)
committerTilghman Lesher <tilghman@meg.abyt.es>
Thu, 8 Jan 2009 22:08:56 +0000 (22:08 +0000)
(closes issue #14069)
 Reported by: evandro
 Patches:
       20081214__bug14069.diff.txt uploaded by Corydon76 (license 14)

git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.4@167840 65c4cc65-6c06-0410-ace0-fbb531ad65f3

res/res_agi.c

index 40c15da8265b2cebe487bea07c8111670be3d2c4..ae19c4bf4e138bd716c13645866126bf5795978b 100644 (file)
@@ -1262,16 +1262,35 @@ static int handle_verbose(struct ast_channel *chan, AGI *agi, int argc, char **a
 static int handle_dbget(struct ast_channel *chan, AGI *agi, int argc, char **argv)
 {
        int res;
-       char tmp[256];
+       size_t bufsize = 16;
+       char *buf, *tmp;
 
        if (argc != 4)
                return RESULT_SHOWUSAGE;
-       res = ast_db_get(argv[2], argv[3], tmp, sizeof(tmp));
+
+       if (!(buf = ast_malloc(bufsize))) {
+               fdprintf(agi->fd, "200 result=-1\n");
+               return RESULT_SUCCESS;
+       }
+
+       do {
+               res = ast_db_get(argv[2], argv[3], buf, bufsize);
+               if (strlen(buf) < bufsize - 1) {
+                       break;
+               }
+               bufsize *= 2;
+               if (!(tmp = ast_realloc(buf, bufsize))) {
+                       break;
+               }
+               buf = tmp;
+       } while (1);
+       
        if (res) 
                fdprintf(agi->fd, "200 result=0\n");
        else
-               fdprintf(agi->fd, "200 result=1 (%s)\n", tmp);
+               fdprintf(agi->fd, "200 result=1 (%s)\n", buf);
 
+       ast_free(buf);
        return RESULT_SUCCESS;
 }