diff options
author | Yuan Yuan <yyuanam@amazon.com> | 2023-05-30 21:20:09 +0200 |
---|---|---|
committer | Yuan Yuan <yyuanam@amazon.com> | 2023-05-31 22:30:03 +0200 |
commit | f8aa257997a6a6f69ec5d5715ab04d7cbfae1d1c (patch) | |
tree | 6cb19ceaeb2df6fc7b91bac1308966df12aa1c43 | |
parent | Merge pull request #13631 from donaldsharp/fix_some_ping_issues (diff) | |
download | frr-f8aa257997a6a6f69ec5d5715ab04d7cbfae1d1c.tar.xz frr-f8aa257997a6a6f69ec5d5715ab04d7cbfae1d1c.zip |
lib: fix vtysh core when handling questionmark
When issue vtysh command with ?, the initial buf size for the
element is 16. Then it would loop through each element in the cmd
output vector. If the required size for printing out the next
element is larger than the current buf size, realloc the buf memory
by doubling the current buf size regardless of the actual size
that's needed. This would cause vtysh core when the doubled size
is not enough for the next element.
Signed-off-by: Yuan Yuan <yyuanam@amazon.com>
-rw-r--r-- | lib/command.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/lib/command.c b/lib/command.c index e92251160..099563721 100644 --- a/lib/command.c +++ b/lib/command.c @@ -735,9 +735,13 @@ char *cmd_variable_comp2str(vector comps, unsigned short cols) char *item = vector_slot(comps, j); itemlen = strlen(item); - if (cs + itemlen + AUTOCOMP_INDENT + 3 >= bsz) - buf = XREALLOC(MTYPE_TMP, buf, (bsz *= 2)); + size_t next_sz = cs + itemlen + AUTOCOMP_INDENT + 3; + if (next_sz > bsz) { + /* Make sure the buf size is large enough */ + bsz = next_sz; + buf = XREALLOC(MTYPE_TMP, buf, bsz); + } if (lc + itemlen + 1 >= cols) { cs += snprintf(&buf[cs], bsz - cs, "\n%*s", AUTOCOMP_INDENT, ""); |