From 46a6247593ebb2bf334b2416b9901917e5791a97 Mon Sep 17 00:00:00 2001
From: Matthias Schiffer <mschiffer@universe-factory.net>
Date: Sat, 2 Jan 2016 23:53:48 +0100
Subject: [PATCH] ar71xx: another fix to wndr3700_board_detect

---
 ...another-fix-to-wndr3700_board_detect.patch | 29 +++++++++++++++++++
 1 file changed, 29 insertions(+)
 create mode 100644 patches/openwrt/0050-ar71xx-another-fix-to-wndr3700_board_detect.patch

diff --git a/patches/openwrt/0050-ar71xx-another-fix-to-wndr3700_board_detect.patch b/patches/openwrt/0050-ar71xx-another-fix-to-wndr3700_board_detect.patch
new file mode 100644
index 000000000..5a1c79e1c
--- /dev/null
+++ b/patches/openwrt/0050-ar71xx-another-fix-to-wndr3700_board_detect.patch
@@ -0,0 +1,29 @@
+From: Matthias Schiffer <mschiffer@universe-factory.net>
+Date: Sat, 2 Jan 2016 23:36:25 +0100
+Subject: ar71xx: another fix to wndr3700_board_detect
+
+My last bugfix (r47538) introduced a new bug in wndr3700_board_detect
+(again...).
+
+Assigning the result of ar71xx_get_mtd_offset_size_format to the model
+variable before stripping of garbage using awk will cause all NUL bytes to
+be removed before awk is applied, leading to model strings like
+"NETGEAR WNDRMACv2NETGEAR", where a NUL byte after the v2 is supposed to
+terminate the string.
+
+Fix by calling ar71xx_get_mtd_offset_size_format twice, once piping to awk
+directly.
+
+diff --git a/target/linux/ar71xx/base-files/lib/ar71xx.sh b/target/linux/ar71xx/base-files/lib/ar71xx.sh
+index 1f341e3..b411e80 100755
+--- a/target/linux/ar71xx/base-files/lib/ar71xx.sh
++++ b/target/linux/ar71xx/base-files/lib/ar71xx.sh
+@@ -39,7 +39,7 @@ wndr3700_board_detect() {
+ 	"33373031")
+ 		model="$(ar71xx_get_mtd_offset_size_format art 41 32 %c)"
+ 		# Use awk to remove everything unprintable
+-		model_stripped="$(echo -n "$model" | LC_CTYPE=C awk -v 'FS=[^[:print:]]' '{print $1; exit}')"
++		model_stripped="$(ar71xx_get_mtd_offset_size_format art 41 32 %c | LC_CTYPE=C awk -v 'FS=[^[:print:]]' '{print $1; exit}')"
+ 		case $model in
+ 		$'\xff'*)
+ 			if [ "${model:24:1}" = 'N' ]; then
-- 
GitLab