[asterisk-commits] tilghman: branch 1.4 r167840 - /branches/1.4/res/res_agi.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Jan 8 16:08:56 CST 2009


Author: tilghman
Date: Thu Jan  8 16:08:56 2009
New Revision: 167840

URL: http://svn.digium.com/view/asterisk?view=rev&rev=167840
Log:
Don't truncate database results at 255 chars.
(closes issue #14069)
 Reported by: evandro
 Patches: 
       20081214__bug14069.diff.txt uploaded by Corydon76 (license 14)

Modified:
    branches/1.4/res/res_agi.c

Modified: branches/1.4/res/res_agi.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/res/res_agi.c?view=diff&rev=167840&r1=167839&r2=167840
==============================================================================
--- branches/1.4/res/res_agi.c (original)
+++ branches/1.4/res/res_agi.c Thu Jan  8 16:08:56 2009
@@ -1262,16 +1262,35 @@
 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;
 }
 




More information about the asterisk-commits mailing list