[posix] avoid CLI buffer overflow (#6578)

This commit is contained in:
Yakun Xu
2021-05-10 21:19:12 -07:00
committed by GitHub
parent 9432e9a659
commit 7721a5119f
4 changed files with 32 additions and 10 deletions
+14
View File
@@ -134,6 +134,20 @@ do_check()
sudo "${OT_CTL}" -I "${NETIF_NAME}" factoryreset
# sleep a while for daemon ready
sleep 2
readonly OPENTHREAD_CONFIG_CLI_MAX_LINE_LENGTH=640
local -r kMaxStringLength="$((OPENTHREAD_CONFIG_CLI_MAX_LINE_LENGTH - 1))"
# verify success if command length doesn't exceed the limit
for len in $(seq 1 ${kMaxStringLength}); do
sudo "${OT_CTL}" -I "${NETIF_NAME}" "$(printf '1%.0s' $(seq 1 "${len}"))"
done
# verify failure if command length exceeds the limit
len=${OPENTHREAD_CONFIG_CLI_MAX_LINE_LENGTH}
if sudo "${OT_CTL}" -I "${NETIF_NAME}" "$(printf '1%.0s' $(seq 1 "${len}"))"; then
die
fi
OT_CLI_CMD="${OT_CTL} -I ${NETIF_NAME}"
else
OT_CLI="$PWD/build/posix/src/posix/ot-cli"