🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
2 messages
2 total messages Started by Zhiqi Zhang Wed, 25 Nov 2026 07:03
[PATCH net] tools: ynl: reject missing regen path argument
#22340
Author: Zhiqi Zhang
Date: Wed, 25 Nov 2026 07:03
63 lines
12636 bytes
ynl-regen.sh expects -p to be followed by a path.  If -p is
passed without an argument, $2 is empty and shift 2 fails without
consuming $1.  The option parser then keeps looping on -p until
the caller kills the script.

I found the issue by manual code inspection and validated it with:

  timeout 2s bash tools/net/ynl/ynl-regen.sh -p

which used to time out with exit code 124.

Reject -p without an argument before shifting.  Also stop if the
selected path cannot be entered, so the script does not continue
from an unintended directory after a bad -p path.

GPT wrote the code change; I reviewed and tested it.

Tested with:

  timeout 2s bash tools/net/ynl/ynl-regen.sh -p
  timeout 2s bash tools/net/ynl/ynl-regen.sh -p \
    /definitely/not/a/kernel/tree
  bash -n tools/net/ynl/ynl-regen.sh
  scripts/checkpatch.pl --strict --file tools/net/ynl/ynl-regen.sh

Fixes: 25b5a2a1905f ("ynl: regenerate all headers")
Signed-off-by: Zhiqi Zhang <zhiqizhangg@gmail.com>
---
 tools/net/ynl/ynl-regen.sh | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/tools/net/ynl/ynl-regen.sh b/tools/net/ynl/ynl-regen.sh
index d9809276db..524fadb770 100755
--- a/tools/net/ynl/ynl-regen.sh
+++ b/tools/net/ynl/ynl-regen.sh
@@ -9,13 +9,20 @@ search=
 while [ ! -z "$1" ]; do
   case "$1" in
     -f ) force=yes; shift ;;
-    -p ) search=$2; shift 2 ;;
+    -p )
+      if [ $# -lt 2 ]; then
+        echo "Option -p requires a path" >&2
+        exit 1
+      fi
+      search=$2
+      shift 2
+      ;;
     * )  echo "Unrecognized option '$1'"; exit 1 ;;
   esac
 done
 
 KDIR=$(dirname $(dirname $(dirname $(dirname $(realpath $0)))))
-pushd ${search:-$KDIR} >>/dev/null
+pushd "${search:-$KDIR}" >>/dev/null || exit 1
 
 files=$(git grep --files-with-matches '^/\* YNL-GEN \(kernel\|uapi\|user\)')
 for f in $files; do

base-commit: 7ccb044c27720d48175577080b851f047ddcfd1c
-- 
2.54.0 (Apple Git-157)
Re: [PATCH net] tools: ynl: reject missing regen path argument
#22995
Author: Hangbin Liu
Date: Thu, 26 Nov 2026 09:23
68 lines
10428 bytes
On Wed, Nov 25, 2026 at 03:03:54PM +0800, Zhiqi Zhang wrote:
> ynl-regen.sh expects -p to be followed by a path.  If -p is
> passed without an argument, $2 is empty and shift 2 fails without
> consuming $1.  The option parser then keeps looping on -p until
> the caller kills the script.
> 
> I found the issue by manual code inspection and validated it with:
> 
>   timeout 2s bash tools/net/ynl/ynl-regen.sh -p
> 
> which used to time out with exit code 124.
> 
> Reject -p without an argument before shifting.  Also stop if the
> selected path cannot be entered, so the script does not continue
> from an unintended directory after a bad -p path.
> 
> GPT wrote the code change; I reviewed and tested it.
> 
> Tested with:
> 
>   timeout 2s bash tools/net/ynl/ynl-regen.sh -p
>   timeout 2s bash tools/net/ynl/ynl-regen.sh -p \
>     /definitely/not/a/kernel/tree
>   bash -n tools/net/ynl/ynl-regen.sh
>   scripts/checkpatch.pl --strict --file tools/net/ynl/ynl-regen.sh
> 
> Fixes: 25b5a2a1905f ("ynl: regenerate all headers")
> Signed-off-by: Zhiqi Zhang <zhiqizhangg@gmail.com>
> ---
>  tools/net/ynl/ynl-regen.sh | 11 +++++++++--
>  1 file changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/net/ynl/ynl-regen.sh b/tools/net/ynl/ynl-regen.sh
> index d9809276db..524fadb770 100755
> --- a/tools/net/ynl/ynl-regen.sh
> +++ b/tools/net/ynl/ynl-regen.sh
> @@ -9,13 +9,20 @@ search=
>  while [ ! -z "$1" ]; do
>    case "$1" in
>      -f ) force=yes; shift ;;
> -    -p ) search=$2; shift 2 ;;
> +    -p )
> +      if [ $# -lt 2 ]; then
> +        echo "Option -p requires a path" >&2
> +        exit 1
> +      fi
> +      search=$2
> +      shift 2
> +      ;;
>      * )  echo "Unrecognized option '$1'"; exit 1 ;;
>    esac
>  done
>  
>  KDIR=$(dirname $(dirname $(dirname $(dirname $(realpath $0)))))
> -pushd ${search:-$KDIR} >>/dev/null
> +pushd "${search:-$KDIR}" >>/dev/null || exit 1
>  
>  files=$(git grep --files-with-matches '^/\* YNL-GEN \(kernel\|uapi\|user\)')
>  for f in $files; do
> 
> base-commit: 7ccb044c27720d48175577080b851f047ddcfd1c
> -- 
> 2.54.0 (Apple Git-157)
> 
> 

Reviewed-by: Hangbin Liu <liuhangbin@kylinos.cn>
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads