From a09fa4b22e32f8a63985a2a367459cfe81d8b486 Mon Sep 17 00:00:00 2001 From: Gregory Oschwald Date: Tue, 10 Dec 2024 08:45:51 -0800 Subject: [PATCH 1/3] Do not depend on non-core Perl modules --- .github/workflows/codeql-analysis.yml | 2 +- dev-bin/make-man-pages.pl | 37 +++++++++++++++++++-------- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 0d8a7e78..3c4bf74c 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -34,7 +34,7 @@ jobs: - name: Initialize CodeQL uses: github/codeql-action/init@v3 - - run: sudo apt install libipc-run3-perl libipc-system-simple-perl libfile-slurp-perl libfile-which-perl pandoc + - run: sudo apt install libipc-run3-perl pandoc - run: | ./bootstrap ./configure diff --git a/dev-bin/make-man-pages.pl b/dev-bin/make-man-pages.pl index 2b6fc853..abdfa802 100755 --- a/dev-bin/make-man-pages.pl +++ b/dev-bin/make-man-pages.pl @@ -6,8 +6,6 @@ use FindBin qw( $Bin ); use File::Path qw( mkpath ); -use File::Slurp qw( edit_file read_file ); -use File::Which qw( which ); sub main { my $target = shift || "$Bin/.."; @@ -15,7 +13,7 @@ sub main { my @translators = qw ( lowdown pandoc ); my $translator; foreach my $p (@translators) { - if ( defined which($p) ) { + if ( _which($p) ) { $translator = $p; last; } @@ -32,6 +30,14 @@ sub main { _make_man( $translator, $target, 'mmdblookup', 1 ); } +sub _which { + my $program = shift; + for my $path ( split /:/, $ENV{PATH} ) { + return 1 if -x "$path/$program"; + } + return 0; +} + sub _make_man { my $translator = shift; my $target = shift; @@ -73,7 +79,11 @@ sub _make_man { sub _make_lib_man_links { my $target = shift; - my $header = read_file("$Bin/../include/maxminddb.h"); + open my $header_fh, '<', "$Bin/../include/maxminddb.h" + or die "Failed to open header file: $!"; + my $header = do { local $/; <$header_fh> }; + close $header_fh or die "Failed to close header file: $!"; + for my $proto ( $header =~ /^ *extern.+?(MMDB_\w+)\(/gsm ) { open my $fh, '>', "$target/man/man3/$proto.3" or die "Failed to open file: $!"; @@ -88,13 +98,18 @@ sub _make_lib_man_links { sub _pandoc_postprocess { my $file = shift; - edit_file( - sub { - s/^\.IP\n\.nf/.IP "" 4\n.nf/gm; - s/(Automatically generated by Pandoc)(.+)$/$1/m; - }, - $file, - ); + open my $fh, '<', $file or die "Failed to open man file for reading: $!"; + my @lines = <$fh>; + close $fh or die "Failed to close file: $!"; + + for my $line (@lines) { + $line =~ s/^\.IP\n\.nf/.IP "" 4\n.nf/gm; + $line =~ s/(Automatically generated by Pandoc)(.+)$/$1/m; + } + + open $fh, '>', $file or die "Failed to open file for writing: $!"; + print $fh @lines or die "Failed to write to file: $!"; + close $fh or die "Failed to close file: $!"; } main(shift); From cbe22dc4f97075696163fe661dc8d25756c61276 Mon Sep 17 00:00:00 2001 From: Gregory Oschwald Date: Wed, 11 Dec 2024 11:01:55 -0800 Subject: [PATCH 2/3] Add more error checking --- dev-bin/make-man-pages.pl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/dev-bin/make-man-pages.pl b/dev-bin/make-man-pages.pl index abdfa802..4a1c6d74 100755 --- a/dev-bin/make-man-pages.pl +++ b/dev-bin/make-man-pages.pl @@ -82,6 +82,9 @@ sub _make_lib_man_links { open my $header_fh, '<', "$Bin/../include/maxminddb.h" or die "Failed to open header file: $!"; my $header = do { local $/; <$header_fh> }; + + die "Error reading file header file: $!" unless defined $header; + close $header_fh or die "Failed to close header file: $!"; for my $proto ( $header =~ /^ *extern.+?(MMDB_\w+)\(/gsm ) { @@ -100,6 +103,8 @@ sub _pandoc_postprocess { open my $fh, '<', $file or die "Failed to open man file for reading: $!"; my @lines = <$fh>; + die "Error when reading man page: $!" if $!; + close $fh or die "Failed to close file: $!"; for my $line (@lines) { From 20cc7ad7faa516cf23d19f4cd9130a403b545c70 Mon Sep 17 00:00:00 2001 From: Gregory Oschwald Date: Wed, 11 Dec 2024 11:02:28 -0800 Subject: [PATCH 3/3] Include status code rather than errno for system calls --- dev-bin/make-man-pages.pl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dev-bin/make-man-pages.pl b/dev-bin/make-man-pages.pl index 4a1c6d74..8d308baf 100755 --- a/dev-bin/make-man-pages.pl +++ b/dev-bin/make-man-pages.pl @@ -59,7 +59,7 @@ sub _make_man { '-M', "section:$section", $input, '-o', $output, - ) == 0 or die "Failed to run pandoc: $!"; + ) == 0 or die "Failed to run pandoc: $?"; _pandoc_postprocess($output); } elsif ( $translator eq 'lowdown' ) { @@ -72,7 +72,7 @@ sub _make_man { '-M', "section:$section", $input, '-o', $output, - ) == 0 or die "Failed to run lowdown: $!"; + ) == 0 or die "Failed to run lowdown: $?"; } }