2374 Commits
Author SHA1 Message Date
aphrody-dev e2e497fe91 docs(plan): faisabilité apk-tools natif Windows (MS-d) 2026-10-09 05:54:18 +02:00
aphrody-dev 6e1261b289 ci: add Aphrody upstream sync and fork plan 2026-10-09 02:34:11 +02:00
Timo Teräs 44dcdfc255 apk-tools-3.0.8 v3.0.8 2026-08-31 13:53:33 +03:00
Timo Teräs 65f14f74dc adb: validate object/array length in adb_r_obj()
Cap the maximum array/object size to ADBI_MAX. Anything larger
would not fit a valid ADB blob, and could cause size_t calculation
overflow for memory allocation on 32-bit architectures. This code
path is not reacahable without a signed and trusted file.
2026-08-31 13:23:32 +03:00
Timo Teräs fad990d6ac blob: fix bounds check in apk_blob_pull_hexdump()
A crafted file might cause an OOB read beyond source buffer.
Typically this is in the uncompression buffer, and would not
cause a crash. Seems there is no immediate place in the callers
that would crash either, but update some of the callers to make
this more obivous and return more approriate error codes.
2026-08-31 13:23:32 +03:00
Timo Teräs 47820c81af extract: harden hardlink and symlink handling
Make sure that the parent directory is a real directory extracted
and processed earlier for symlinks. And that the hardlink target
is a previously processed regular file.
2026-08-31 13:23:32 +03:00
Timo Teräs b7bfd6f46b fs_fsys: remove unreached directory branch in fsys_file_extract
The directory creation is always delegated to ->dir_create().
Also return a proper error code for unsupported file types.
2026-08-31 13:23:32 +03:00
Timo Teräs 85e4833fd4 fs_fsys: consider apk temporary filenames as harmful in package
It inteterfes with the rename logic, and could conflict with
correct extracton of a package.
2026-08-31 13:23:32 +03:00
Timo Teräs 8e5aaacf88 fs_fsys: harden hardlink target validation 2026-08-31 13:23:32 +03:00
Timo Teräs c4768d19ad test: add fixup for fakeroot mangled LD_LIBRARY_PATH
We likely get system libapk.so for fakeroot tests otherwise.
2026-08-31 13:07:05 +03:00
Timo Teräs 6bd27cc840 test: fix shellcheck warning for user/dirperms 2026-08-31 11:50:15 +03:00
Timo Teräs 70e00ae314 SECURITY: amend reporting instructions 2026-08-31 11:21:59 +03:00
Timo Teräs 1168cf8b84 add Security Policy 2026-08-31 11:14:02 +03:00
Timo Teräs 900a3f5280 fs_fsys: chmod directory set-uid/gid bit, and use AT_SYMLINK_NOFOLLOW
Fix setting uid/gid bit for directories: it needs a separate follow
up fchmodat() as these bits are ignored for the mkdirat() call.

Also always use AT_SYMLINK_NOFOLLOW bit to not follow symlinks
for these operations. Typically this is not a problem unless
the user has done incomptile changes to the apk managed file system.

fixes #11216
fixes #11217
2026-08-28 13:38:39 +03:00
Timo Teräs 2e1a2a1bfe db: fallback to not using cache if its not writable
This allows non-user apk read-only commands to fetch missing
indexes as if --no-cache was implified.
2026-08-28 11:08:02 +03:00
Timo Teräs 36a9c1a0f3 db: download missing index also with read-only actions 2026-08-28 11:04:34 +03:00
Timo Teräs 0dc269c8dd adb: use adb specific error codes when calling adb_w_error
fixes #11190
2026-08-26 12:46:40 +03:00
Timo Teräs 6bb3eca312 adb: remove development time assert in adb_w_error
fixes #11190
2026-08-26 12:39:46 +03:00
Timo Teräs aa6cac3315 ci: remove armhf release link
The armhf binary has not been built since commit aa245e7002
"ci: test on more cpu architectures" which refactored the pipelines.
While removal of armhf release binary seems to have been accidental,
there seems to have been no use for it and most sensible arm platforms
now run armv7 binaries, so let's remove this now.

fixes #11214
2026-08-26 12:07:40 +03:00
Timo Teräs 8cc338923c move help/completion generators to individual subdirs
This allows generating the zsh completions with the correct
filename (so it does not overlap with bash completions).

ref aports#18367
2026-08-26 11:58:06 +03:00
Timo Teräs 7593499ee4 adb: validate ADB block size and memory allocation
Do a basic sanity check on the size, and validate memory allocation
status.
2026-08-14 15:49:33 +03:00
Tobias Koch 3174f53b7d libfetch: size the address scratch buffer for full-form IPv6
MAX_ADDRESS_STRING was 4*8+1 = 33 characters, but an IPv6 literal in
full form runs to 45 characters plus the terminator.  host_to_address()
rejects any address that does not fit, so no_proxy CIDR entries
silently failed to match a host written in full form.

Use INET6_ADDRSTRLEN, which is the constant meant for this.

Signed-off-by: Tobias Koch <tobias.koch@aeltra.eu>
2026-08-08 18:31:25 +03:00
Tobias Koch 78de60cdae libfetch: release the redirect URL on all paths in http_request()
Two leaks of the "new" URL:

 - A second Location header in the same reply released the previous
   allocation with free() rather than fetchFreeURL(), leaking new->doc.

 - Any error between parsing a Location header and consuming it at the
   bottom of the retry loop -- a malformed Content-Length, say --
   reaches the ouch label, which never released new at all.

Use fetchFreeURL() in the first case and release new at the ouch label
in the second.  The label is reached both before and after the loop
assigns new to url, so the release there is guarded against the alias.

Signed-off-by: Tobias Koch <tobias.koch@aeltra.eu>
2026-08-08 18:31:25 +03:00
Tobias Koch 60a34ccaa0 libfetch: avoid sign extension in http_base64()
src is a char pointer, so on platforms where char is signed -- x86-64
among them -- every input byte >= 0x80 sign-extends when shifted into t
and floods the high bits, corrupting the whole four-character group.
Encoding "caf\xc3\xa9" then yields "Y2Fm/6k=" instead of "Y2Fmw6k=", so
Basic credentials containing any non-ASCII byte are sent wrong.
Platforms where char is unsigned (arm, aarch64, ppc) are unaffected,
which is why this goes unnoticed on a good part of the build farm.

Convert through unsigned char before shifting.

Signed-off-by: Tobias Koch <tobias.koch@aeltra.eu>
2026-08-08 18:31:25 +03:00
Tobias Koch 388f861d39 libfetch: track the previous entry in fetch_cache_get()
last_conn was initialised to NULL and never advanced, so the branch
that unlinks a matched entry from the middle of the list was
unreachable.  A cache hit on any entry but the first therefore ran
"connection_cache = conn->next_cached", dropping every entry ahead of
the match from the list without closing it and leaking its descriptor,
SSL context and buffers.

Advance last_conn as the list is walked.

Signed-off-by: Tobias Koch <tobias.koch@aeltra.eu>
2026-08-08 18:31:25 +03:00
Tobias Koch 7e5268c420 libfetch: include 400 and 599 in HTTP_ERROR()
HTTP_ERROR() excluded both ends of its intended range, so 400 (Bad
Request) and 599 counted as neither success nor error.

http_request() only reaches the macro for an error status when the 'v'
flag is set; without it the status-line switch has already taken
"if (!verbose) goto ouch".  With 'v', a 400 or 599 instead takes the
branch commented "all other cases: we got a redirect".  No redirect is
actually followed there, since hdr_location only sets "new" for a
status matching HTTP_REDIRECT(), and the reply is still reported as an
error via the http_seterr() in the switch.  But the connection is
closed outright instead of being drained and returned to the connection
cache, and the caller's url_stat is left unfilled.

Use the conventional 4xx-5xx range.

Signed-off-by: Tobias Koch <tobias.koch@aeltra.eu>
2026-08-08 18:31:25 +03:00
Tobias Koch b65a7bbd57 libfetch: return -1, not EBADF, from fetchIO_read()/fetchIO_write()
Both functions return ssize_t, and returning EBADF returns a positive
9 -- which a caller reads as "9 bytes transferred" rather than as an
error.  A reader looping while the result is > 0 would treat 9 bytes of
uninitialised buffer as payload.

Set errno and return -1, matching the convention of the read/write
callbacks these functions wrap.

Signed-off-by: Tobias Koch <tobias.koch@aeltra.eu>
2026-08-08 18:31:25 +03:00
Tobias Koch 25042a09a7 libfetch: test the write callback in fetchIO_write()
fetchIO_write() guarded on f->io_read before calling through
f->io_write, so a fetchIO created with a read callback but no write
callback would dereference a NULL function pointer.

Signed-off-by: Tobias Koch <tobias.koch@aeltra.eu>
2026-08-08 18:31:25 +03:00
Tobias Koch 8f00aba1e3 libfetch: fix inverted $HOME test in fetch_netrc_auth()
The condition ran the getpwuid() fallback when $HOME was set, throwing
away the value it had just read, and skipped it when $HOME was unset --
leaving p NULL for the following snprintf("%s/.netrc", p).

Fall back to getpwuid() when $HOME is not set, as the surrounding code
intends.

Signed-off-by: Tobias Koch <tobias.koch@aeltra.eu>
2026-08-08 18:31:25 +03:00
Tobias Koch dbe5c12334 libfetch: fix leak in the fetchAppendURLList() error path
When strdup() failed, the cleanup loop counted down over i but freed
dst->urls[j].doc on every iteration -- always the entry whose strdup()
had just failed, and therefore always NULL.  The strings duplicated by
the preceding iterations were leaked.

Walk j back down to dst->length instead, which frees exactly the
entries that were successfully duplicated and stops before the one that
failed.

Signed-off-by: Tobias Koch <tobias.koch@aeltra.eu>
2026-08-08 18:31:25 +03:00
Tobias Koch 7aaf899141 libfetch: fix use-after-free in fetch_cache_put()
Commit d430a98976 ("libfetch: fix use-after-free in connection cache
management") hoisted next_cached out of the eviction loop so that the
walk no longer reads iter after the close callback has freed it.  The
same increment expression still advances "last", however, and it runs
for entries that were just unlinked and handed to that callback.

"last" is therefore left pointing at freed memory, and the next
eviction writes through it via "last->next_cached = ...", corrupting
the connection cache.

Advance "last" only for entries that are retained.

Signed-off-by: Tobias Koch <tobias.koch@aeltra.eu>
2026-08-08 18:31:25 +03:00
Tobias Koch c87decd1c9 libfetch: free the addrinfo list in fetch_bind()
fetch_bind() calls getaddrinfo() but never releases the returned list,
leaking it on both the success and the failure path.

Signed-off-by: Tobias Koch <tobias.koch@aeltra.eu>
2026-08-08 18:31:25 +03:00
Timo Teräs 522171e05c apk-tools-3.0.7 v3.0.7 2026-07-28 14:28:06 +03:00
Timo Teräs 69ac1af362 extract: harden validation of malicious filenames during extraction
Move the validation to tar.c and extract_v3.c to validate filename
before it reaches the consuming side. This implicitly fixes 'extract'
applet to also validate the filenames.

Also instead of just ignoring the malicious files treat the package
as being broken: abort further extraction, and during regular install
rollback instead of keeping it in 'broken' state.

fixes #11194
fixes #11212
2026-07-28 14:16:57 +03:00
Timo Teräs 23d3a41605 genhelp: remove code duplication from generators 2026-07-24 14:43:00 +03:00
mastertac 844009a027 genhelp: add Zsh completion generator
Add a genhelp_zsh.lua plugin alongside the existing bash generator,
producing a Zsh completion script (_apk) via a #compdef header and
_arguments/compadd-based dispatch, rather than the COMP_WORDS/COMPREPLY
mechanism Bash relies on.

Applet names are paired with their descriptions from apk.8.scd's
COMMANDS section for use with _describe. Per-applet flags are grouped
by alias (e.g. -h/--help) into single _arguments specs with their
first-sentence description from OPTIONS, following the same
first-sentence truncation genhelp_bash.lua already uses. Package name
completion is wired through __apk_installed_pkgs/__apk_available_pkgs
helper functions using compadd, mapped per applet the same way the
bash plugin's wildcard table is.

Wire the new plugin into the build as a second custom_target in
src/meson.build, installed to zsh/site-functions. The build-time
output is named _apk_zsh to avoid colliding with the existing bash
target's _apk output in the build tree; it is installed as _apk,
which Zsh's compinit discovers via the #compdef directive rather
than a filename convention, so no build-time renaming is required.

This addresses the gap discussed upstream in apk-tools!44 and
alpine/aports!14571, where Zsh completions exist only as a
hand-maintained, unversioned copy in aports rather than being
generated from the same source of truth as the Bash completions
and built-in help.
2026-07-23 09:55:40 +00:00
mastertac 0559460d36 genhelp: generalize '--format' flag parsing
Previously only '--format=bash' was recognized; any other value fell
through to the input-file branch and was passed to doc:parse(), which
fails since it isn't a filename. Accept '--format=<name>' generically
so additional output plugins (e.g. genhelp_zsh.lua) can be selected
the same way.
2026-07-23 09:55:40 +00:00
Rosie K Languet 0681f842ff doc: document default protected paths
See src/database.c:2101

Signed-off-by: Rosie K Languet <rkl@rosiesworkshop.net>
2026-07-03 16:14:43 -04:00
Sertonix 90b974fd85 doc: remove mention to nonexistant *default* command 2026-06-30 13:40:05 +02:00
Sertonix f62d556932 repoparser: allow lines starting with variable
otherwise it is not possible to have the protocol be configured by a
variable
2026-06-30 13:32:36 +02:00
dana 097d611f2b doc: fix incorrect --compression short option
broken by 932599280d somehow

also fix formatting
2026-06-16 12:13:45 +00:00
Paul Spooren 93d8e1bc3c genhelp: make gzipped embedded help reproducible
If Lua zlib module is not available, genhelp falls back to `gzip`, which embeds
the MTIME. As a result the created `apk` binary is unreproducible.

This commits passes `-n` so gzip omits the original MTIME and sets it to 0
instead.

Signed-off-by: Paul Spooren <mail@aparcar.org>
2026-06-11 09:41:53 +02:00
Sertonix 20fe3dccc4 doc: fix apk-cache(5) missing 2026-05-05 12:03:52 +00:00
Zhaoming Luo 3683412d39 doc: fix example error in apk-query(8)
The FIELDS value does not allow 'dependency'.

Signed-off-by: Zhaoming Luo <zhml@posteo.com>
2026-04-25 13:16:15 +08:00
Timo Teräs 7e92634afe apk-tools-3.0.6 v3.0.6 2026-04-13 11:36:44 +03:00
Timo Teräs ba8fd33f4f extract_v3: validate link target size
Validate the path size to prevent unbounded alloca().

fixes #11195
2026-04-13 11:31:09 +03:00
Timo Teräs f94ea9bd75 query: match depends exactly against dependencies
This allows finding all packages containing a specific dependency,
e.g. apk query --match depends "python3~3.14"
2026-04-11 16:26:32 +03:00
Timo Teräs 8743dbc270 defines: add and use APKE_BUFFER_SIZE
Replace usage of the system ENOBUFS error with APKE_BUFFER_SIZE
as it may cause some confusion if the error is from apk or the OS.
2026-04-09 17:13:17 +03:00
Timo Teräs 6cd9b3550e db: fix url buffer sizes and names
Fix open_repository[] size to PATH_MAX as full URLs are needed
there. Rename the cache filename buffers that are NAME_MAX length
to _filename to indicate that they have only filename portion.

fixes #11196
2026-04-09 17:13:17 +03:00
Timo Teräs f2c0ae7b01 pkg: add and use PKG_VER_MAX for PKG_VER_FMT 2026-04-09 17:13:17 +03:00