From 74c840c3ac1388b8b48956b59152cf136f4a5613 Mon Sep 17 00:00:00 2001
From: Bastian Bittorf <bittorf@bluebottle.com>
Date: Fri, 25 Apr 2014 10:12:05 -0400
Subject: [PATCH] [base-files]
 target/linux/*/base-files/lib/upgrade/platform.sh - wrong
 check for ARGC

ARGC is a 'C-ism', but not known/valid in shell-syntax - insert the correct
var $# (=number of args) here. under normal conditions this had no impact,
but we should at least correct it. the error was observable like this:

root@box:~ [ -e "/etc/functions.sh" ] && . /etc/functions.sh
root@box:~ [ -e "/lib/functions.sh" ] && . /lib/functions.sh
root@box:~ . /lib/upgrade/platform.sh
root@box:~ . /lib/upgrade/common.sh
root@box:~ platform_check_image /tmp/myfirmware.bin
ash: bad number
root@box:~ echo $?
0

Signed-off-by: Bastian Bittorf <bittorf@bluebottle.com>
---
 target/linux/adm5120/base-files/lib/upgrade/platform.sh  |    2 +-
 target/linux/adm8668/base-files/lib/upgrade/platform.sh  |    2 +-
 target/linux/ar71xx/base-files/lib/upgrade/platform.sh   |    2 +-
 target/linux/atheros/base-files/lib/upgrade/platform.sh  |    2 +-
 target/linux/au1000/base-files/lib/upgrade/platform.sh   |    2 +-
 target/linux/avr32/base-files/lib/upgrade/platform.sh    |    2 +-
 target/linux/brcm47xx/base-files/lib/upgrade/platform.sh |    2 +-
 target/linux/brcm63xx/base-files/lib/upgrade/platform.sh |    2 +-
 target/linux/cns21xx/base-files/lib/upgrade/platform.sh  |    2 +-
 target/linux/cns3xxx/base-files/lib/upgrade/platform.sh  |    2 +-
 target/linux/ixp4xx/base-files/lib/upgrade/platform.sh   |    2 +-
 target/linux/lantiq/base-files/lib/upgrade/platform.sh   |    2 +-
 target/linux/mpc85xx/base-files/lib/upgrade/platform.sh  |    2 +-
 target/linux/ppc40x/base-files/lib/upgrade/platform.sh   |    2 +-
 target/linux/ramips/base-files/lib/upgrade/platform.sh   |    2 +-
 target/linux/x86/base-files/lib/upgrade/platform.sh      |    2 +-
 target/linux/x86/olpc/base-files/lib/upgrade/platform.sh |    2 +-
 target/linux/x86_64/base-files/lib/upgrade/platform.sh   |    2 +-
 18 files changed, 18 insertions(+), 18 deletions(-)

diff --git a/target/linux/adm5120/base-files/lib/upgrade/platform.sh b/target/linux/adm5120/base-files/lib/upgrade/platform.sh
index f067089..fab2b3d 100644
--- a/target/linux/adm5120/base-files/lib/upgrade/platform.sh
+++ b/target/linux/adm5120/base-files/lib/upgrade/platform.sh
@@ -10,7 +10,7 @@ RAMFS_COPY_DATA=/lib/adm5120.sh
 platform_check_image() {
 	local magic="$(get_magic_word "$1")"
 
-	[ "$ARGC" -gt 1 ] && return 1
+	[ "$#" -gt 1 ] && return 1
 
 	case "$board_name" in
 	"ZyXEL"*|"Compex WP54 family")
diff --git a/target/linux/adm8668/base-files/lib/upgrade/platform.sh b/target/linux/adm8668/base-files/lib/upgrade/platform.sh
index 583fa2e..98e47ad 100644
--- a/target/linux/adm8668/base-files/lib/upgrade/platform.sh
+++ b/target/linux/adm8668/base-files/lib/upgrade/platform.sh
@@ -1,6 +1,6 @@
 PART_NAME=linux
 platform_check_image() {
-	[ "$ARGC" -gt 1 ] && return 1
+	[ "$#" -gt 1 ] && return 1
 
 	case "$(get_magic_word "$1")" in
 		# u-boot
diff --git a/target/linux/ar71xx/base-files/lib/upgrade/platform.sh b/target/linux/ar71xx/base-files/lib/upgrade/platform.sh
index 37ceea6..dfec133 100755
--- a/target/linux/ar71xx/base-files/lib/upgrade/platform.sh
+++ b/target/linux/ar71xx/base-files/lib/upgrade/platform.sh
@@ -111,7 +111,7 @@ platform_check_image() {
 	local magic="$(get_magic_word "$1")"
 	local magic_long="$(get_magic_long "$1")"
 
-	[ "$ARGC" -gt 1 ] && return 1
+	[ "$#" -gt 1 ] && return 1
 
 	case "$board" in
 	all0315n | \
diff --git a/target/linux/atheros/base-files/lib/upgrade/platform.sh b/target/linux/atheros/base-files/lib/upgrade/platform.sh
index d4daaac..d44b8fa 100644
--- a/target/linux/atheros/base-files/lib/upgrade/platform.sh
+++ b/target/linux/atheros/base-files/lib/upgrade/platform.sh
@@ -31,7 +31,7 @@ platform_find_kernelpart() {
 }
 
 platform_check_image() {
-	[ "$ARGC" -gt 1 ] && return 1
+	[ "$#" -gt 1 ] && return 1
 
 	case "$(get_magic_word "$1")" in
 		# Combined Image
diff --git a/target/linux/au1000/base-files/lib/upgrade/platform.sh b/target/linux/au1000/base-files/lib/upgrade/platform.sh
index 71744e6..1a9d151 100644
--- a/target/linux/au1000/base-files/lib/upgrade/platform.sh
+++ b/target/linux/au1000/base-files/lib/upgrade/platform.sh
@@ -2,7 +2,7 @@ KERNEL_IMG="openwrt-au1000-au1500-vmlinux.bin"
 ROOTFS_IMG="openwrt-au1000-au1500-root.fs"
 
 platform_check_image() {
-	[ "$ARGC" -gt 1 ] && return 1
+	[ "$#" -gt 1 ] && return 1
 	case "$(get_magic_word "$1")" in
 		6f70)
 			( get_image "$1" | tar -tf - $KERNEL_IMG >/dev/null && \
diff --git a/target/linux/avr32/base-files/lib/upgrade/platform.sh b/target/linux/avr32/base-files/lib/upgrade/platform.sh
index 00ad863..403a851 100755
--- a/target/linux/avr32/base-files/lib/upgrade/platform.sh
+++ b/target/linux/avr32/base-files/lib/upgrade/platform.sh
@@ -7,7 +7,7 @@ PART_NAME=firmware
 platform_check_image() {
 	local magic="$(get_magic_long "$1")"
 
-	[ "$ARGC" -gt 1 ] && return 1
+	[ "$#" -gt 1 ] && return 1
 
 	[ "$magic" != "27051956" ] && {
 		echo "Invalid image type."
diff --git a/target/linux/brcm47xx/base-files/lib/upgrade/platform.sh b/target/linux/brcm47xx/base-files/lib/upgrade/platform.sh
index 644f3c1..48885b1 100644
--- a/target/linux/brcm47xx/base-files/lib/upgrade/platform.sh
+++ b/target/linux/brcm47xx/base-files/lib/upgrade/platform.sh
@@ -1,7 +1,7 @@
 PART_NAME=firmware
 
 platform_check_image() {
-	[ "$ARGC" -gt 1 ] && return 1
+	[ "$#" -gt 1 ] && return 1
 
 	case "$(get_magic_word "$1")" in
 		# .trx files
diff --git a/target/linux/brcm63xx/base-files/lib/upgrade/platform.sh b/target/linux/brcm63xx/base-files/lib/upgrade/platform.sh
index 63ab774..5c9e2c2 100644
--- a/target/linux/brcm63xx/base-files/lib/upgrade/platform.sh
+++ b/target/linux/brcm63xx/base-files/lib/upgrade/platform.sh
@@ -1,6 +1,6 @@
 PART_NAME=linux
 platform_check_image() {
-	[ "$ARGC" -gt 1 ] && return 1
+	[ "$#" -gt 1 ] && return 1
 	case "$(get_magic_word "$1")" in
 		3600|3700|3800)
 			# 6348GW-11 boards use openwrt-96348GW-11-squashfs-cfe.bin files
diff --git a/target/linux/cns21xx/base-files/lib/upgrade/platform.sh b/target/linux/cns21xx/base-files/lib/upgrade/platform.sh
index 52aa789..fd9bd28 100755
--- a/target/linux/cns21xx/base-files/lib/upgrade/platform.sh
+++ b/target/linux/cns21xx/base-files/lib/upgrade/platform.sh
@@ -11,7 +11,7 @@ platform_check_image() {
 	local board=$(get_board_name)
 	local magic="$(get_magic_word "$1")"
 
-	[ "$ARGC" -gt 1 ] && return 1
+	[ "$#" -gt 1 ] && return 1
 
 	case "$board" in
 	nsb3ast)
diff --git a/target/linux/cns3xxx/base-files/lib/upgrade/platform.sh b/target/linux/cns3xxx/base-files/lib/upgrade/platform.sh
index 5990991..6d94a53 100644
--- a/target/linux/cns3xxx/base-files/lib/upgrade/platform.sh
+++ b/target/linux/cns3xxx/base-files/lib/upgrade/platform.sh
@@ -69,7 +69,7 @@ platform_check_image() {
 	local magic="$(get_magic_word "$1")"
 	local magic_long="$(get_magic_long "$1")"
 
-	[ "$ARGC" -gt 1 ] && return 1
+	[ "$#" -gt 1 ] && return 1
 
 	case "$board" in
 	laguna)
diff --git a/target/linux/ixp4xx/base-files/lib/upgrade/platform.sh b/target/linux/ixp4xx/base-files/lib/upgrade/platform.sh
index d10d934..508a167 100644
--- a/target/linux/ixp4xx/base-files/lib/upgrade/platform.sh
+++ b/target/linux/ixp4xx/base-files/lib/upgrade/platform.sh
@@ -93,7 +93,7 @@ platform_check_image() {
 	local kern_part_size=0x$(platform_find_part_size "$kernelpart")
 	local kern_length=0x$(dd if="$1" bs=2 skip=1 count=4 2>/dev/null)
 
-	[ "$ARGC" -gt 1 ] && return 1
+	[ "$#" -gt 1 ] && return 1
 
 	case "$board" in
 	avila | cambria )
diff --git a/target/linux/lantiq/base-files/lib/upgrade/platform.sh b/target/linux/lantiq/base-files/lib/upgrade/platform.sh
index dc5bbe2..841566e 100755
--- a/target/linux/lantiq/base-files/lib/upgrade/platform.sh
+++ b/target/linux/lantiq/base-files/lib/upgrade/platform.sh
@@ -1,7 +1,7 @@
 PART_NAME=firmware
 
 platform_check_image() {
-	[ "$ARGC" -gt 1 ] && return 1
+	[ "$#" -gt 1 ] && return 1
 
 	case "$(get_magic_word "$1")" in
 		# uImage
diff --git a/target/linux/mpc85xx/base-files/lib/upgrade/platform.sh b/target/linux/mpc85xx/base-files/lib/upgrade/platform.sh
index dbd179f..d95ec30 100755
--- a/target/linux/mpc85xx/base-files/lib/upgrade/platform.sh
+++ b/target/linux/mpc85xx/base-files/lib/upgrade/platform.sh
@@ -28,7 +28,7 @@ platform_check_image() {
 	local board=$(mpc85xx_board_name)
 	local magic="$(get_magic_long "$1")"
 
-	[ "$ARGC" -gt 1 ] && return 1
+	[ "$#" -gt 1 ] && return 1
 
 	case $board in
 	tl-wdr4900-v1)
diff --git a/target/linux/ppc40x/base-files/lib/upgrade/platform.sh b/target/linux/ppc40x/base-files/lib/upgrade/platform.sh
index ed08cab..b20b83c 100644
--- a/target/linux/ppc40x/base-files/lib/upgrade/platform.sh
+++ b/target/linux/ppc40x/base-files/lib/upgrade/platform.sh
@@ -11,7 +11,7 @@ platform_check_image() {
 	local board=$(ppc40x_board_name)
 	local magic="$(get_magic_word "$1")"
 
-	[ "$ARGC" -gt 1 ] && return 1
+	[ "$#" -gt 1 ] && return 1
 
 	case "$board" in
 	kilauea | openrb | magicbox)
diff --git a/target/linux/ramips/base-files/lib/upgrade/platform.sh b/target/linux/ramips/base-files/lib/upgrade/platform.sh
index 8ff6063..f072bf3 100755
--- a/target/linux/ramips/base-files/lib/upgrade/platform.sh
+++ b/target/linux/ramips/base-files/lib/upgrade/platform.sh
@@ -11,7 +11,7 @@ platform_check_image() {
 	local board=$(ramips_board_name)
 	local magic="$(get_magic_long "$1")"
 
-	[ "$ARGC" -gt 1 ] && return 1
+	[ "$#" -gt 1 ] && return 1
 
 	case "$board" in
 	3g-6200n | \
diff --git a/target/linux/x86/base-files/lib/upgrade/platform.sh b/target/linux/x86/base-files/lib/upgrade/platform.sh
index 9503d5d..a2dd20a 100644
--- a/target/linux/x86/base-files/lib/upgrade/platform.sh
+++ b/target/linux/x86/base-files/lib/upgrade/platform.sh
@@ -14,7 +14,7 @@ x86_get_rootfs() {
 }
 
 platform_check_image() {
-	[ "$ARGC" -gt 1 ] && return 1
+	[ "$#" -gt 1 ] && return 1
 
 	case "$(get_magic_word "$1")" in
 		eb48|eb63) return 0;;
diff --git a/target/linux/x86/olpc/base-files/lib/upgrade/platform.sh b/target/linux/x86/olpc/base-files/lib/upgrade/platform.sh
index ffd0b93..c90a4ce 100644
--- a/target/linux/x86/olpc/base-files/lib/upgrade/platform.sh
+++ b/target/linux/x86/olpc/base-files/lib/upgrade/platform.sh
@@ -1,5 +1,5 @@
 platform_check_image() {
-	[ "$ARGC" -gt 1 ] && return 1
+	[ "$#" -gt 1 ] && return 1
 
 	case "$(get_magic_word "$1")" in
 		48eb) return 0;;
diff --git a/target/linux/x86_64/base-files/lib/upgrade/platform.sh b/target/linux/x86_64/base-files/lib/upgrade/platform.sh
index 9503d5d..a2dd20a 100644
--- a/target/linux/x86_64/base-files/lib/upgrade/platform.sh
+++ b/target/linux/x86_64/base-files/lib/upgrade/platform.sh
@@ -14,7 +14,7 @@ x86_get_rootfs() {
 }
 
 platform_check_image() {
-	[ "$ARGC" -gt 1 ] && return 1
+	[ "$#" -gt 1 ] && return 1
 
 	case "$(get_magic_word "$1")" in
 		eb48|eb63) return 0;;
-- 
1.7.10.4

