Subject: | Building with -Werror=format-security fails with Perl 5.28.0: LMDB.xs:118:2: error: format not a string literal and no format arguments |
LMDB_File incorrectly uses croak() and that can lead to a crash and produces a warning (or a compilation error) with Perl 5.28.0 now. Attached patch fixes it.
By the way, there are plenty of other format string warnings.
Subject: | LMDB_File-0.12-Fix-passing-mdb_strerror-value-to-croak.patch |
From b9caab7824725758242101b0e9c696c94cb63d10 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
Date: Fri, 29 Jun 2018 12:35:42 +0200
Subject: [PATCH] Fix passing mdb_strerror() value to croak()
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
croak() expects a sprintf-like format string, mdb_strerror() can
return any arbitrary string, including formatting sequences. This
could trick croak() to access an unitialized memory.
Perl 5.28.0 annotates croak() and building LMDB_File with
-Werror=format-security fails now:
LMDB.xs: In function 'populateStat':
LMDB.xs:118:2: error: format not a string literal and no format arguments [-Werror=format-security]
croak(mdb_strerror(res));
^~~~~
This patch fixes it.
Signed-off-by: Petr PÃsaÅ <ppisar@redhat.com>
---
LMDB.xs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/LMDB.xs b/LMDB.xs
index 01c8504..43f13de 100644
--- a/LMDB.xs
+++ b/LMDB.xs
@@ -115,7 +115,7 @@ populateStat(pTHX_ HV** hashptr, int res, MDB_stat *stat)
{
HV* RETVAL;
if(res)
- croak(mdb_strerror(res));
+ croak("%s", mdb_strerror(res));
RETVAL = newHV();
StoreUV("psize", stat->ms_psize);
StoreUV("depth", stat->ms_depth);
--
2.14.4