Commit Graph

1859 Commits

Author SHA1 Message Date
Panu Matilainen e571df4b9c Add copy control and in particular, destructor to the macro context
The macro contexts being static structs, they get their destructor
automatically called at program end. Which counter-intuitively *causes*
a leak if macros are stored in an STL container and rpmFreeMacros()
isn't called, because then the container clears itself and the macros
are left dangling, whereas without the destructor they are still
reachable. freeMacros() obviously wants to be a member function but
trying to keep things in the struct land for now.

Doesn't really change anything as of now, but this is needed for moving
the macro storage to C++ container.
2024-04-30 09:06:24 +03:00
Panu Matilainen f23483f629 Replace temporary argv array in Lua posix.exec() with a vector 2024-04-25 13:25:02 +03:00
Panu Matilainen bac494c35c Replace a couple of local IO buffers with a vector 2024-04-25 13:25:02 +03:00
Panu Matilainen 99e26b9df5 Replace homegrown mallocing getcwd() with filesystem::current_path() 2024-04-25 13:25:02 +03:00
Panu Matilainen 5f7be71090 Use strings as keyid and STL map for keyring storage
C++ strings can hold \0's so we can use it for convenient storage of
keyids, passing them to C requires special attention anyhow. And then
we can easily replace all array bookkeeping and lookup fubar with
STL map. We could just as easily use unordered_map, but map matches
what it did before so...
2024-04-25 13:25:02 +03:00
Panu Matilainen e2722fd423 Take advantage of rvasprintf() in rpmlog()
rpmlog() predates rvasprintf() by something like two decades, but no
reason not to use it now. One malloc() down, yay.
2024-04-25 13:25:02 +03:00
Panu Matilainen 695b5c2521 Fix multiply defined local macros escaping scope
freeArgs() only popped any local macros once, so if a local macro was
pushed multiple times, whether through %define or multiple identical
options getting passed, we leaked any remaining macros to the outside
scope.

Simply pop the local macros in a loop to fix. Have the internal
popMacro() return the previous pointer (if any) to simplify the job.
We even had an expected-fail test for this, now passing, but add a
more straightforward reproducer too.

This bug was circa 26 years old. Some might call it vintage at this point.

Fixes: #3056
2024-04-24 11:06:35 +02:00
Panu Matilainen e6d6b49f2f Unbreak zstd compression from 7462ad4dbe
A stupid newbie C++ error, array allocation would've been "new uint8_t[nb]"
and requiring delete[] as well. Use a vector instead, then we don't
need to manually free or track the size.

We really need to test the optional io types too, eww.
2024-04-24 09:14:51 +03:00
Panu Matilainen 317dadbdbe Natively allocate expression most parser structs 2024-04-23 09:36:51 +03:00
Panu Matilainen 7e558e3de6 Natively allocate keyring and pubkey structs
Use vector for pubkey packet storage as well to bring down the number
of mallocs.
2024-04-23 09:36:51 +03:00
Panu Matilainen eb561c88bc Use c++ string for rpmExpand() helper buffer 2024-04-23 09:36:51 +03:00
Panu Matilainen 59984c66c5 Use a c++ string for macro expansion buffer
Natively allocate the struct so we can use a string in there.
2024-04-23 09:36:51 +03:00
Panu Matilainen 1721962889 Use C++ constructs for rpmlog internal storage
Change the log record message to a string and then the records can be
stored in a vector without requiring custom destructors and all that.
2024-04-23 09:36:51 +03:00
Panu Matilainen 344e837f1a Replace internal Lua printing stack with a C++ stack 2024-04-23 09:36:51 +03:00
Panu Matilainen 9af6b4f39f Replace internal Lua print buffer with a C++ string 2024-04-23 09:36:51 +03:00
Panu Matilainen ad80c1761e Natively allocate internal rpmlua structs
Eliminate raw calloc/malloc uses, just new/delete for the parts that
end up on C side but our first vector uses too for some temp arrays.
2024-04-23 09:36:51 +03:00
Panu Matilainen 7462ad4dbe Natively allocate rpmio structs
Rename some internal structs to common style, the dust is thick in this
part of the cellar. In particular "lzfile" as a struct name clashes with
our local variables, don't do that.
2024-04-23 09:36:51 +03:00
Panu Matilainen 0d1071b99a Minimally convert digest code to native c++ allocation
Some background + rationale that will apply to a lot more commits going
forward and not going to keep repeating it all, so using this as a cover
letter of sorts:

Converting rpm to something resembling C++ is going to be a multi-year
operation, and what is being done here is just the first step of many.

Moving to native C++ allocation seems like an important first step as it
allows using non-trivial C++ data types (such as strings) in said constructs
(with malloc/free, destructors do not run). Also, it brings down the
number of raw C allocations with their ugly casts. It's worth nothing
that we'll never be free of raw mallocs entirely as some of the allocations
we return are expected to be free()'d from C, such as the output
parameter of rpmDigestFinal(). So we just want to get to the state where
ALL C-style allocations are for data going across the API border as
quickly as possible, the mixed state of things is ugly and fragile.

In many places rpm is relying on calloc() or memset() to zero-initialize
structs, but this cannot be used on C++ structs with "non-trivial" data
types such as strings, STL containers and the like. The {}
initialization is the nearest C++ counterpart for that. It'd be safer
to place the initialization(s) in the struct members directly but we're
shooting for minimal changes at this point, that'll come later.

Finally, we are using "naked new" because many of our pointers are going
across the API border to C where smart pointers simply cannot be used,
not without extra tricks anyhow. We don't want to worry about that just
now. We'll be using "naked new" for internal pointers too initially, again
just to keep changes minimal.
2024-04-23 09:36:51 +03:00
Michael Schroeder 4e9458ecca Add the "Primary Binding" pgp signature type
This type is needed to verify the primary binding signature
embedded in subkey binding signatures.
2024-04-22 15:21:39 +03:00
Michael Schroeder 200c91ff72 Relax openssl version requirement
And also delete the no longer needed include statements.
2024-04-18 12:50:24 +03:00
Panu Matilainen 8c7d8d9412 Remove the WITH_CXX option, this is a one-way street 2024-04-09 11:00:00 +03:00
Panu Matilainen 62840a3cdf Add casts that C++ requires but C doesn't across librpmio
In other words, a whole lot of "yes, really".
2024-04-09 11:00:00 +03:00
Panu Matilainen 656c8e75f5 Fixup missed constification in Lua readline callback
Should've been in commit 38b2602142
2024-04-09 08:16:18 +03:00
Panu Matilainen f8a72afbdb Fix pointer bogosity in rpmlog callback
rpmlogCallbackData is already a pointer type, we don't want a pointer
to a pointer for this. Kinda surprising it actually worked, but then
it's just a void pointer so...
2024-04-09 08:16:18 +03:00
Panu Matilainen 5231d5f54d Make rpmmacro_internal.h self-standing, ie include what you use 2024-04-09 08:16:18 +03:00
Panu Matilainen 396c8e8201 Handle Lua header C++ guards centrally in rpmlua.h
Upstream Lua headers lack C++ guards, argh. Lump them all into rpmlua.h
and deal with it centrally there. In the past we've avoided including
Lua there but now that Lua is mandatory it doesn't cause other issues.
2024-04-09 08:16:18 +03:00
Panu Matilainen 437b5a1068 Avoid jumping over variable declarations
C lets us do this but in C++ needs to run destructors at end of scope,
so they better be properly initialized...

These are all over the place but so trivial putting them to different
commits doesn't make much sense.
2024-04-09 08:16:18 +03:00
Michael Schroeder fec1bd8d2a Add the "issuer fingerprint" subpacket type
This subpacket is an alternative to the "issuer keyid" subpacket.
It contains the pubkey version plus the complete fingerprint.
2024-04-09 08:12:14 +03:00
Panu Matilainen 4174de56d0 Fix couple of obvious'ish signed narrowing issues in rpmio code 2024-04-05 16:16:22 +03:00
Panu Matilainen 38b2602142 readline callback const correctness 2024-04-05 13:18:27 +03:00
Panu Matilainen 9a345d1913 Use an union for the zstd compress/decompress streams instead
Cleaner than void pointer and avoid casting.
2024-04-05 13:18:27 +03:00
Panu Matilainen f75cd15f85 Wrap rpmio inner file pointer access behind typed helper function
Otherwise we'd need casts for each of these accesses, having a function
allows doing more if necessary.
2024-04-05 13:18:27 +03:00
Panu Matilainen 5010191f6d Work around C++ restriction on forward declarations
Forward declarations to structs like we have in rpmio isn't legitimate
C++, as a minimal bandaid solution declare them as extern in the
internal header, and limit visibility.
2024-04-05 13:18:27 +03:00
Panu Matilainen 7445a092f7 Lift %shrink out of doFoo()
This really belongs to a separate function in the first place, and doing
so allows us to turn 'b' into a const char *, which in turn makes
the assignment to string literal "" in the url2path case legitimate.
Fun times and no functional changes.
2024-04-05 13:18:27 +03:00
Panu Matilainen 3a2b04c96d Avoid relying on writable string literals in macros
This hack here is illegal in c++. Just strdup() the silly little string,
it's not like this is a performance critical spot.
2024-04-05 13:18:27 +03:00
Panu Matilainen 401d845d99 Add c++ guards to internal headers and sources as needed 2024-04-05 13:18:27 +03:00
Panu Matilainen f734e1724d Sanitize rpmGlob() behavior wrt non-glob patterns
Previously rpmGlob() has behaved as if GLOB_NOMAGIC was passed, ie
return non-globbed patterns as is without bothering to check if
there are actual matches. This makes for weird and surprising behavior:
~/.notthere would return no match, but /home/user/.notthere returns a
match. Which makes no sense whatsoever.

Rather than clone all the glob() options to the rpm interface, link
this to the NOCHECK flag: the callers who are prepared to deal with
non-existent files are already using RPMGLOB_NOCHECK, and all the
rest actually expect all the matches to be there.
2024-03-26 10:52:57 +01:00
Panu Matilainen 63e369cd35 Split off the internal OpenPGP parser to a separate repository
Now that we have an alternative to building without Rust, it's time
to say bye to this old thing. We will not support the parser but
preserve minimal hooks in cmake to allow building with it, at least
for a transition period:

	https://github.com/rpm-software-management/rpmpgp_legacy

Fixes: #2414
2024-03-20 14:08:24 +02:00
Panu Matilainen 0334bc7370 Prepare to cutting out the internal OpenPGP parser for good
Push the build option into the rpmpgp_legacy directory so it doesn't
show up at all unless the directory is present, and rename it to
WITH_LEGACY_OPENPGP to better reflect the status: it's hardly internal
if it lives in a separate repo, and it's something you should not use
going forward.

Add a terse README to the rpmpgp_legacy directory as the initial to-be
repo description to explain the status and intentionally vague build
instructions: if you don't know then you really should not.

Also add a separate COPYING file there: the parser originates from
rpmio/ so it falls under rpm's dual license, just simplify the text
that makes no sense in the new context.
2024-03-20 14:08:24 +02:00
Panu Matilainen 725ca51695 Allow building rpm without OpenPGP support
For bootstrapping purposes, having rpm depend on Rust is painful, but
directing people to unmaintained crypto code as an alternative is
hair-raising. As a middle ground, let rpm be built without OpenPGP
support at all, which at least gives you a functional rpm and rpm-build
even if you can't sign or verify signatures.

Achieving this is a moderately complex dance which can't meaningfully
be split into multiple commits because everything is interconnected:

Add a new WITH_SEQUOIA option to control use of Sequoia, on by default.
When Sequoia is disabled, default to a newly added dummy PGP implementation
instead which just returns error on everything. And finally, if the
older WITH_INTERNAL_OPENPGP is enabled, use the old PGP implementation.

As the intent is to cut out rpmpgp_legacy to a separate repository,
sanity requires that we also split the openssl/libgcrypt code at the
digest/signature fault line. It's not ideal, but the alternative of
having unused crypto code on which an external component depends on
is just not sustainable. This way, the signature side of things is
quite neatly cut off with the PGP stuff. The diff looks big but there
are no code/functional changes in the libgcrypt/openssl split.
2024-03-20 12:42:33 +02:00
Panu Matilainen 1377d5f3b0 Drop silly "register" use from our allocation routines
I guess somebody somewhen a long long time ago thought this would make
it go that little bit faster. It doesn't.
2024-03-18 10:12:39 +02:00
Panu Matilainen 46bd0ed2a9 Document fork, exec, wait and redirect2null Lua functions as deprecated
Rpm scriptlets should have no business dealing with this level of
detail in process control, rpm.execut() is much saner and safer
for scriptlet needs. We can't just remove because this is a public
API with known users (eg glibc in Fedora), but we can at least document
these as deprecated with noisy warnings.

fork() and exec() are the main "problems" here, but wait() and
redirect2null() become meaningless once you take the first two away.

Fixes: #2420
2024-03-14 15:16:11 +01:00
Panu Matilainen 8de699ee70 Issue a warning when passing arguments to non-parametric macros
This should be an error for consistency with other macro argument
checking but as there appear to be usages in the wild, make it a
warning for now.

Fixes: #2932
2024-03-14 10:30:30 +01:00
Florian Festi 3ad98187cc Use basename (3) for the %basename macro 2024-03-07 12:39:19 +01:00
Florian Festi 9571e3d9a2 Use dirname (3) for %dirname
This changes the behaviour of %dirname to something sane. No longer
return the argument unchanged if there is no / found. Also handle
several cornercases properly.

Resolves: #2928
2024-03-07 12:39:19 +01:00
Panu Matilainen 1c8443a2a8 Fix an UB in expression code (when built without -fno-strict-overflow)
Sigh. Having to fiddle with such stuff is just so, so dumb.
2024-01-31 10:55:38 +02:00
Panu Matilainen 04b3317e61 Fix a bunch of argv leaks in the Lua extension 2024-01-31 10:13:08 +02:00
Panu Matilainen a77c1d0670 Fix libintl linkage and include directories (cmake transition fallout)
We checked for libintl in the top-level CMakeLists.txt but then never
used it for anything. This only ever worked on glibc where this all
is bundled in. Unfortunately Intl only becomes an importable target
in cmake >= 3.20 which is too new for us to rely on for now.

Python bindings are omitted here because we don't have any translated
messages in there. Whether we should is another topic.
2024-01-08 12:32:35 +02:00
Panu Matilainen 6e507ddd9c Cosmetics: fix rpmio cmake indentation style 2024-01-08 12:32:35 +02:00
Panu Matilainen 57f3711846 Fix unconditional dependency on non-POSIX GLOB_ONLYDIR flag
This regressed when we axed our internal glob copy in commit
66fa46c006. Luckily GLOB_ONLYDIR is only
an optimization so we can just skip it if not available.
2024-01-08 12:32:35 +02:00