aboutsummaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorToni <matzeton@googlemail.com>2023-05-20 16:18:52 +0200
committerGitHub <noreply@github.com>2023-05-20 16:18:52 +0200
commit5e8f93c2d157b4af818bc80b2737ee17e920e8e9 (patch)
treefe4b1c70eb91dacfc139388c5e33dda0d3499b16 /utils
parent8f718c90519171e09e4e9877bf3c59cc6343c794 (diff)
Improved missing usage of nDPIs malloc wrapper. Fixes #1978. (#1979)
* added CI check Signed-off-by: lns <matzeton@googlemail.com>
Diffstat (limited to 'utils')
-rwxr-xr-xutils/check_symbols.sh41
1 files changed, 41 insertions, 0 deletions
diff --git a/utils/check_symbols.sh b/utils/check_symbols.sh
new file mode 100755
index 000000000..32f4fac89
--- /dev/null
+++ b/utils/check_symbols.sh
@@ -0,0 +1,41 @@
+#!/usr/bin/env sh
+
+set -e
+
+SCRIPT_DIR="$(realpath $(dirname ${0}))"
+NDPI_LIB="${1:-${SCRIPT_DIR}/../src/lib/libndpi.a}"
+
+if [ ! -r "${NDPI_LIB}" ]; then
+ printf '%s\n' "${0}: nDPI static library '$(realpath ${NDPI_LIB})' not found."
+ exit 1
+fi
+
+FAIL_COUNT=0
+CURRENT_OBJECT=''
+for line in `nm -P -u "${NDPI_LIB}"`; do
+ OBJECT="$(printf '%s' "${line}" | grep -E "^${NDPI_LIB}\[.*\.o\]:" | grep -oE "\[.*\.o\]" || true)"
+ if [ ! -z "${OBJECT}" ]; then
+ CURRENT_OBJECT="${OBJECT}"
+ fi
+
+ #printf '%s\n' "${line}"
+ FOUND_SYMBOL="$(printf '%s' "${line}" | grep '^\(malloc\|calloc\|realloc\|free\)$' || true)"
+
+ if [ ! -z "${FOUND_SYMBOL}" ]; then
+ SKIP=0
+ case "${CURRENT_OBJECT}" in
+ '[ndpi_utils.o]'|'[ndpi_memory.o]'|'[roaring.o]') SKIP=1 ;;
+ esac
+
+ if [ ${SKIP} -eq 0 ]; then
+ FAIL_COUNT="$(expr ${FAIL_COUNT} + 1)"
+ printf '%s: %s\n' "${CURRENT_OBJECT}" "${FOUND_SYMBOL}"
+ fi
+ fi
+done
+
+printf 'Unwanted symbols found: %s\n' "${FAIL_COUNT}"
+if [ ${FAIL_COUNT} -gt 0 ]; then
+ printf '%s\n' 'Please make sure to use only ndpi_malloc/ndpi_calloc/ndpi_realloc/ndpi_free wrapper instead of malloc/calloc/realloc/free'
+fi
+exit ${FAIL_COUNT}