* [PATCH net] tools: ynl: reject missing regen path argument
@ 2026-11-25 7:03 Zhiqi Zhang
2026-11-26 9:23 ` Hangbin Liu
0 siblings, 1 reply; 2+ messages in thread
From: Zhiqi Zhang @ 2026-11-25 7:03 UTC (permalink / raw)
To: Donald Hunter, Jakub Kicinski
Cc: David S. Miller, Eric Dumazet, Paolo Abeni, Simon Horman, netdev,
linux-kernel
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)
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH net] tools: ynl: reject missing regen path argument
2026-11-25 7:03 [PATCH net] tools: ynl: reject missing regen path argument Zhiqi Zhang
@ 2026-11-26 9:23 ` Hangbin Liu
0 siblings, 0 replies; 2+ messages in thread
From: Hangbin Liu @ 2026-11-26 9:23 UTC (permalink / raw)
To: Zhiqi Zhang
Cc: Donald Hunter, Jakub Kicinski, David S. Miller, Eric Dumazet,
Paolo Abeni, Simon Horman, netdev, linux-kernel
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>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-26 9:23 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-25 7:03 [PATCH net] tools: ynl: reject missing regen path argument Zhiqi Zhang
2026-11-26 9:23 ` Hangbin Liu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox