Commit Graph

13714 Commits

Author SHA1 Message Date
Panu Matilainen 5f9fcbbfc4 Use the new ID-based digest API for build-time digest generation
No functional changes, but using the rpmtag names makes it clearer
what these things will be used for.
2017-02-27 08:39:15 +02:00
Pavlina Moravcova Varekova 0faff2d405 Allow to use spaces in "_sourcedir" path #125
The patch enables to use formats:

%define  _sourcedir  /my\ directory/my\ subdirectory
%define  _sourcedir  /my directory/my subdirectory

Formats, with directories in double-quotes or quotes:
%define  _sourcedir  "directory"
%define  _sourcedir  'directory'
are not accepted.

Comment to Panu and Florian:

I did not add formats with double-quotes or quotes because
- the implemented format was the most strightforward possibility
- in rpm spec files double-quotes or quotes are not usually supperted too

The second allowed format is only a side effect of the implementation,
it was not my purpose.
2017-02-24 16:23:51 +02:00
Peter Jones e6f346ead4 Don't nerf "rpmspec --eval '%trace' -P foo.spec" output with ellipses.
The whole point of %trace is that some macro is being evaluated in a
surprising way, and you want to know what it is.  This is often the
result of an unfortunately complex macro with difficult to see
intermediate results.

Shortening the output because it doesn't fit past 61 or so characters
does not help, and we have big screens these days.  Don't do it.

Signed-off-by: Peter Jones <pjones@redhat.com>
2017-02-24 13:23:16 +01:00
Peter Jones 17d5ae8ed3 Add --trace macros to enable %trace on the command line.
This allows you to do 'rpmspec --trace -P foo.spec", which is much more
natural than editing the .spec itself to add %trace, and much more
convenient than using --eval yourself.

Signed-off-by: Peter Jones <pjones@redhat.com>
2017-02-24 13:23:16 +01:00
Peter Jones bf248badd3 Bounds check strings to print correctly in %trace mode.
In %trace mode, evaluating a macro which is undefined causes an invalid
read of 1 byte when searching for the end of the string:

trillian:~$ valgrind rpmspec --eval '%trace' --eval '%{?myUndefinedMacro}'
==21534== Memcheck, a memory error detector
==21534== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==21534== Using Valgrind-3.12.0 and LibVEX; rerun with -h for copyright info
==21534== Command: rpmspec --trace --eval %{?myUndefinedMacro}
==21534==

  1>   %{?myUndefinedMacro}^==21534== Invalid read of size 1
==21534==    at 0x55018D4: printMacro (macro.c:296)
==21534==    by 0x5502DFC: expandMacro (macro.c:1077)
==21534==    by 0x5503710: doExpandMacros (macro.c:1280)
==21534==    by 0x5504AB6: rpmExpand (macro.c:1629)
==21534==    by 0x508F59A: rpmcliAllArgCallback (poptALL.c:120)
==21534==    by 0x6DAF71D: invokeCallbacksOPTION (popt.c:156)
==21534==    by 0x6DAF75B: invokeCallbacksOPTION (popt.c:139)
==21534==    by 0x6DB1428: poptGetNextOpt (popt.c:1515)
==21534==    by 0x508F912: rpmcliInit (poptALL.c:302)
==21534==    by 0x1095B2: main (rpmspec.c:63)
==21534==  Address 0x8a010f3 is 0 bytes after a block of size 19 alloc'd
==21534==    at 0x4C2DB9D: malloc (vg_replace_malloc.c:299)
==21534==    by 0x5507C17: rmalloc (rpmmalloc.c:44)
==21534==    by 0x5502788: expandMacro (macro.c:927)
==21534==    by 0x5503710: doExpandMacros (macro.c:1280)
==21534==    by 0x5504AB6: rpmExpand (macro.c:1629)
==21534==    by 0x508F59A: rpmcliAllArgCallback (poptALL.c:120)
==21534==    by 0x6DAF71D: invokeCallbacksOPTION (popt.c:156)
==21534==    by 0x6DAF75B: invokeCallbacksOPTION (popt.c:139)
==21534==    by 0x6DB1428: poptGetNextOpt (popt.c:1515)
==21534==    by 0x508F912: rpmcliInit (poptALL.c:302)
==21534==    by 0x1095B2: main (rpmspec.c:63)
==21534==

  1>   %{?_transaction_color}^
  1>   %{?_prefer_color}^
  1>   %{_netsharedpath}^
  1>   %{_install_langs}^
==21534==
==21534== HEAP SUMMARY:
==21534==     in use at exit: 7,183 bytes in 71 blocks
==21534==   total heap usage: 7,811 allocs, 7,740 frees, 3,500,361 bytes allocated
==21534==
==21534== LEAK SUMMARY:
==21534==    definitely lost: 19 bytes in 1 blocks
==21534==    indirectly lost: 0 bytes in 0 blocks
==21534==      possibly lost: 0 bytes in 0 blocks
==21534==    still reachable: 7,164 bytes in 70 blocks
==21534==         suppressed: 0 bytes in 0 blocks
==21534== Rerun with --leak-check=full to see details of leaked memory
==21534==
==21534== For counts of detected and suppressed errors, rerun with: -v
==21534== ERROR SUMMARY: 5 errors from 1 contexts (suppressed: 0 from 0)
trillian:~$

This can easily be avoided by checking the first byte as well as the
second for our sentinal value (NUL).

Signed-off-by: Peter Jones <pjones@redhat.com>
2017-02-24 13:23:16 +01:00
Pavlina Moravcova Varekova 34b61a1f82 Fix number of references on spec_Type (#114)
After creating a specPkg from a spec file we must increase spec file
reference counter. Otherwise spec file may be accidentally deallocated
and usage of SpecPkg can cause an error.
2017-02-23 14:03:10 +02:00
Panu Matilainen dffb3bc39a And finally, just use the FD digest API without messing with bundles 2017-02-23 11:34:28 +02:00
Panu Matilainen de32ea0c28 Eliminate the second digest bundle from signature verification
We don't need two sets, instead do two rounds of signature checking:
once after just the header has been read, and once after the payload
has been read too.

The fooKeys strings freeing needs to be moved to the end as we can
now jump past it otherwise.
2017-02-23 11:34:23 +02:00
Panu Matilainen 7c1d4c5772 Refactor header read out of payload read helper 2017-02-23 11:34:16 +02:00
Panu Matilainen bf03be0938 Simplify the error code logic in signature verification
We really dont need three different variables to determine whether
the operation was success or not. Assume failure all along and
only assign success at the very end.
2017-02-23 11:34:07 +02:00
Panu Matilainen 7356504e0d Refactor digest + signature verification loop to helper function 2017-02-23 11:33:04 +02:00
Panu Matilainen b24258fdf8 Refactor digest initialization to helper function 2017-02-23 11:29:01 +02:00
Panu Matilainen 2b456b22f1 Refer to digests by their rpm tags instead of algorithms 2017-02-23 11:29:01 +02:00
Panu Matilainen 43fecc67a4 Add an internal API to dup in-flight digest context from FD 2017-02-23 11:29:01 +02:00
Panu Matilainen 6c7b85e317 Make signature range clearer and more flexible
Rename the siginfo payload field to range, which better explains
what it means. Also make it a bitfield which allows expressing
the actual combinations: modern signature/digest items are on
header only, rpm v3 ones are on header+payload and in the future
we might have payload-only digest(s) as well.

No functional changes intended.
2017-02-22 12:27:58 +02:00
Panu Matilainen b74096a751 Make the stftime() buffer big enuff (RhBug:1425231)
Apparently 50 bytes is not enough for everybodys dates:

    LC_TIME=ko_KR.utf8 rpm -q --queryformat '%{installtime:date}\n' rpm

Lets hope nobody on this planet needs to deal with dates that read like
a short story. Aliens we dont consider, sorry.
2017-02-22 08:32:15 +02:00
Panu Matilainen 9721b59a20 Handle buffer-too-small error from strftime()
Pass emsg around from the callers, actually emit an error if output
doesn't fit our buffer, allowing us to get rid of the old TODO note.

strftime() returning zero is not, generally speaking, always an error
because a format might be empty or the result could be empty, such
as %p/%P in many locales. However in our case the formats are known
to be non-empty.
2017-02-22 08:30:39 +02:00
Panu Matilainen ef0596d0c0 Oops, id and algo reversed in fdInitDigestID() prototype :( 2017-02-21 15:37:27 +02:00
Panu Matilainen 904fb9310d Adjust the internal FD digest API to accept IDs too 2017-02-21 15:05:22 +02:00
Panu Matilainen 6046386afd Use arbitrary ids instead of algorithm number to identify digests in bundles
Change the way individual digests within bundles are stored and accessed:
Previously the digest algo number was used directly as the index into
the bundle. Which works, but limits you to a single digest per algo,
and the array is likely to be rather sparse. To address both issues, use
an arbitrary integer ID to address the digests and always add new
digests in the first available slot. And yes the implementation is
a bit simplistic and taking some shortcuts, but so was the previous one.

Abstracting out the actual algorithm allows using eg rpm tag values
as the identifier, and also makes it possible to do multiple digests
of the same type on overlapping ranges. This is entirely backwards
compatible however if you simply use algorithm number also as the id,
so callers *need* to be updated.
2017-02-21 14:30:39 +02:00
Panu Matilainen 316573c07e Fix ancient (and in practise, unseen) typo on "not trusted" message 2017-02-21 12:21:55 +02:00
Panu Matilainen f31bae39a6 Assimilate rpmpkgReadHeader() back into rpmReadHeader()
There are no other callers of rpmpkgReadHeader() left so this
separation makes no sense.
2017-02-21 11:17:42 +02:00
Panu Matilainen 46ed65aca6 Signature check before header import on package reads
Until now we have been reading and importing the headers, and then
pull out the original immutable image from the header in order to
do signature checking on unknown packages. Those header manipulations
are relatively complex and thus vulnerable operatations that are,
to add to the insult, totally unnecessary as the header on disk is
just the way we want it for signature checking as it is.

This changes the package reading process rather fundamentally: we first
read (and sanity-check) the header blobs, then do signature checking on
the still un-imported blob, and only then try to import the headers
(which could still fail, at least in theory). This reduces the amount of
code exposed to unverified headers considerably: the deep header internals
are avoided entirely, and there's one less signature checking code-path
to worry about as it's now unified with the one used by headerCheck().

There's a subtle change in the "preferred" signature type: rpmpkgRead()
used to prefer DSA over RSA, headerSigVerify() prefers RSA. However
that's rather academic as both signature types never co-exist in
the same package.

For normal use, all this shouldn't change anything at all.
2017-02-21 09:47:01 +02:00
Panu Matilainen 1cec6e078e Note memory ownership transfer in hdrblobImport() to avoid double-frees
After a successful import, the header owns the memory originally alloced
for the hdrblob. Set the blob allocation to NULL on successful import
so callers dont need to guess about freeing it in case of other failures.
2017-02-21 09:03:10 +02:00
Panu Matilainen 9e23df916d Refactor the package retrofit logic out to a helper function 2017-02-21 08:37:56 +02:00
Panu Matilainen 7b870ad01d Support returning keyid from headerSigVerify() 2017-02-20 17:00:42 +02:00
Panu Matilainen a148aefe96 Support checking signatures from another header blob in headerSigVerify() 2017-02-20 17:00:36 +02:00
Panu Matilainen 860e304925 Refactor to simplify and streamline return code handling in rpmpkgRead()
Assume failure, only assign other values for final decisions.
No intended functional changes.
2017-02-20 16:58:21 +02:00
Bernhard M. Wiedemann 8d84878ee0 Allow SOURCE_DATE_EPOCH to override file timestamps
Limit the maximum date to SOURCE_DATE_EPOCH or use origtime if not defined
similar to the tar --clamp-mtime option

based on a patch by Nicolas Vigier <boklm at torproject.org>
2017-02-16 12:29:33 +01:00
Stephen Gallagher 64028f9a1c Add OpenSSL support for digest and signatures
Autotools: add --with-crypto=openssl
This enables RPM to locate the appropriate flags for compiling
against OpenSSL for digest and hash functions.

This implementation changes the old behavior of
--with[out]-beecrypt toggling between beecrypt and nss. It will
now throw an error if attempting to use --with-beecrypt
indicating that the user should instead use --with-crypto=

See also:
https://github.com/rpm-software-management/rpm/issues/119
2017-02-16 11:26:55 +01:00
Pavlina Moravcova Varekova 932385ab90 Fix unclear %dev error message
Mistakes in %dev as "%dev(c,b,0) /dev/lirc"
will give unclear errors like:

     Missing devmajor in %dev b

Make a copy of the all the arguments in brackets to make the error clear:

    Missing devmajor in %dev(c,b,0)
2017-02-16 11:04:10 +01:00
Tomas Orsava 102eab50b3 Fix pythondistdeps.py --provides for Python wheels
As Python wheels do not contain targetted Python version in the directory/file
name of their metadata like Python eggs do, and since the Python version is not
contained in the metadata either, it is necessary to get it from elsewhere.

Here it is parsed from the path the metadata resides at
(e.g. /usr/lib/pythonX.Y/site-packages/...)
2017-02-15 15:59:15 +01:00
Florian Festi a8e51b3bb0 brp-python-bytecompile: Process python lib dirs even without standard Python
There is no need for /usr/bin/python when byte compiling files in
/usr/lib/pythonX.Y (only /usr/bin/pythonX.Y). Moved check so we do not exit
prematurely.

Fixes: rhbz#1411588
2017-02-14 14:10:11 +01:00
Panu Matilainen e1252472c1 Validate boundaries for pgpGrab() when reading V4 signatures (#151)
In V4 signature packets there are multiple data sections, whose length
is stored as two bytes before the data. We've been checking the data
boundaries, but a truncated/malformed packet might be missing the
length data too. Add + use a little helper function to check the
length is actually there.
2017-02-14 14:21:03 +02:00
Pavlina Moravcova Varekova f71874dc0e Fix test 226
"--noreplace" was omited and results were set according to the wrong
test (+ spelling).
2017-02-13 14:12:59 +02:00
Pavlina Moravcova Varekova b4df891bb5 Fix confusing %defattr/%attr error messages
Mistakes in %defattr/%attr such as "%defattr(123, root, root, x750)"
will give a confusing and misleading errors like:

     error: Bad dirmode spec: %defattr(123)

Make a copy of the all the arguments to make the error sensible:

     Bad dirmode spec: %defattr(644, root, root, x755 )
2017-02-13 14:06:50 +02:00
Panu Matilainen b04dcc306e And another out of bounds read in PGP parser
pgpPrtSubType() assumes there is at least one byte of packet body
for it to process, check the lower boundary too. The check for
pgpLen() zero return is slightly confusing and perhaps the reason
why this has been overlooked: zero return from pgpLen() is an error
alright, but in order to store the perfectly legal packet body length
you need one byte nevertheless, so pgpLen() returns 1 for zero-length
body.
2017-02-09 11:36:51 +02:00
Panu Matilainen c4b35c45ac Clean up doScript() a bit by assuming failure, no functional changes 2017-02-08 12:32:04 +02:00
Davide Cavalca 007a405b98 selinux: use string_to_security_class() instead of class ID
SELinux recommends to use string_to_security_class() instead of referencing
class IDs directly. This also fixes a build issue for systems that don't
include flask.h by default.

References:
https://selinuxproject.org/page/NB_Imp_SELinux-aware_Apps#Implementing_SELinux-aware_Applications_2
76913d8adb
2017-02-08 11:25:25 +02:00
Panu Matilainen d63ec5b1a1 Fix a rather obvious typo in ndb is_correct_db()
The idea quite clearly is to compare the two different stat results,
not an inode number with itself.
2017-02-08 10:01:07 +02:00
Panu Matilainen 0821d69b0c Handle OpenPGP reserved tag correctly
RFC-4880 states tag value 0 is reserved and that packet tag
MUST NOT have this value, so we should error out and not just chug on.
2017-02-08 09:51:09 +02:00
Panu Matilainen 4ab3e0c5d1 Fix out of bounds read(s) when determining PGP packet version (#149)
Add a helper function for checking boundaries (can I have just one
teeny weeny bite - erm - byte, please?) and returning the version,
use systematically where it matters.

It *might* be okay to do this at start of pgpPrtPkt() once and for all,
but then AFAICT OpenPGP does not forbid zero length body in general,
plus there are multiple callers for getFingerprint() so might as well
check individually in the callers that actually care.
2017-02-08 08:44:30 +02:00
Panu Matilainen 657553ffab Fix out of bounds copy on malformed PGP packet (#148)
Validate the packet is of correct size for the keyid type before
copying. Ditto for similar code in signature creation time.
2017-02-07 12:08:54 +02:00
Panu Matilainen e843855527 Make peach with doxygen >= 1.8.8 (#131)
Doxygen >= 1.8.8 skips files with unknown (or missing) extension,
whereas previously they were assumed C-like. Rename the Doxyheader
files to Doxyheader.h to keep the C-association, adjust makefiles.

Thanks to Pavlina Varekova for chasing this down!
2017-02-06 13:07:00 +02:00
Panu Matilainen 3a07ba3ba6 Sanity check header tag values. Like, doh.
There's a check for total number of tags, and their types and all
but absolutely no check for the actual tag numbers. So we end up
accepting negative tags which should not exist. The tag type should
really be uint32_t but that's another can of worms, lets have something
easily backportable for now.

This is enough to fix issues #133, #135, #136, #138 and #139 on the
level of detecting header structural inconsistency.
2017-02-03 11:27:52 +02:00
Panu Matilainen 90afaf5111 Fix minor memleak in signature checking
In case of disablers we continue to the next item without
freeing possible error message from rpmSigInfoParse(), handle
this similarly to the other signature parameters.
2017-02-03 11:01:46 +02:00
Panu Matilainen e0eab77cd6 Fix thinko vrt unknown and other signature types in rpmpkgVerifySigs()
"Other" signature types are sizes and the like whose values we don't
care about in here, but whose types we validate and want to be sane.
So take errors from rpmSigInfoParse() into account, but skip
rpmVerifySignature() because it doesn't make sense for the "other" types.

On the other hand, unknown types we should just skip, this is necessary
to avoid unnecessarily breaking forward-compatibility.
2017-02-03 10:52:04 +02:00
Panu Matilainen db1a33c8d3 Prevent double-free on hdrblobRead() failure (#147)
Introduced in recent header read/init/parse refactoring: when
hdrblobInit() fails via hdrblobRead(), the allocated memory is freed
but hdrblobInit() would already have assigned it to blob->ei.
Normally this is not an issue but rpmpkgVerifySigs() codepath differs
from the other paths in that it does not end in importing the header,
so it needs to free blob->ei by itself. Which doesn't go so well
if hdrblobRead() already freed the memory pointed to by blob->ei.
Ensure it's set to NULL on failure to prevent this kind of accidents.
2017-02-03 09:22:32 +02:00
Bernhard M. Wiedemann 0e87aed178 set SOURCE_DATE_EPOCH from changelog
if requested by macro
to allow for more reproducible builds of packages.

See https://reproducible-builds.org/ for why this is good
and https://reproducible-builds.org/specs/source-date-epoch/
for the definition of this variable.
2017-02-01 14:53:40 +01:00
Florian Festi c004d7647e Add example for multi threaded compression xz settings 2017-02-01 11:02:30 +01:00