Commit graph

2896 commits

Author SHA1 Message Date
Andrew Gregory
edd57c8b96 perform cleanup on sync db parsing errors
Cleanup was only being performed when libarchive failed to actually read
the file.

Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
2024-02-07 12:27:26 +00:00
Andrew Gregory
5c75a55c7d allow freeing partial db package cache
The free function was checking DB_STATUS_PKGCACHE, which is only set
once the package cache has been fully built.

Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
2024-02-07 12:27:26 +00:00
morganamilo
bf76b5e89f libalpm: correctly log curl_download_internal return value
Signed-off-by: Allan McRae <allan@archlinux.org>
2024-02-04 10:23:34 +10:00
Allan McRae
ce528a2654 libalpm/discspace.c: ensure mount points provide directories
In the very unlikely situtation where getmntent() and friends return
non-null, but the mount directory is NULL, a null dereference could
occur. It is unclear what the best course of action is in this case,
so just move on to the next mount point.

Signed-off-by: Allan McRae <allan@archlinux.org>
2024-02-04 09:02:36 +10:00
Allan McRae
f996f30163 libalpm/remove.c: prevent undefined behaviour in shift_pacsave error path
Signed-off-by: Allan McRae <allan@archlinux.org>
2024-02-04 09:02:36 +10:00
Allan McRae
2079f6866a alpm_list_reverse: restore original list on failure
Signed-off-by: Allan McRae <allan@archlinux.org>
2024-02-04 07:56:00 +10:00
Allan McRae
845dadf183 _cache_mtree_open: remove unused variable
Signed-off-by: Allan McRae <allan@archlinux.org>
2024-02-04 07:56:00 +10:00
Allan McRae
c64f898c48 _alpm_pkg_load_internal: remove unneeded if statement
This statement is always true due to an earlier test.

Signed-off-by: Allan McRae <allan@archlinux.org>
2024-02-04 07:56:00 +10:00
Allan McRae
16a2a79728 libalpm/signing.c: prevent underflow in length_check
The length_check function could underflow if the provided buffer index
is greater than the signature buffer length, leading to an out of
bounds read.

Signed-off-by: Allan McRae <allan@archlinux.org>
2024-02-04 07:54:12 +10:00
Ronan Pigott
4c93e63ddf add.c: drop newline in permission and ownership log messages
These are the only log messages produced by pacman that include an
embedded newline, and it looks very incongruous in a typical pacman.log.

Signed-off-by: Allan McRae <allan@archlinux.org>
2024-01-10 08:52:35 +10:00
Andrew Gregory
42fa74e91a free handle resources before running scripts
The primary purpose of this is to allow cleanup of file descriptors
allocated by curl that were left open in the child.  I am not aware of
any issues caused by the open file descriptors, but think it better to
not leave random open fd's lying around.

Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
2024-01-09 22:39:14 +00:00
Andrew Gregory
929bad61c0 _alpm_handle_free: free all in-memory resources
Freeing handle resources was previously split awkwardly between
_alpm_handle_free and alpm_release.  This consolidates the freeing of
all in-memory resources to _alpm_handle_free, leaving alpm_release as a
thin wrapper that provides safety checks and frees any external
resources, e.g. removing lock files.

Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
2024-01-09 22:39:14 +00:00
morganamilo
8d38746586
libalpm: fix check_pgp_signature docs
The function did have these return values a long time ago but now only
return 0 or -1.
2023-12-04 15:34:49 +00:00
Andrew Gregory
0df44c2e20 db.c: set pm_errno for server list modifications
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
2023-12-02 04:56:25 +00:00
Andrew Gregory
3aa1975c1d alpm: add cache server support
Cache servers differ from regular servers in that they do not produce
warnings and are not removed from the server pool for "soft errors"
(i.e. the server was reachable, but the download failed) and they are
not used for databases.  If a host is used for both a cache server and a
regular server, it may still be removed from the server pool for soft
errors that occur when used as cache server and removal from the server
pool for soft errors will not affect future attempted use as a cache
server.

Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
2023-12-02 04:56:25 +00:00
Andrew Gregory
56626816b6 dload: differentiate between hard and soft errors
Set error count to -1 to indicate a hard error to allow them to be
treated differently.

Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
2023-12-02 04:56:25 +00:00
Andrew Gregory
2e23126e2a remove unused pkgconfig template
libalpm uses meson's pkgconfig module which does not use the template
file.

Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
2023-11-25 13:04:56 -08:00
Jack Rosenthal
e9b385a636 alpm: Don't chroot() to "/"
chroot() requires CAP_SYS_CHROOT.  If the caller has put us in the
right root directory already, don't call chroot().  This allows
running pacman in a containerized environment without CAP_SYS_CHROOT.
2023-10-23 12:13:10 +00:00
morganamilo
aff12189d8 libalpm: check filecache_find return and log errors
Some user had erros while updating their system.

:: Proceed with installation? [Y/n]
:: Retrieving packages...
checking keyring...
checking package integrity...
error: failed to commit transaction (invalid or corrupted package)
Errors occurred, no packages were upgraded.

The issue was filecache_find returning null and alpm passing that null
path to check validity. How this happened I have no idea. It may be
something to do with the user's cachedir being a network drive.

Also warn when the file exists but it is not a regular file or can not
be opened.
2023-09-30 13:28:31 +00:00
morganamilo
b4f11d5496 alpm: test access of symlinks not where they point
On platforms that have AT_SYMLINK_NOFOLLOW

Fixes FS#69720
2023-09-26 03:37:49 +00:00
morganamilo
015cdb21bd
Fix unused variable warning 2023-09-20 04:32:21 +01:00
morganamilo
2348dcab22 pacman+libalpm: print version names for conflicting packages
When ever pacman prints a conflict, it now prints pkgname-version,
instead of just pkgname.

alpm_conflict_t now carries *alpm_pkg_ts instead of just the
names of each package.

Fixes FS#12536 (point 2)
2023-09-05 01:57:01 +00:00
Allan McRae
471a030466 Avoid NULL deference in curl_check_finished_download
We have not set handle in the function at this stage, so we can not
assign an error to it.  Pass the handle to the function to avoid
waiting until the payload is retrieved.

Signed-off-by: Allan McRae <allan@archlinux.org>
2022-12-13 10:00:13 +10:00
Allan McRae
775d511f42 load_packages: fix memory leak on error
The memory assigned in _alpm_pkg_load_internal was not freed on
error.

Signed-off-by: Allan McRae <allan@archlinux.org>
2022-12-13 10:00:13 +10:00
Allan McRae
19a8587459 _alpm_pkg_load_internal: prevent double closing file descriptor
Move closing of the file descriptor until the end of the function, as
any following error will lead to a "goto error" that attempts to close
it again.

Signed-off-by: Allan McRae <allan@archlinux.org>
2022-12-13 10:00:13 +10:00
Allan McRae
ea83fd3927 Catch possible error in archive_entry_pathname when extracting files
Prevents a null deference on error.

Signed-off-by: Allan McRae <allan@archlinux.org>
2022-12-13 10:00:13 +10:00
Allan McRae
3436bc6c3e Finish comparing all pairs of filenames for duplicates before erroring
This also prevents a use-after-free issue where we free the list we
are interating over and the do i->next.

Signed-off-by: Allan McRae <allan@archlinux.org>
2022-12-13 10:00:13 +10:00
Allan McRae
23aa82812e Fix typo in comment
Signed-off-by: Allan McRae <allan@archlinux.org>
2022-11-08 14:20:36 +10:00
Allan McRae
05e52ef796 Document alpm_pkg_xdata_t type and accessor
Also more definitions to more relevant areas in alpm.h.

Signed-off-by: Allan McRae <allan@archlinux.org>
2022-11-08 14:19:35 +10:00
Allan McRae
b2c9543ea9 Use modern openssl interfaces for calculating MD5 and SHA256 checksum
The currently used openssl interfaces for calculating checksums have been
deprecated in openssl-3.0.  Move to the modern interfaces to avoid build
warnings.

Signed-off-by: Allan McRae <allan@archlinux.org>
2022-11-07 16:58:29 +10:00
Andrew Gregory
da68447ec6 set bash env variables before running scripts
Bash sources user configuration files under a number of conditions that
can cause issues with scripts when bash is used as the scriptlet shell.

Bash assumes it's being run under rsh/ssh if stdin is connected to a
socket and sources the user bashrc unless the environment variable
$SHLVL is >= 2.  Commit 6a4c6a02de
switched from pipes to sockets when communicating with child processes
to work around SIGPIPE issues.  Normally $SHLVL would be inherited from
the shell running pacman, but operations involving scriptlets are
generally run with sudo which does not let the $SHLVL variable through
unless specifically configured to.

Similarly $BASH_ENV can cause bash to source user-specified configuration
files if set.

https://lists.gnu.org/archive/html/help-bash/2022-02/msg00082.html

Note: the list discussion and bash source all reference SHLVL >= 2, this
is the SHLVL value *after* bash has incremented it on startup.  Setting
it to 1 in pacman is sufficient to disable the unwanted behavior.

Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
2022-10-15 10:40:59 -07:00
Chris Down
015eb31c3a dload: Remove unused ABORT_SIGINT
The last user of ABORT_SIGINT was removed in commit 84723cab5d
("Cleanup the old sequential download code"), and this isn't exported as
part of the public API.

Signed-off-by: Chris Down <chris@chrisdown.name>
Signed-off-by: Allan McRae <allan@archlinux.org>
2022-07-21 20:00:44 +10:00
Andrew Gregory
6dcd4b5383 makepkg: store pkgtype in xdata
Package type is not relevant to alpm or even exposed to front-ends in
any way.

Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
2022-07-21 19:01:45 +10:00
Andrew Gregory
3405709b46 add extended data field for arbitrary package data
This adds a mechanism for package builders to add arbitrary data to
packages that is not necessarily relevant enough to the package
installation process to gain first-class support in alpm.  Currently
these fields have to be added to parsers with a "not actually used"
comment and can't be retrieved through the API.

Extended data is stored in "name=value" format in the xdata field
(%XDATA% in desc files):

xdata = pkgtype=debug

or

%XDATA%
pkgtype=debug

Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
2022-07-21 19:01:27 +10:00
Allan McRae
2bf67416c1 Fix remaining email list address
One instance was missed in b0a2fd75b2.

Signed-off-by: Allan McRae <allan@archlinux.org>
2022-06-25 22:59:20 +10:00
morganamilo
bddfcc3f40 libalpm: add getter for handle on db and pkg
db and pkg store a pointer to the handle for internal use but don't
actually provide a way for a user to get it.

Making this accessible is more convenient for front ends and FFI
wrappers.

For example, in other languages it's common to return the error value
directly. To achieve this the python and rust wrappers also store their
own pointer to the handle inside their own pkg/db wrappers.

Exposing this would allow the wrappers to forgo the extra pointer and
just return `pkg.get_handle().last_error()`.
2022-03-08 09:56:53 +10:00
Allan McRae
40583ebe89 Avoid information leakage with badly formed download header
Parsing of Content-Disposition relies on well formed headers.
A malformed header such as:

Content-Disposition="";

will result in a strnduppayload->content_disp_name, -1, ptr),
which will copy memory until it hits a \0.

Prevent this by only copying the value if it exists.

Fixes FS#73704.

Signed-off-by: Allan McRae <allan@archlinux.org>
2022-03-06 21:49:56 +10:00
Allan McRae
632eb9739d Do not use WKD to import keys for package installs from a file
In order to use WKD in pacman -U/--upgrade operations, we need to
get the packager information from the .PKGINFO within the package.
That has obvious security implications. e.g. something like this
could convince a user to download a different key to what they
expect:

packager = foo bar <>^[[2K^[[0G:: Import PGP key DEADBEEF, "foo <bar>

While downloading an untrusted key has little impact due to the
web-of-trust model used by pacman, this could be bad in combination
with an exploit that allowed trust of keys in the keyring to be
altered.

To be safe, do not use WKD when installing using -U.

Fixes FS#73703.

Signed-off-by: Allan McRae <allan@archlinux.org>
2022-03-06 21:25:30 +10:00
Allan McRae
6b37d99431 Fix segfault when failing to import keys
Avoid a segfault when a search of the keyserver returns that the
key is found but returns no primary IDs.  We are then likely going
to fail the import, but attempt anyway because no-one know what
a keyserver will do!

Fixes FS#73534.

Signed-off-by: Allan McRae <allan@archlinux.org>
2022-03-06 20:36:59 +10:00
Allan McRae
e1246baddd Ensure WKD key lookup returns the correct key
Looking up a key using WKD just ensures you have a key with the
same email address, it does not ensure that a key with the correct
fingerprint has been downloaded.

Check a key with the relevant fingerprint is available after a
WKD import.
2022-03-06 19:57:09 +10:00
morganamilo
7340fb9b2e libalpm: mark filelist_contains as taking a const filelist
This is useful for bindings as it guarantees the value will not be
changed.

Signed-off-by: Allan McRae <allan@archlinux.org>
2022-03-06 17:32:23 +10:00
Allan McRae
ad918bcb75 Remove reference to internal type in docs
Signed-off-by: Allan McRae <allan@archlinux.org>
2022-03-06 15:32:27 +10:00
Allan McRae
569bcd9d26 Add missing parameter names to silence doxygen
Signed-off-by: Allan McRae <allan@archlinux.org>
2022-03-06 15:24:19 +10:00
Morten Linderud
241c29f0cc makepkg: Implement pkgtype in .PKGINFO
This implements pkgtype into .PKGINFO. This is useful to ensure tools
parsing packages do not miss important context on the creation of the
package.

For instance discovering if a given .pkg.tar is a debug package, one
would have to do heuristics on the pkgdesc and "${pkgbase}-debug".
However both of these values are controlled by the packager.

Similarly, the heuristic for discovering split packages is if pkgbase
and pkgname differ, which can happen in any package as both values are
packager controlled.

This should ensure we don't need to rely on heuristics and instead
include the context of how the package was created.

Signed-off-by: Morten Linderud <morten@linderud.pw>
Signed-off-by: Allan McRae <allan@archlinux.org>
2022-01-09 14:03:16 +10:00
Allan McRae
0be1d4e5d0 Remove parsing of long removed files in .PKGINFO
These fields have not existed for many years.

Signed-off-by: Allan McRae <allan@archlinux.org>
2022-01-02 18:06:15 +10:00
Allan McRae
90df85e9cf Update copyright years
./build-aux/update-copyright 2021 2022

Signed-off-by: Allan McRae <allan@archlinux.org>
2022-01-02 13:34:52 +10:00
morganamilo
58c81fa213 alpm: return -1 for error in find_dl_candidates
This is the error value generally used and the calling function
explicitly checks for -1, later causing the error to be missed
and the transaction to continue.

> pacman -S xterm
warning: xterm-369-1 is up to date -- reinstalling
resolving dependencies...
looking for conflicting packages...

Package (1)  Old Version  New Version  Net Change  Download Size

extra/xterm  369-1        369-1          0.00 MiB       0.42 MiB

Total Download Size:   0.42 MiB
Total Installed Size:  1.05 MiB
Net Upgrade Size:      0.00 MiB

:: Proceed with installation? [Y/n]
error: no servers configured for repository: extra
(1/1) checking keys in keyring                                                                 [--------------------------------------------------------] 100%
(1/1) checking package integrity                                                               [--------------------------------------------------------] 100%
error: failed to commit transaction (wrong or NULL argument passed)
Errors occurred, no packages were upgraded.
2021-12-29 16:16:18 +10:00
Allan McRae
5352367022 Prevent translation of curl
Signed-off-by: Allan McRae <allan@archlinux.org>
2021-11-20 12:39:42 -08:00
morganamilo
5287cc7251 alpm: fix wrong access() being used
When removing files we check _alpm_access() to see if we can write
(delete) the file. If not, we check if the file exists because if the
file does not exist then we don't actually need to remove it so there's
no issue.

However the second call uses acess() instead of _alpm_access() which
does not the rootdir into account.
2021-11-20 12:39:22 -08:00
morganamilo
b0a2fd75b2 Update mailing list url
change pacman-dev@archlinux.org to pacmandev@lists.archlinux.org

Most of this is copyright notices but this also fixes FS#72129 by
updating the address in docs/index.asciidoc.
2021-11-20 12:38:25 -08:00