Commit graph

2932 commits

Author SHA1 Message Date
Allan McRae
f86c15e780 unlink_file: restore trailing slash on directory before checking mountpoint
The dir_is_mountpoint() function has the explicit requirement that the
trailing slash of the directory is present.  We strip the trailing slash
in unlink_file() to handle directories replaced with symlinks, but that
then affects the dir_is_mountpoint() check.

Add the trailing slash when we have established we are dealing with a
directory. Note this may fail in the case of a file managed by pacmane
with name length of PATH_MAX that has been replaced by a directory on the
file system. Bail on this unlikely scenario.

In addtion, be less fancy with adjusting length of the file char array.

Signed-off-by: Allan McRae <allan@archlinux.org>
2024-04-05 00:51:13 +00:00
Allan McRae
0ccb584262 Do not pass NULL paramenter to bsearch with empty filelist
A filelist can be non-NULL but empty (particularly with a lot of
NoExtract entries). Handle this in alpm_filelist_contains()

Identified using the undefined behaviour sanitizer.

Signed-off-by: Allan McRae <allan@archlinux.org>
2024-04-05 00:35:08 +00:00
Remi Gacogne
cfa68f7b26 Restore partially downloaded files to the temporary directory
This allows downloads to be continued.

Signed-off-by: Allan McRae <allan@archlinux.org>
2024-04-01 20:52:55 +00:00
Remi Gacogne
e1a7b83e8e Download to a temporary directory owned by the Download user
Signed-off-by: Remi Gacogne <rgacogne@archlinux.org>
Signed-off-by: Allan McRae <allan@archlinux.org>
2024-04-01 20:52:55 +00:00
Remi Gacogne
5e9bff6216 Stop trusting the Content-Disposition HTTP header 2024-04-01 20:52:55 +00:00
Allan McRae
26b7b35307 Remove random_partfile from payload struct
It is not used any more due to filling the payload structure earlier.

Signed-off-by: Allan McRae <allan@archlinux.org>
2024-04-01 20:52:55 +00:00
Allan McRae
04d04381bc libalpm: fill in more payload information before passing to downloader
Filling in more of the payload fields before passing to the downloader ensures
that the these fields do not get lost during sandboxed operations.

It also fixes the use of -U with XferCommand, but testsuite still fails due to
"404" page being downloaded for the signature. Given we can not identify this
as being a non-signature download with the XferCommand, we can just turn off
signature checking in this test.

Signed-off-by: Allan McRae <allan@archlinux.org>
2024-04-01 20:52:55 +00:00
Remi Gacogne
cf359b0da4 Add support for DownloadUser with XferCommand
Signed-off-by: Allan McRae <allan@archlinux.org>
2024-04-01 20:52:55 +00:00
Remi Gacogne
93a796aa27 Add sandboxed download for the internal downloader
If the SandboxUser configure option is set, the internal downloader
will fork of a child process and drop to the specified user to download
the files.

Signed-off-by: Remi Gacogne <rgacogne@archlinux.org>
Signed-off-by: Allan McRae <allan@archlinux.org>
2024-04-01 20:52:55 +00:00
Allan McRae
9667bc6b12 Expose _alpm_reset_signals() to library
Signed-off-by: Allan McRae <allan@archlinux.org>
2024-04-01 20:52:55 +00:00
Remi Gacogne
62c6874689 Add callbacks for sandboxed operations
Add log and download callbacks to use within a sandbox.  These are
designed to be passed from the sandbox to the parent through a file
descriptor and then processed into alpm callbacks to be passed to the
frontend.

Note, only callbacks used in libalpm are added. Other callbacks should
be set to NULL in the child process.
2024-04-01 20:52:55 +00:00
Remi Gacogne
ce83cf6361 Provide function for switching user in child processes
Add alpm_sandbox_child() function that will be used for switching to a
less priviledged user to run child processes.

Signed-off-by: Allan McRae <allan@archlinux.org>
2024-04-01 20:52:55 +00:00
Remi Gacogne
56eb87287e Add DownloadUser configuration option
The DownloadUser option will be used to drop privledges to the
specified user when downloading files.

The intention is for this to be extended in the future  to a more
general sandbox configuration to cover operating on package and
database files prior to verification.

Add this option to pacman configuration and the various accessors into
the libalpm backend.

Signed-off-by: Allan McRae <allan@archlinux.org>
2024-04-01 20:52:55 +00:00
Vladislav Nepogodin
01e64e8b6a use snprintf instead of sprintf
sprintf does not check for buffer overflows (CWE-120)

	modified:   src/pacman/callback.c
2024-03-25 13:24:41 +10:00
Allan McRae
b59d68a209 Update bug report URL in tranlsation configuration files
Signed-off-by: Allan McRae <allan@archlinux.org>
2024-03-19 12:02:44 +10:00
Demi Obenour
eb5bf69138 Fetch signature and database from the same URL
Previously, the for loops on lines 1035 and 1037 would advance to the
next element in the server list, even if downloading the URL succeeded.
If there are no more servers in the list, `s` would be NULL, causing
a NULL pointer dereference on line 1046.  If there were servers left
in the list, the signature would be downloaded from a wrong URL.

1. Fetching of database signatures is enabled.
2. There is only one enabled remote repository URL, or fetching from
   all but the last one fails and fetching from the last one succeeds.
3. An XferCommand is used.

Qubes OS Arch templates satisfy all of these conditions and trigger the bug.
2024-03-19 11:44:38 +10:00
Allan McRae
6bb95c8856 Fix error messages for unknown key in databases
Signed-off-by: Allan McRae <allan@archlinux.org>
2024-03-05 07:25:11 +10:00
Allan McRae
e3dc296ba3 Pull translations for release
Signed-off-by: Allan McRae <allan@archlinux.org>
2024-03-04 13:07:58 +10:00
Allan McRae
f343db5b8e Do not segfault with badly formed URL
Signed-off-by: Allan McRae <allan@archlinux.org>
2024-02-28 07:38:56 +10:00
Allan McRae
d55b47e551 Update copyright years
Signed-off-by: Allan McRae <allan@archlinux.org>
2024-02-24 18:40:44 +10:00
Allan McRae
c8afb0aa1a Prepare translations
Signed-off-by: Allan McRae <allan@archlinux.org>
2024-02-19 11:27:21 +10:00
Masato TOYOSHIMA
2180e4d127 libalpm: download signatures with the external downloader
Ensure relevant signature files are downloaded when using the fetch
callback.

Signed-off-by: Allan McRae <allan@archlinux.org>
2024-02-16 19:27:09 +10:00
morganamilo
abc6dd7411 libalpm: check calloc in alpm_list_cmp_unsorted 2024-02-15 23:02:15 +00:00
morganamilo
7a43c6fee0 Speedup comparing lists if they happen to be in the same order 2024-02-15 23:02:15 +00:00
morganamilo
62095d916b Prompt to delete invalid package 2024-02-15 23:02:15 +00:00
morganamilo
386125fc89 Validate extra data when comparing dbpkg to pkgfile 2024-02-15 23:02:15 +00:00
morganamilo
196de7e94a Add function to check if lists are equal 2024-02-15 23:02:15 +00:00
morganamilo
e1dc609939 libalpm: print warnings for unknown keys in databases/packages
Signed-off-by: Allan McRae <allan@archlinux.org>
2024-02-10 11:31:12 +10:00
Allan McRae
0649a66ee5 Add ALPM_PKG_REASON_UNKNOWN type
Return ALPM_PKG_REASON_UNKNOWN when parsing of %REASON% in the local
database fails.

Signed-off-by: Allan McRae <allan@archlinux.org>
2024-02-09 11:14:38 +10:00
morganamilo
6e6d3f18e3 libalpm: don't use atio for pkgreason
atio's behaviour is undefined if the input is not valid. Also it does
all sorts of whitespace and prefix handling which we don't need for
pkgreason.

Instead of going into UB on invalid input we now return EXPLICIT as the
fallback and print an error. However we don't actually error out as the
DB parsing tries to be error tolerant.

Signed-off-by: Allan McRae <allan@archlinux.org>
2024-02-09 11:14:38 +10:00
Andrew Gregory
0a394144b2 validate package metadata after loading
alpm has certain requirements for package metadata necessary for proper
functioning, name and version in particular.  These requirements are
already enforced in makepkg, but nowhere in alpm.

Exceptions are treated as errors for non-local packages because they
cannot be installed without potentially resulting in undefined behavior.
Exceptions for local packages are treated as warnings because they are
already installed, so any damage has already been done, and the user
would otherwise have no way to uninstall them.

Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
2024-02-07 12:27:26 +00:00
Andrew Gregory
fde59b99e8 be_package: delay freeing archive resource
The error path uconditinally tries to free the archive, leading to a
double-free segmentation fault if the error path is triggered after
already freeing it.

Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
2024-02-07 12:27:26 +00:00
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