Commit Graph

1938 Commits

Author SHA1 Message Date
Emil Velikov
9cc16ef0ac libkmod: use uint8_t for the child prefix/index
Stop implicitly casting the child prefix/index to int. It can have high
bits set thus get promoted to wildly incorrect value and cause chaos
further on.

In addition, convert the existing `unsigned char` instances to uint8_t,
which better illustrates what we're after - a fixed sized 8 bit unsigned
integer.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/251
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2024-11-22 15:31:15 -06:00
Emil Velikov
f5589e70c6 depmod: use uint8_t for the child prefix/index
Stop implicitly casting the child prefix/index to int. It can have high
bits set thus get promoted to wildly incorrect value and cause chaos
further on.

In addition, convert the existing `unsigned char` instances to uint8_t,
which better illustrates what we're after - a fixed sized 8 bit unsigned
integer.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/251
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2024-11-22 15:31:15 -06:00
Tobias Stoeckmann
3f8f288020 libkmod, tools: Fix format specifiers
Use %zu for size_t, not %zd which would be for ssize_t.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/248
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2024-11-20 22:34:33 -06:00
Tobias Stoeckmann
213508a611 libkmod: Prevent ouf of boundary access
Follow up of aad7c697, which fixes the same issue in another function.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/248
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2024-11-20 22:34:33 -06:00
Tobias Stoeckmann
808eb4b8e9 libkmod: Propagate hash_add errors
If newly created module in kmod_module_new could not be added to hash,
return an error. Otherwise it is possible to create multiple independent
structs with the same name, which the hash set is supposed to prevent.

An error only occurs in out of memory conditions.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/248
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2024-11-20 22:34:33 -06:00
Emil Velikov
c5c36b61da testsuite: remove need_spawn = false support
Our test suite is a little unique in my experience in that the test can
be either a normal (fork) child or a (re)spawned one. All the other test
frameworks I have used opt for only one of the two.

I'm not entirely sure why we have both since the latter is sufficient for
all use-cases that we have. Perhaps the former was kept as
micro-optimisation?

Currently I am exploring a way to provide the results summary and the
need_spawn = false ones, are printed multiple times. At a glance I
couldn't quite find a way to fix it.

In addition I am also looking at removing/reducing the use of exit()
across the test suite. Where the two code-flows makes that process more
convoluted.

So let's remove one of the code-paths, simplify things and fix the
logging output. If needed we can re-introduce it later on.

NOTE: there's a lot going on here, because clang-format insist on
reformatting bunch of the DEFINE_TEST() instances :-\

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/246
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2024-11-20 22:27:37 -06:00
Emil Velikov
d75b9949aa testsuite/test-init: use distinct test names
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/246
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2024-11-20 22:27:37 -06:00
Emil Velikov
eb575e4c0f testsuite: run all tests, don't exit on first failure
Instead of exiting on the first failing test execute all tests and
report overall failure as needed.

This gives us a better overview - which do we have single failure or
multiple instances need work - and more consistent results numbers.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/246
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2024-11-20 22:27:37 -06:00
Emil Velikov
49e54bf2ad testsuite: use exitcode 77 for skipped tests
Using 77 is a de-facto standard for skipped tests that both autotools
and meson support OOTB. Use that instead of EXIT_SUCCESS aka 0.

Semi-recently we removed the only skip = true tests, although with more
tests incoming we're need bound to have a few users.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/246
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2024-11-20 22:27:37 -06:00
Emil Velikov
a76afe12ab testsuite/modprobe: Simplify modprobe exec
Too much copy and paste for simple exec tests. Just provide an
EXEC_MODPROBE macro to help.

Hats off to Lucas for the initial idea and porting the depmod test.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/246
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2024-11-20 22:27:37 -06:00
Lucas De Marchi
ec3baed9f9 testsuite: Test depmod with relative -m
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/243
2024-11-20 22:25:30 -06:00
Lucas De Marchi
d8b2455f40 testsuite: Simplify defines for depmod -m test
Simplify the defines so it's easier to extend the test for another
directory.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/243
2024-11-20 22:25:30 -06:00
Lucas De Marchi
0fd93e6317 testsuite/depmod: Simplify depmod exec
Too much copy and paste for simple exec tests. Just provide an
EXEC_DEPMOD macro to help.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/243
2024-11-20 22:25:30 -06:00
Lucas De Marchi
babcee5c12 testsuite/depmod: Remove bogus rootfs from test
The testsuite rootfs shouldn't be part of the argument.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/243
2024-11-20 22:25:30 -06:00
Lucas De Marchi
a9e69c02d6 depmod: Fix handling relative moduledir
Make sure moduledir is always relative to the basedir and document it as
such.

Note: scdoc 1.11.3 produces a strange result when trying to render the
man page for the 2 examples. Workaround that by ending with an explicit
newline, which produces another stranger behavior (but visually correct)
of indenting the next line.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/243
2024-11-20 22:25:30 -06:00
Lucas De Marchi
263ab7243c man: Fix reference to MODULEDIR
The expression used is <MODULEDIR>, so keep it consistent with the
option name.

Fixes: e9f2580eaf ("man: Reword depmod's paths")
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/243
2024-11-20 22:25:30 -06:00
Lucas De Marchi
3d491c6fe4 depmod: Remove multiple ternary operations
Just keep a separate default value around and use it in case no option
from command line was parsed.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/243
2024-11-20 22:25:30 -06:00
Lucas De Marchi
63302cf655 util: Promote path_is_absolute() to header
This is a trivial function that can be used elsewhere. There's no point
in keeping the assert if we are going to crash in the very next
instruction. Rather add the relevant attribute and drop the assert.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/243
2024-11-20 22:25:30 -06:00
Lucas De Marchi
e82a548cb2 depmod: Fix error messages related to module_directory
It's no longer a constant: print the right message.

Fixes: 4f8a6a85 ("tools: Check snprintf return value")
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/243
2024-11-20 22:25:30 -06:00
Enrico Joerns
4b5d9681ce ci/codeql: use filter-sarif to filter meson-private
There is a severe number of false-positive in code scanning caused by
inspecting meson-internal test files like
'build/meson-private/tmpzb46osmq/testfile.c'.

As a workaround, use the 'filter-sarif' action to filter out these
results before uploading the SARIF (Static Analysis Results Interchange
Format).

This PR was inspired by https://github.com/rauc/rauc/pull/1346 and the
example from https://github.com/advanced-security/filter-sarif.

Signed-off-by: Enrico Joerns <ejo@pengutronix.de>
[Emil: port from rauc, use checksums for actions]
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/249
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2024-11-19 01:36:56 -06:00
Tobias Stoeckmann
9cbb979934 depmod: Properly check index keys
Synchronize character checks with libkmod-index.c. 8-bit ASCII chars
would turn negative (due to signed char), which index__checkstring does
not properly check for.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/247
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2024-11-19 01:34:57 -06:00
Emil Velikov
346928a9f1 ci: add meson setup -D {distconf,module}dir=relative/ checks
Based on the autotools build, meson does not support relative
directories for distconfig and moduledir. We fixed that recently, but
never added a check so we don't regress.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/245
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2024-11-19 01:11:10 -06:00
Tobias Stoeckmann
feb3108ce5 libkmod: Fix file error handling regression
The propagation of errors from loading function through errno must make
sure that errno is positive, otherwise errors are not correctly spotted.

Fixes: 81e5c797 ("libkmod: propagate {zstd,xz,zlib}_load errors")
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/242
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2024-11-19 00:24:58 -06:00
Tobias Stoeckmann
088e2e2d69 libkmod: Fix typo in comment
The word practise only exists in British English and is a verb.
Switch to practice and adjust style.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/241
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2024-11-19 00:23:32 -06:00
Tobias Stoeckmann
c14b75dfcc libkmod: Improve index comment
In version 1 of kmod, definitions of INDEX_MAGIC_OLD and INDEX_MAGIC
were in two adjacent lines, which made the sentence starting with
"Second one" much easier to read.

Since the "second one" is actually INDEX_MAGIC and even kmod version 1
did use it, let's not talk about "newer versioned binary files" anymore
but clearly state that 0xB007FA57 is deprecated.

Also add a missing full stop.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Signed-off-by: Max Kunzelmann <maxdev@posteo.de>
Link: https://github.com/kmod-project/kmod/pull/241
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2024-11-19 00:23:32 -06:00
Max Kunzelmann
eb82bae272 libkmod: Do not set errno in libkmod-index
Don't set errno in read functions ad it's a libc interface which we
should not be overriding. None of the functions up the call stack (some
examples) check on it.

Signed-off-by: Max Kunzelmann <maxdev@posteo.de>
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/240
[ Reword commit message according to suggestion by Emil and remove
  inline ]
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2024-11-19 00:04:54 -06:00
Lucas De Marchi
c6b4652dd9 Remove scratchbuf implementation
All its unique features have been ported to strbuf and users converted.
Nuke it.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/239
2024-11-17 15:35:14 -06:00
Lucas De Marchi
3fca291dc5 depmod: Convert output_symbols_bin() to strbuf
Remove last use of scratchbuf.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/239
2024-11-17 15:35:13 -06:00
Lucas De Marchi
d303efe370 depmod: Convert depmod_modules_search_path() to strbuf
Replace the scratchbuf usage with corresponding API from strbuf.

depmod_modules_search_path() itself may further be simplified in the
future to share opening the dir with depmod_modules_search_dir(),
but that is left for later.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/239
2024-11-17 15:35:13 -06:00
Lucas De Marchi
14ce34d755 strbuf: Add strbuf_shrink_to()
Useful when working with paths on a loop and resetting to a base path
component on every loop iteration.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/239
2024-11-17 15:35:13 -06:00
Lucas De Marchi
5706fb7d61 strbuf: Add strbuf_used()
So users don't feel tempted to look at inside the strbuf. Just add a
function for it and proper tests.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/239
2024-11-17 15:35:13 -06:00
Lucas De Marchi
68c0b9fb8c strbuf: Add strbuf_pushmem()
Wrapper for memcpy(). It's similar to strbuf_pushchars(), but push any
char, including the NUL byte, relying on the size passed as argument.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/239
2024-11-17 15:35:13 -06:00
Lucas De Marchi
cc2ba0b74a strbuf: Do not append '\0' if not needed
Unconditionally appending '\0' is not a big problem, but that does
trigger the buffer to potentially be re-allocated. Avoid that by
checking the last char is not already NUL.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/239
2024-11-17 15:35:13 -06:00
Lucas De Marchi
952bf223e0 strbuf: Add strbuf_reserve_extra()
To accomplish the same task as scratchbuf_alloc() does: make sure the
buffer has enough space for next operations. One difference is that
ensures **extra** space, not the total space. If needed in future,
a strbuf_reserve(), that resembles C++'s std::vector::reserve(), can be
added on top.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/239
2024-11-17 15:35:13 -06:00
Lucas De Marchi
1e36bfada5 strbuf: Allow to start with stack space
This is the main functionality of the scratchbuf implementation: it
starts with a buffer on stack that covers most of the calls, but also
has a fallback to allocate the buffer if it grows beyond the initial
size.

Port that functionality from scratchbuf to strbuf, so the former can be
eventually removed.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/239
2024-11-17 15:35:13 -06:00
Lucas De Marchi
25f2b2e096 strbuf: Invalidate (only) when stolen
The main for strbuf_steal() to free() on error was to allow the caller
to pass the NULL up the stack with just a return call to
strbuf_steal().

However this is error-prone and surprising that the buffer is still
invalidated on error. Provide an strbuf cleanup attribute that can be
used for the same purpose and make sure that when the string is stolen,
it's set to NULL, so there's no dangling pointer around.

Since we run the  testsuite with AddressSanitizer, a simple test can be
added to make sure the stolen string becomes valid when the attribute is
used.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/239
2024-11-17 15:35:13 -06:00
Lucas De Marchi
b8776806de strbuf: Document strbuf_popchar(s)
Document the behavior for these functions and also clarify why the
testsuite can check the buffer for equality after calling strbuf_str().

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/239
2024-11-17 15:35:13 -06:00
Lucas De Marchi
c83ce183f0 strbuf: Re-use buf_realloc()
Let the realloc happen in only one place, so we can change its behavior
in future.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/239
2024-11-17 15:35:13 -06:00
Lucas De Marchi
b7e2c1eb58 strbuf: Extract realloc
Extract the realloc from the size calculation so it can be shared with
other upcoming callers.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/239
2024-11-17 15:35:13 -06:00
Tobias Stoeckmann
ebd0476972 libkmod: Release memory on error paths
Do not override pointers to first list nodes if appending failed,
otherwise it's impossible to release already existing nodes of these
lists afterwards.

Remove the now unused function kmod_list_remove_n_latest as well.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/228
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2024-11-15 12:59:45 -06:00
Tobias Stoeckmann
5a5b4c545c depmod: Release memory on error path
Check malloc return value and clean up resources if allocation fails.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/228
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2024-11-15 12:59:45 -06:00
Tobias Stoeckmann
da0ee2217d depmod: Release memory on error paths
If a list node could not be added, release already allocated data which
was supposed to end up in list.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/228
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2024-11-15 12:59:45 -06:00
Tobias Stoeckmann
63aec6095b libkmod: Introduce kmod_list_release
Add a macro to reduce amount of explicit while-loops for removal of
nodes and release of their associated data in code base.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/228
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2024-11-15 12:59:45 -06:00
Emil Velikov
16ea23b741 libkmod: store common section off/size and use them
Currently, we repeatedly loop over the elf headers looking for five well
known sections. Just do it once in kmod_elf_new() and reuse the data as
needed.

Note that not all sections are guaranteed to be available, so check and
ELFDBG print the ones which are missing.

v2: quit looping when found, ELFDBG print missing sections
v3: match the first section name, use a loop

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/210
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2024-11-15 10:03:46 -06:00
Emil Velikov
9099346ce9 libkmod: rename kmod_elf_get_strings()
Rename kmod_elf_get_strings() to kmod_elf_get_modinfo_strings() and fold
the section name within, instead of passing it as an argument.

This aligns better with the other kmod_elf function names and will allow
us to tweak the kmod_elf_get_section() handling with later commit.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/210
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2024-11-15 10:03:46 -06:00
Emil Velikov
18567a8eb6 libkmod: stop copying symbol names in kmod_elf_get_dependency_symbols()
Since the caller already copies the strings as needed, we can just
point to the elf data directly.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/210
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2024-11-15 10:03:46 -06:00
Emil Velikov
4c74e4dcec libkmod: stop copying symbol names in kmod_elf_get_symbols()
Since the caller already copies the strings as needed, we can just
point to the elf data directly.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/210
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2024-11-15 10:03:46 -06:00
Emil Velikov
63e10397b0 libkmod: stop copying symbol names in kmod_elf_get_symbols_symtab()
Since the caller already copies the strings as needed, we can just
point to the elf data directly.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/210
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2024-11-15 10:03:46 -06:00
Emil Velikov
e5ef157bd5 libkmod: check for trailing \0 in __ksymtab_strings
As per the documentation (man 5 elf) the section must be null
terminated. Move the check further up and remove the no longer needed
code trying to workaround non-compliant instances.

Note: drop the erroneous +1 in the overflow (malloc size) calculation

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/210
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2024-11-15 10:03:46 -06:00
Emil Velikov
069d314f8a libkmod: stop copying symbol names in kmod_elf_get_modversions()
Since the caller already copies the strings as needed, we can just
point to the elf data directly.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/210
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2024-11-15 10:03:46 -06:00