[Libguestfs] [PATCH nbdkit 2/2] docs: Enhance podwrapper to detect trailing whitespace

Richard W.M. Jones rjones at redhat.com
Sat May 21 14:09:33 UTC 2022


Now that trailing whitespace should no longer appear in POD files,
enhance podwrapper to detect this and error out.

I had to modify podwrapper so it doesn't introduce trailing whitespace
when it encounters a blank line in a --verbatim include.

I also fixed an instance of unwanted trailing whitespace.
---
 docs/nbdkit-release-notes-1.16.pod |  2 +-
 podwrapper.pl.in                   | 11 ++++++++---
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/docs/nbdkit-release-notes-1.16.pod b/docs/nbdkit-release-notes-1.16.pod
index 7e8d76fa..5334e33b 100644
--- a/docs/nbdkit-release-notes-1.16.pod
+++ b/docs/nbdkit-release-notes-1.16.pod
@@ -17,7 +17,7 @@ to the fixed versions is highly recommended.  The new
 L<nbdkit-security(1)> man page contains an up to date list of past
 security issues.
 
-=head3 CVE-2019-14850 
+=head3 CVE-2019-14850
 denial of service due to premature opening of back-end connection
 
 See the full announcement and links to mitigation, tests and fixes
diff --git a/podwrapper.pl.in b/podwrapper.pl.in
index bd0cf3ee..e28020a0 100755
--- a/podwrapper.pl.in
+++ b/podwrapper.pl.in
@@ -286,6 +286,10 @@ die "$progname: $input: is not valid utf8" unless utf8::is_utf8 ($content);
 die "$progname: $input: =encoding must not be present in input\n"
     if $content =~ /^=encoding/m;
 
+# Don't permit trailing whitespace.
+die "$progname: $input: trailing whitespace in input\n"
+    if $content =~ /[ \t]$/m;
+
 # We may add an encoding line, but this breaks RHEL 6-era Pod::Simple
 # with the error "Cannot decode string with wide characters".
 $content =~ s/^=(.*)/\n=encoding utf8\n\n=$1/m
@@ -576,14 +580,15 @@ sub read_whole_file
 sub read_verbatim_file
 {
     my $input = shift;
-    my $r = "";
+    my @r = ();
 
     open FILE, "<:encoding(UTF-8)", $input or die "$progname: $input: $!";
     while (<FILE>) {
-        $r .= " $_";
+        chomp;
+        if (length) { push @r, " $_" } else { push @r, "" }
     }
     close FILE;
-    $r;
+    return join ("\n", @r) . "\n";
 }
 
 =head1 SEE ALSO
-- 
2.35.1



More information about the Libguestfs mailing list