[Android] compile.sh: local.properties init: fix regex matching android sdk/ ndk variables.

Robert Mourning git at videolan.org
Tue Jan 30 17:06:23 CET 2018


vlc-android | branch: master | Robert Mourning <robedmo.git at gmail.com> | Sat Jan 27 05:39:42 2018 -0500| [eed01ac18e8576818be69a81843a06a8ccc86052] | committer: Geoffrey Métais

compile.sh: local.properties init: fix regex matching android sdk/ndk variables.

grep was interpreting the variables as regexes intended to
match themselves. this could cause errors or false positives/negatives if the
variables contain regex metacharacters. now the variables are escaped to
produce regexes that will always and only match themselves.

Signed-off-by: Geoffrey Métais <geoffrey.metais at gmail.com>

> https://code.videolan.org/videolan/vlc-android/commit/eed01ac18e8576818be69a81843a06a8ccc86052
---

 compile.sh | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/compile.sh b/compile.sh
index 0f650204c..01614f4e1 100755
--- a/compile.sh
+++ b/compile.sh
@@ -176,14 +176,20 @@ init_local_props() {
         echo_props > "$1"
         return 0
     fi
+    # escape special chars to get regex that matches string
+    make_regex() {
+        echo "$1" | sed -e 's/\([[\^$.*]\)/\\\1/g' -
+    }
+    android_sdk_regex=`make_regex "${ANDROID_SDK}"`
+    android_ndk_regex=`make_regex "${ANDROID_NDK}"`
     # check for lines setting the SDK directory
     sdk_line_start="^sdk\.dir="
     total_sdk_count=`grep -c "${sdk_line_start}" "$1"`
-    good_sdk_count=`grep -c "${sdk_line_start}${ANDROID_SDK}\$" "$1"`
+    good_sdk_count=`grep -c "${sdk_line_start}${android_sdk_regex}\$" "$1"`
     # check for lines setting the NDK directory
     ndk_line_start="^ndk\.dir="
     total_ndk_count=`grep -c "${ndk_line_start}" "$1"`
-    good_ndk_count=`grep -c "${ndk_line_start}${ANDROID_NDK}\$" "$1"`
+    good_ndk_count=`grep -c "${ndk_line_start}${android_ndk_regex}\$" "$1"`
     # if one of each is found and both match the environment vars, no action needed
     if [ "$total_sdk_count" -eq "1" -a "$good_sdk_count" -eq "1" \
 	    -a "$total_ndk_count" -eq "1" -a "$good_ndk_count" -eq "1" ]



More information about the Android mailing list