Commit Graph

13605 Commits

Author SHA1 Message Date
Panu Matilainen 7f428ecf6e Don't bother with headerVerifyInfo() on region tag
The region tag is hand-checked for its special values in
headerVerifyRegion() and now that v3 packages get the first tag
checked (commit 1c25d27895), there's
little point in calling headerVerifyInfo() on the the region tag.
2016-11-17 12:29:11 +02:00
Panu Matilainen 1c25d27895 Enable data overlap check on 1st tag of v3 packages
The region tag data (aka region trailer) violates the regular ordering
of tag data and can't be checked with headerVerifyInfo() in one go,
but for v3 packages without the region tag start again from tag 0
to get data overlap check on the whole thing, for both headers.
As a side bonus makes the signature code again that little bit
closer to the other header...
2016-11-17 12:17:45 +02:00
Panu Matilainen 67709078a7 Add back separate check for tag data offset range
This used to be there before commit 89dce2b91d
sort of made it unnecessary, but since then we've started looking
at the actual data in case of string tags, so there's new opportunities
for trouble as well - witness commit
1b93f23579. So this is kind of a
belt-and-suspenders thing...
2016-11-17 11:30:13 +02:00
Panu Matilainen 1b93f23579 Make sure start pointer is legal in strtaglen()
strtaglen() takes care not go fall off the edge off the world... except
if you make it start there. Oops.
2016-11-17 11:27:59 +02:00
Panu Matilainen 6bada81529 Make filter query/verify by file attributes generic
We only have a disabler for %ghost files ATM but that doesn't mean
the actual code can't be generic, the logic is actually much clearer
this way (especially compared to the to-negate-or-not-to-negate
fun on verify side)

One might envision a generic way to set filters via a cli argument to
go with this, eg --noattr=cd to skip documentation and configs,
or --noattr=g as an alias to --noghost.
2016-11-17 10:50:18 +02:00
Panu Matilainen bb27f9fffa Fix %ghost verification and --noghost behavior (RhBug:1395818)
Verify has "always" accepted --noghost as an option but it's always
been broken too, the --noghost option used to *clear* the bit on
qva_fflags, bit which nothing set in the first place. When you
test that bit for enabling verify on ghosts, chances are the ghosts
remain ethereal...

That was until commit efd696d32d fixed
the bit clear to set to make --noghost work on queries, but hardwired
the verify code to no ghosts. Wtf?

So... after 15 years of existence (commit
60977b6c27) and somewhat colorful
history, lets make it work and document it too. qva_fflags is supposed
to be a "filter out if matching attribute in file" bitfield but its been
kinda hard to tell when there was one example left which had it the wrong
way around. The original commit has two more examples where the bit setting
is right but disabled with "ifdef NEVER" ... since removed.
2016-11-17 10:14:01 +02:00
Panu Matilainen e1f847db58 Oops, missed early return from headerVerifyInfo()
Should've been in commit d022809023,
I need new eyes...
2016-11-17 08:49:15 +02:00
Panu Matilainen 05c7dc7ce0 Use hdrchkRange() for the region range check, covers both ends... 2016-11-16 17:45:21 +02:00
Panu Matilainen c4f746c424 Don't bother with headerVerifyInfo() on already validated data
Now that we're verifying the entire header (as of
commit 0d36fc4cba) there's little point
in revalidating the same data here again. Just call ei2h() for endianess
correction instead.
2016-11-16 17:40:08 +02:00
Panu Matilainen 0d36fc4cba Always sanity check the entire header, not just immutable region
To begin with, rpm v3 packages don't HAVE an immutable region. Which
means that for v3 packages whose signatures we cannot verify on normal
paths, we'd also miss even the most basic of sanity checks because
ril on v3 packages is zero.

For installed packages this also enables data overlap checks for
tags outside the region, which up to now have been checked but only
one by one in headerSigVerify().
2016-11-16 17:27:18 +02:00
Panu Matilainen 8602e474eb Make headerVerifyInfo() return code sane
Return zero for zuccess (haha) like most of the world does, -1
for success is so bizarre it's like violating the principle of
least surprise on purpose. Callers only ever cared about the
non-success value for error reporting but since that is taken
care of by headerVerifyInfo() it doesn't matter at all. Return
the ordinal of failing tag achieves the same should anybody care.

Leaving the error message to actual index number to keep the message
compatible, not that its likely to matter.
2016-11-16 13:43:09 +02:00
Panu Matilainen 7010c677b0 Enable data overlap checks for signature header too
For whatever historical reason rpmReadSignature() had its own loop
for calling headerVerifyInfo() on each tag one by one. Not only is
this redundant since headerVerifyInfo() can loop on its own and a
wholly unnecessary difference between the signature and regular header,
it also misses the opportunity to perform data overlap checks on the
signature data.
2016-11-16 13:26:41 +02:00
Panu Matilainen e4705b4181 Tolerate NULL info retval argument to headerVerifyInfo()
Use a local temporal if info is not supplied, half the callers
don't care anymore.
2016-11-16 13:13:20 +02:00
Panu Matilainen 8dda888e14 Fix off-by-one stack write in rpmGlob() (RhBug:1371914)
Happens with eg pattern "~0//0", easily visible if alloca() is changed
to malloc(). Reported as a security concern, dunno about that but a bug
it is anyway.
2016-11-16 10:55:50 +02:00
Panu Matilainen 1545e71d87 Validate string data lengths too on headerVerifyInfo()
For this we need to pass dataStart into headerVerifyInfo(), and
then we can actually just call dataLength() to do the hard work.
There's a non-trivial cost involved of course, especially since we
now do this twice, but better slow than sorry. We can always
make things smarter later on, and this closes down a major hole
in how rpm deals with header data.
2016-11-15 14:26:10 +02:00
Panu Matilainen ffeed045ad Add error message retval argument to headerVerifyInfo()
Collapses four copy-paste variants of the theme into one.

But, wait - this loses "sigh " prefix on signature header errors!
Oh, the tragedy!
2016-11-15 14:01:34 +02:00
Panu Matilainen d022809023 Refactor single exit point to headerVerifyInfo(), no functional changes. 2016-11-15 13:41:19 +02:00
Panu Matilainen 6ca9a406cf Eliminate redundant helper variables in header digest/signature verification
We're ultimately copying the data to the sigtd so why bother with
intermediate info and siglen variables? Use a helper function to
to convert the entry into into td instead, eliminating a redundant
memset + copy on the info struct. Plus the resulting code is that
wee bit more readable.
2016-11-15 13:30:40 +02:00
Panu Matilainen 4fe0f0f4ad Avoid unnecessary malloc + copy on header digest/signature verification
No idea why the copy was there, maybe it was needed at some point.
2016-11-15 13:08:56 +02:00
Neal Gompa (ニール・ゴンパ) 2797d00ecd python: remove redundant suffix in python module name in metadata
No one is quite sure why there's a redundant '-python' suffix,
but the module isn't named that, and typically we want the name
in the metadata to be the same as the name of the module.

This has no effect on Python code itself, as it doesn't change the
name of the installed module used in import statements, and since
we've never published to PyPi, it's not something that can be sanely
referenced for 'pip' and other similar tools in a useful manner.
2016-11-11 13:36:14 +01:00
Panu Matilainen 8f3c798b12 Make package exists/does not exist error more informative
Rearrange the message to "linenum: line: message" which is a more
logical order of things (I think), and in particular, include the
actual actual package name in the message. In order to do that,
consolidate the error logging inside lookupPackage() where we
now get a slightly hysterical logic around the error messages but what
the hey, its not like this is an exported API.
2016-11-11 14:26:03 +02:00
Panu Matilainen 52e9b5efde Ensure that file trigger conditions are paths. 2016-11-11 13:42:47 +02:00
Panu Matilainen dd7af7ed6e Ensure that a trigger condition actually exists.
All this time rpm has merrily accepted a trigger with no condition
at all, eg "%triggerin --". Doh. Check and error out on missing trigger.
This is all ridiculously subtle and fragile - pay attention to splitting
the line only after all error messages have been done for full error
message, but since we're now moving s further on whitespace we need
to store the separation point into another helper to avoid breaking
the other %trigger line semantics.
2016-11-11 13:16:59 +02:00
Panu Matilainen 8fc3a220b3 Revise trigger separator checking a bit to pave way for next commit
Make the missing separator check more obvious (check s, not reqargs),
jump over a potential separator when found, and eliminate a leftover early
return causing memleaks. Apart from memleak, shouldn't actually change it.
2016-11-11 13:14:06 +02:00
Panu Matilainen c217b60a7b Require whitespace around trigger -- separators (RhBug:1352828)
"--" in filenames and such might be rare but it can exist, requiring
whitespace surrounding the separator is the only sane thing to do.
Would be easier to strstr() on " -- ", but inevitably that would
break somebodys tab-aligned spec so...

For anybody suspiciously looking at the pointer arithmetics: "--" cannot
be at the beginning of a line which gets us here so s-1 has to be safe,
and on the other side there has to be at least the trailing \0 at s+2.
2016-11-10 16:58:59 +02:00
Panu Matilainen 723a618dcc Log a warning about possible unexpanded macros in NVR
This is a sort of too-little-too-late bandaid for the issue
in RhBug:547997 / commit 507f21f6bb.
Unexpanded macros here are almost certainly packaging bugs,
except if they happen on a parse for build-requires when its
more beneficial to just let the unexpanded stuff through. We dont
have a means to separate between build-dep parse and build but
lets at least warn about these things. Refactor the logging into
a helper function to avoid umptheen cases dealing with warnings
and errors and spec or no spec etc.
2016-11-10 15:45:52 +02:00
Panu Matilainen ccdb1aa5c6 Fix debuginfo etc when subpackages have different versions (RhBug:1051407)
Rpm has always been a bit dazed and confused when it comes to specs
with sub-packages having different version etc from the main package.
Many things work fine in that case .. except .. when they dont. Debuginfo
picking up wrong versions (RhBug:1051407) is just one example, there
are countless more in bugzilla wrt buildroot paths and whatnot.
The simple and sane solution would be not piling on them macros
from sub-packages, but that would surely break somebodys precious
spec tricks.

The ugly but brutally simple and compatible solution to this all is to
create separate set of macros when on the main package, this lets users
in and out of rpm pick which one (latest or main) they want. To hopefully
avoid stomping on anybodys toes, use uppercasing for the macro name (other
variants like %pkg_release are awfully commonly used). Pile 'em on, yay!
2016-11-09 09:55:05 +02:00
Panu Matilainen fb47bc09f8 Fix possible unitialized use in pgp code 2016-11-08 12:05:46 +02:00
Panu Matilainen 02bc5e2139 Fix linear search fallback case in rpmfnFindFN()
Building with -Og reveals m being possibly ununitialized here,
and on closer inspection there's an actual bug here: on linear
search cmpPoolFn() needs the increasing index, not trying the
same (in theory possibly uninitialized) value of mid.

Fixes regression introduced by yours truly in commit
9bf578376d. Oops.
2016-11-08 12:04:25 +02:00
Panu Matilainen 1ba05a7456 Copy all possible special %doc/%license files before checking errors
Prior to commit f16a522ca4, failing
as early as possible was the only way to catch errors. However
now that rpm actually checks for the files by itself, this behavior
can lead to really confusing error messages. For example if the
first %doc of, say, twenty files is missing, you'll get error messages
for all twenty.

So don't stop copying on errors but copy as much as possible and
check for errors last, this way the actually missing files will
stand out.
2016-11-07 16:56:26 +02:00
Panu Matilainen f6521c50f6 Fix %transfiletriggerpostun undeterministic behavior (RhBug:1284645)
Keys from rpmdbIndexIteratorNext() are not necessarily \0-terminated,
buyer beware.

Sometimes you get lucky, but in particular when built as PIE (such as
by default in Fedora) this falls over consistently.
In Fedora this has been hidden by the fact that test suite has been
disabled because its been so broken with fakechroot until recently,
and without PIE the testsuite regularly passes. Valgrind does
complain though.
2016-11-07 13:46:04 +02:00
Panu Matilainen 3cac383bb8 Drop special hackery to force rpm into /bin/rpm
Let rpm go into $(bindir) along with everything else, it just isn't
that special. Many distros are nowadays symlinkingbin to usr/bin anyway
which makes the special casing of /bin/rpm even more silly.
Somebody wants to put it someplace else, 'mv' is your friend and
I'm not going to stop you.
2016-11-04 13:16:02 +02:00
Panu Matilainen bd9f53bb7b Link test utilities in $(bindir) instead of hardcoded /usr/bin
This isn't 100% correct but more so than the former version:
"make distcheck" now completes, whee! The test-suite fails left and
right with path issues during it so there's more work to do however.
2016-11-04 12:49:17 +02:00
Panu Matilainen ecb4182655 Ensure test data is removable when cleaning
During distcheck the test data is copied from a read-only tree, so without
this chmod, clean-local will fail due to permissions on the data files.
The other data in testing/ gets copied from other sources or gets
permissions explicitly set (eg make install)
2016-11-04 12:12:10 +02:00
Panu Matilainen 77bf115632 Tweak up distclean-local to appease distcheck 2016-11-04 11:47:18 +02:00
Panu Matilainen c896a481f2 Fix "make dist" work out of the box again
ChangeLog is listed as EXTRA_DIST but there's no rule to create it
so dist target is broken except when invoked with Makefile.maint. Which
nobody finds because its such a strange thing to have.

Move back ChangeLog generation into main Makefile.am but do not
require git to create it. Instead have a rule to create an empty
file to appease EXTRA_DIST no matter what, and only create the
real thing if we're in a git checkout and git command is present.
2016-11-04 11:02:50 +02:00
Panu Matilainen 97c78d1d48 Oops, update POTFILES, lib/legacy.c is no more
Should've been in commit ab24d7aa54
2016-11-03 10:03:51 +02:00
Panu Matilainen 826a839c03 Add/fix a few missing/misleading doxygen annotations 2016-11-02 13:37:09 +02:00
Panu Matilainen 84efd17423 Fix internal headers getting pulled into API docs
The issue is probably as old as the librpm API docs in itself...
2016-11-02 13:27:10 +02:00
Panu Matilainen 4182b8a9a6 C files do not belong to API docs 2016-11-02 13:19:36 +02:00
Panu Matilainen e6639abf33 Drop CHANGES out of dist tarballs
It's almost 10 years out of date, people are better off looking
at git changelog now.
2016-11-02 12:10:30 +02:00
Panu Matilainen 5c74ebd725 Refactor verifyHeader() to use rpmfiVerify()
Replace manually maintained yet-another-return-code with an
"all failures" variable and base the actual return code on that.
It's tempting to use just one verify result variable but that'd be
wrong because of the shared file mtime filtering.
No functional changes intended.
2016-10-27 16:31:00 +03:00
Panu Matilainen 82933fd17e Add support for file verification in python bindings
Note that this is for rpmfile only, intentionally NOT adding this
to the rpmfi python representation which is deprecated.
omitMask is optional, otherwise identical to its C counterpiece.
Untested but hey, it works in C - what could possibly go wrong.
2016-10-27 16:06:27 +03:00
Panu Matilainen 776b504a73 Export relevant RPMVERIFY_FOO symbols to python
There are some obsolete enums like LGETFILECONFAIL around, no point
bringing those to python at this point.
2016-10-27 16:01:07 +03:00
Panu Matilainen 591f95a849 Export file verification as a rpmfiles/rpmfi method
Turn rpmVerifyFile() into indexed rpmfilesVerify() method but
drop the unnecessary double return code which also "fixes" the
oddball argument order where return value is not last, add
thin wrapper for rpmfi iteration. Mark rpmVerifyFile() deprecated
due to the strange calling conventions and unused arguments.
Leaving the code in verify.c to make it clearer what changed, looks
a bit out of place but doesn't matter as it doesn't need access
to rpmfi(les) internals.

Verification functionality as such is supposed to be unchanged by this.
2016-10-27 15:38:09 +03:00
Panu Matilainen f286b7a84f Refactor rpmVerifyFile() a bit to clarify exit code
Use a local helper variable for collecting verification results,
arrange a single exit point for the function and base the return
value on the verify result to make it clear what the return code
actually means. As a sort of side-effect its now legal to call
rpmVerifyFile() with NULL res, not that it makes a whole lot of
sense to do so since all the interesting stuff is there. But useful
for next refactoring steps...
2016-10-27 14:55:15 +03:00
Panu Matilainen 0afc0017fb Don't adjust stat file size on rpmDoDigest() failure when verifying
The size is likely to be wrong anyhow but if we can't read the file
then any correction is likely to be more wrong than the original value.
While at it, eliminate an unnecessary function-level temporary
variable used for this one purpose only.
2016-10-27 14:46:44 +03:00
Panu Matilainen bfc63b6c3b Use proper datatypes for headerVerifyInfo() args
Now that we can, lets use the actual data types instead of void
pointers and be const-correct about it as well. Which immediately
points out a missing const in ei2h() first arg...
2016-10-27 11:39:01 +03:00
Panu Matilainen d0c1081c33 Drop unused negate argument from headerVerifyInfo()
Now that we've declared headerVerifyInfo() internal we're free to
do things with it. Even *gasp* improve, mayhap..
2016-10-27 11:30:19 +03:00
Panu Matilainen 83a8640b47 ...and finally bury the rpmlead datatype entirely inside rpmlead.c
Since rpmLeadWrite() takes a header there's no more need for
rpmLeadFromHeader() to be "public" and since nothing returns
leads there's no need to free them either, make static + adjust
to eliminate the need for ever allocating a lead so the free func
can go too. Whee. the remaining rpmlead.h is something we could
actually consider making public.
2016-10-27 11:08:25 +03:00