diff options
author | markster <markster@f38db490-d61c-443f-a65b-d21fe96a405b> | 2004-10-14 04:12:05 +0000 |
---|---|---|
committer | markster <markster@f38db490-d61c-443f-a65b-d21fe96a405b> | 2004-10-14 04:12:05 +0000 |
commit | e53edbed56a6786eb2a01efefa713dbd44b2cccc (patch) | |
tree | 858128021d59bbc84e79620591009d9c51804c37 /cli.c | |
parent | 66dcd2d9a2f7476967af55e8adb998574ae7dddb (diff) |
Handle excessive entries properly (bug #2634)
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@3994 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'cli.c')
-rwxr-xr-x | cli.c | 18 |
1 files changed, 12 insertions, 6 deletions
@@ -437,11 +437,11 @@ static char *__ast_cli_generator(char *text, char *word, int state, int lock); static int handle_commandmatchesarray(int fd, int argc, char *argv[]) { - char *buf; + char *buf, *obuf; int buflen = 2048; int len = 0; char **matches; - int x; + int x, matchlen; if (argc != 4) return RESULT_SHOWUSAGE; @@ -455,11 +455,17 @@ static int handle_commandmatchesarray(int fd, int argc, char *argv[]) #if 0 printf("command matchesarray for '%s' %s got '%s'\n", argv[2], argv[3], matches[x]); #endif - if (len + strlen(matches[x]) >= buflen) { - buflen += strlen(matches[x]) * 3; - buf = realloc(buf, buflen); + matchlen = strlen(matches[x]) + 1; + if (len + matchlen >= buflen) { + buflen += matchlen * 3; + obuf = buf; + buf = realloc(obuf, buflen); + if (!buf) + /* Out of memory... Just free old buffer and be done */ + free(obuf); } - len += sprintf( buf + len, "%s ", matches[x]); + if (buf) + len += sprintf( buf + len, "%s ", matches[x]); free(matches[x]); matches[x] = NULL; } |