aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Fandrich <danf@mageia.org>2024-04-16 19:37:08 -0700
committerDan Fandrich <danf@mageia.org>2024-04-16 19:45:20 -0700
commit6fb12d2bfe8a7360103f07e18197ba5d280989b1 (patch)
tree7dd392491230d0c3a4612dbe2549c00edb2700ec
parentf894bb17b82ef676a0121cdddcee57994e8b275d (diff)
downloadmgaadvisories-6fb12d2bfe8a7360103f07e18197ba5d280989b1.tar
mgaadvisories-6fb12d2bfe8a7360103f07e18197ba5d280989b1.tar.gz
mgaadvisories-6fb12d2bfe8a7360103f07e18197ba5d280989b1.tar.bz2
mgaadvisories-6fb12d2bfe8a7360103f07e18197ba5d280989b1.tar.xz
mgaadvisories-6fb12d2bfe8a7360103f07e18197ba5d280989b1.zip
Ensure the .adv file ends with newline when publishing
Lacking a newline corrupts the file when the ID is appended. Return an error if this case is detected.
-rw-r--r--NEWS4
-rw-r--r--lib/MGA/Advisories.pm11
2 files changed, 15 insertions, 0 deletions
diff --git a/NEWS b/NEWS
index 7d92c2f..3440810 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,7 @@
+Version 0.X
+
+- ensure .adv file ends with newline when publishing
+
Version 0.30
- try to fix publish-all
diff --git a/lib/MGA/Advisories.pm b/lib/MGA/Advisories.pm
index 2506c3c..3752250 100644
--- a/lib/MGA/Advisories.pm
+++ b/lib/MGA/Advisories.pm
@@ -9,6 +9,7 @@ use DateTime::Format::ISO8601;
use Email::Sender::Simple qw(try_to_sendmail);
use Email::Simple;
use Email::Simple::Creator;
+use Fcntl qw(SEEK_END);
use HTTP::Request;
use LWP::UserAgent;
use Parallel::ForkManager;
@@ -232,6 +233,16 @@ sub assign_id {
return;
}
+ # Appending the ID later assumes that the file ends in a newline
+ open(my $fha, "<", $advfile);
+ seek($fha, -1, SEEK_END);
+ my $c = <$fha>;
+ close($fha);
+ if ($c ne "\n") {
+ print STDERR "$advname missing newline at end of file\n";
+ return;
+ }
+
my $adv = LoadFile($advfile);
if ($adv->{ID}) {
print STDERR "$advname already has an ID assigned: $adv->{ID}\n";