libopkg: implement lightweight package listing logic Instead of building a complete package dependency tree internally, use a lightweight list data structure to gather and sort package names, version and descriptions. This reduced the "opkg list" memory footprint on x86/64 from ~8MB to ~1.5MB. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
libopkg: support passing callbacks to feed parsing functions Extend pkg_hash_add_from_file(), pkg_hash_load_feeds() and pkg_hash_load_status_files() to accept a per-package callback function andan associated userdata pointer. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
libopkg: use xsystem() to spawn opkg-key Instead of the custom fork()/exec() implementation, use the existing xsystem() helper function which provides a number of benefits: - It readily provides error reporting in case the execution fails - It has a simpler api - It uses vfork() internally which avoids the need to copy pages This likely fixes https://bugs.openwrt.org/index.php?do=details&task_id=2734. Fixes: 71f02a3 ("libopkg: add support for signature checking through usign") Signed-off-by: Jo-Philipp Wich <jo@mein.io>
file_util.c: refactor and fix checksum_hex2bin() - Simplify function body by reducing the amount of intermediate vars - Derive length checks from the size of the buf - Replace complex for(;;) by a simple while() advancing the src string - Handle edge case of a zero length input not returning NULL Fixes: c09fe20 ("libopkg: fix skipping of leading whitespace when parsing checksums") Signed-off-by: Jo-Philipp Wich <jo@mein.io>
file_util.c: fix possible bad memory access in file_read_line_alloc() In the case of a zero length string being returned by fgets(), the condition checking for a trailing new line would perform a bad memory access outside of `buf`. This might happen when line with a leading null byte is read. Avoid this case by checking that the string has a length of at least one byte. Also change the unsigned int types to size_t to store length values while we're at it. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
opkg: Fix -Wformat-overflow warning A null pointer is being passed to printf. This can lead to problems. Fixes warning: error: '%s' directive argument is null [-Werror=format-overflow=] 41 | opkg_message(l, "%s: "fmt, __FUNCTION__, ##args); \ | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ note: in expansion of macro 'opkg_msg' 45 | opkg_msg(l, fmt": %s.\n", ##args, strerror(errno)) | ^~~~~~~~ note: in expansion of macro 'opkg_perror' 247 | opkg_perror(ERROR, "Failed to create temporary directory '%s'", Signed-off-by: Rosen Penev <rosenp@gmail.com>
alternatives: remove duplicate 'const' specifier To quash warnings from GCC 7. /home/yunion/git-repo/openwrt/openwrt/build_dir/target-mips_24kc_musl/linux-malta_be/opkg-2019-06-14-21b7bd73/libopkg/pkg_alternatives.c:35:42: warning: duplicate 'const' declaration specifier [-Wduplicate-decl-specifier] static const struct alternative_provider const providers[] = { ^~~~~ Signed-off-by: Yousong Zhou <zhouyousong@yunionyun.com>
alternatives: special-case busybox as alternatives provider Almost all busybox applets are alternatives to some other existing "full" utilities. To lift the maintenance burden of enumerating CONFIG symbols, symlink path of each applet, we special case busybox here as a known alternatives provider. All file pathes provided by busybox will serve as fallback alternatives with -inf priority. Packages intending to switch to using alternatives mechanism will also not need to depend on the same kind of change be applied on busybox in base system v3 <- v2 continue to next when fetching provider pkg failed v2 <- v1 Move busybox-specific part into data section Signed-off-by: Yousong Zhou <zhouyousong@yunionyun.com> Acked-by: Jo-Philipp Wich <jo@mein.io>
libopkg: check for file size mismatches Reject package files whose file size deviates from the size specified in the package index in order to complicate producing hash collisions. Ref: https://groups.google.com/d/msg/opkg-devel/o4kiGQMvkiw/hu0TVv59DgAJ Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Revert "libopkg: accept alternative notation for "Replaces" control field" This reverts commit 1504d35f123980bf322df99fb434f6fda6e3ecd2. We won't use Replaces: for the repo ABI_VERSION tracking after all, so drop this hack before it becomes another liability. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Revert "libopkg: check installed reverse dependencies upon install/upgrade" This reverts commit 89fe77cb119a24f728088320d66d51250a1f02ab. After spending further thoughts on this I think this makes no sense at all and such situations should be avoided on the repo level instead by don't providing incompatible packages having an identical name. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
libopkg: accept alternative notation for "Replaces" control field The presence of a "Replaces:" tag in any package feed list will cause opkg prior to "d217daf libopkg: fix replacelist parsing and writing" to segfault while parsing such a list. Add a hack which lets opkg recognize a "Replace2" field and handle it identically to "Replaces". Signed-off-by: Jo-Philipp Wich <jo@mein.io>
libopkg: consider provided packages in pkg_vec_mark_if_matches() Also consider the list of provided abstract packages when testing the package vector for name matches. This fixes the "opkg whatdepends" command with abstract provided package arguments. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
opkg_download: print error when fork() fails Instead of silently failing and claiming that the signature verification failed, print out the error status when the initial fork() call fails. Ref: https://bugs.openwrt.org/index.php?do=details&task_id=1999 Signed-off-by: Jo-Philipp Wich <jo@mein.io>