From a9e341a469fe1b24b1f9d6947adfd020c64ba43f Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Thu, 19 Mar 2026 14:33:47 +0100 Subject: [PATCH] optiontable: replace stdin with filename arg, harden `open()` call Closes #21008 --- lib/CMakeLists.txt | 2 +- lib/Makefile.am | 2 +- lib/optiontable.pl | 5 ++++- tests/test1276.pl | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 4b4f1c3788..7384844960 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -379,7 +379,7 @@ endif() if(PERL_EXECUTABLE) add_custom_target(curl-optiontable COMMENT "Generating lib/easyoptions.c" VERBATIM USES_TERMINAL - COMMAND "${PERL_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/optiontable.pl" < "${PROJECT_SOURCE_DIR}/include/curl/curl.h" + COMMAND "${PERL_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/optiontable.pl" "${PROJECT_SOURCE_DIR}/include/curl/curl.h" > "${PROJECT_SOURCE_DIR}/lib/easyoptions.c" DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/optiontable.pl" "${PROJECT_SOURCE_DIR}/include/curl/curl.h" ) diff --git a/lib/Makefile.am b/lib/Makefile.am index ab575ae730..0fa4d781a4 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -178,7 +178,7 @@ tidy: @CLANG_TIDY@ --config-file=$(top_srcdir)/.clang-tidy.yml $(TIDYFLAGS) $(CURL_CLANG_TIDYFLAGS) $$_csources -- $(AM_CPPFLAGS) $(CPPFLAGS) -DHAVE_CONFIG_H $(_tidy_cflags)) optiontable: - @PERL@ $(srcdir)/optiontable.pl < $(top_srcdir)/include/curl/curl.h > $(srcdir)/easyoptions.c + @PERL@ $(srcdir)/optiontable.pl $(top_srcdir)/include/curl/curl.h > $(srcdir)/easyoptions.c if HAVE_WINDRES .rc.lo: diff --git a/lib/optiontable.pl b/lib/optiontable.pl index 1222536794..db0659cbb0 100755 --- a/lib/optiontable.pl +++ b/lib/optiontable.pl @@ -79,7 +79,9 @@ sub add { } my $fl; -while() { +my $file = shift @ARGV; +open(CURL_H, '<', $file) or die; +while() { my $l = $_; if($fl) { # continued deprecation @@ -121,6 +123,7 @@ while() { } } } +close(CURL_H); for my $name (sort @names) { my $oname = $name; diff --git a/tests/test1276.pl b/tests/test1276.pl index 3eb04c035f..8732ca4b1e 100755 --- a/tests/test1276.pl +++ b/tests/test1276.pl @@ -34,7 +34,7 @@ sub showline { my $root = $ARGV[0] || '..'; -open(my $fh, "-|", "perl $root/lib/optiontable.pl < $root/include/curl/curl.h"); +open(my $fh, "-|", 'perl', "$root/lib/optiontable.pl", "$root/include/curl/curl.h"); binmode $fh; my @gen=<$fh>; close($fh);