Petr Písař [Wed, 10 Jul 2024 14:54:56 +0000 (16:54 +0200)]
Fix a possible format overflow in dump_genid()
GCC 14 called with CFLAGS='-O2 -Wformat-overflow' complains:
/tmp/libsolv/ext/testcase.c: In function ‘dump_genid’:
/tmp/libsolv/ext/testcase.c:1275:33: warning: ‘: genid ’ directive writing 8 bytes into a region of size between 3 and 12 [-Wformat-overflow=]
1275 | sprintf(cntbuf, "genid %2d: genid ", cnt++);
| ^~~~~~~~
/tmp/libsolv/ext/testcase.c:1275:7: note: ‘sprintf’ output between 17 and 26 bytes into a destination of size 20
1275 | sprintf(cntbuf, "genid %2d: genid ", cnt++);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/libsolv/ext/testcase.c:1270:33: warning: ‘: genid ’ directive writing 8 bytes into a region of size between 3 and 12 [-Wformat-overflow=]
1270 | sprintf(cntbuf, "genid %2d: genid ", cnt++);
| ^~~~~~~~
/tmp/libsolv/ext/testcase.c:1270:7: note: ‘sprintf’ output between 17 and 26 bytes into a destination of size 20
1270 | sprintf(cntbuf, "genid %2d: genid ", cnt++);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
That's indeed a bug: sprintf() writes into a 20-byte array cntbuf. cnt
is int, 32-bit long integer on x86_64 Linux platform. dump_genid()
starts with cnt = 1 and increases. It can go up to 2147483647 decimal
value, then wrap to -2147483648 decimal value. That's up to 11 bytes
of the integer, plus 14 bytes of a static string, plus 1 byte of
a trailing '\0'. 26 bytes in total.
While it's improbable that cnt would amount that long number in real
life, it's better to be prepared for the worst. Also a benefit is that
static analyzers will be be content.
This patch increases cntbuf[] size to accomodate common 32-bit
ints. (Generic, albeit illegible, expression would be:
First resolve the given jobs, then the dependencies of the
resulting packages ignoreing the ones provided by currently
installed packages. After that resolve all already installed
packages. This is similar to SOLVER_FLAG_FOCUS_BEST but less
aggressive in updating packages.
This commit implements the file tree work needed
for the "plaindir" format. Like with the "find" command,
we do not follow symlinks to directories in recursive
mode.
Petr Písař [Mon, 13 May 2024 07:55:01 +0000 (09:55 +0200)]
Report unsupported compression in solv_xfopen() with errno
If libsolv was built without Zstandard support and "primary.xml.zst"
was passed solv_xfopen(), solv_xfopen() returned 0 without setting
errno. A calling application could not distinguish an unsupported
compression format from other I/O errors.
This patch improves this situation by setting errno variable to an
appropriate value. The value macros are documented in POSIX 2017.
getdecisionlist: keep track of all literals from a unit rule
Otherwise, sort_unit_decisions() may not find a unit rule and
go into and endless loop. Before this commit, we left out
conflicted packages to make the decisionlist shorter.
An alternative would be to track those left out literals.
David Cantrell [Tue, 26 Mar 2024 16:13:55 +0000 (12:13 -0400)]
Fix a couple small static analysis findings for uninitialized structs
The memset() on the KeyValue is more explicit even though if you trace
the code you will see it fills out the struct. However, it's possible
that not every struct member will be initialized and adding the
memset() makes things more obvious and appeases the static analyzer.
This seems to be unneeded as the Makefile written by cmake
automatically detects that it needs to rebuild if a different
python version is used. But just be be on the safe side...
Remove the "0:" stripping from the evr in testcase_read. Messing
with the evr is not our business, we need to reproduce the data
as faithful as possible.
Save memory in repo_updateinfoxml by not interleaving repo_addflexarray calls
Mixing repo_addflexarray calls will make the code moving the arrays
in the idarraydata all the time as it cannot append to the arrays.
So first collect the array contents of the collection flexarray and
then add it in one go.
This is based on pull request #533 by Aleš Matěj <amatej@redhat.com>.
Treat condition both as positive and negative literal in pool_add_pos_literals_complex_dep
That's because (A IF B ELSE C) gets rewritten to (A OR ~B) AND (C OR B) and
(A UNLESS B ELSE C) gets rewritten to (A AND ~B) OR (C AND B). In both
cases we have A, B, ~B, C.
Fabrice Fontaine [Sun, 12 Feb 2023 14:27:27 +0000 (15:27 +0100)]
Fix build without C++
Fix the following build failure without C++:
CMake Error at CMakeLists.txt:1 (PROJECT):
No CMAKE_CXX_COMPILER could be found.
Tell CMake where to find the compiler by setting either the environment
variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
to the compiler, or to the compiler name if it is in the PATH.
Move replace solution types from the bindings to the library
This adds two new functions:
solver_all_solutionelements()
return a queue with (type,p,rp) solution triplets.
solver_solutionelementtype2str()
this is similar to solver_solutionelement2str(), but also takes a
type parameter so that the replace types result in different strings.
Make use of the two functions in the example solver to
show how they work.