Emil Velikov [Wed, 23 Oct 2024 16:19:53 +0000 (17:19 +0100)]
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>
Emil Velikov [Wed, 23 Oct 2024 16:19:53 +0000 (17:19 +0100)]
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>
Emil Velikov [Wed, 23 Oct 2024 16:19:53 +0000 (17:19 +0100)]
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>
Emil Velikov [Thu, 24 Oct 2024 22:18:28 +0000 (23:18 +0100)]
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>
Emil Velikov [Wed, 23 Oct 2024 16:19:53 +0000 (17:19 +0100)]
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>
Emil Velikov [Wed, 23 Oct 2024 22:11:27 +0000 (23:11 +0100)]
libkmod: const annotate kmod_modversion::symbol
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>
Index files in pre-order have a significant performance improvement
for libkmod users.
On Arch Linux system, dumping configuration takes 296 read calls
in pre-order, compared to 4080 in post-order. Tests on a Raspberry
Pi 2 test system have shown an improvement by 9 %.
Even writing is faster now. This happens because we must know in
advance how many bytes index nodes will consume in the resulting file.
Although this code calculates it on the fly and caches the results,
saving lseek system calls has a significant positive effect which
compensates this extra overhead.
On Arch Linux system, writing index takes 6143 lseek calls now, compared
to previous 83701, leading to a performance gain of 13 %.
Emil Velikov [Mon, 11 Nov 2024 13:08:20 +0000 (13:08 +0000)]
meson: undefine NDEBUG in the tests
When using -D b_ndebug=true or inheriting CFLAGS="-DNDEBUG" from the
environment, the asserts will be no-op thus the checks in the
LD_PRELOADED libraries will be omitted.
Explicitly undefine the macro, so we don't accidentally shoot ourselves
in the foot.
dependabot[bot] [Fri, 8 Nov 2024 17:55:23 +0000 (17:55 +0000)]
ci: bump the all-actions group across 1 directory with 3 updates
Bumps the all-actions group with 3 updates in the / directory: [actions/checkout](https://github.com/actions/checkout), [yshui/git-clang-format-lint](https://github.com/yshui/git-clang-format-lint) and [github/codeql-action](https://github.com/github/codeql-action).
Updates `actions/checkout` from 4.1.7 to 4.2.2
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/692973e3d937129bcbf40652eb9f2f61becf3332...11bd71901bbe5b1630ceea73d27597364c9af683)
If an overly long signature is found in a module file, it is possible to
trigger an out of boundary write in kmod_module_hex_to_str due to
integer and subsequent heap buffer overflow.
This approach replaces malloc + sprintf with a simple hex-lookup and a
strbuf approach, being slightly faster in real life scenarios while
adding around 100 bytes to library size. A much faster approach could be
done without strbuf and using our overflow check functions, but
readability should win here.
Specially crafted files could overflow internal counters, allowing out of
boundary writes. Make sure that neither counters nor resulting calculations
overflow.
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/234 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Lucas De Marchi [Mon, 11 Nov 2024 15:04:44 +0000 (09:04 -0600)]
tree-wide: Sprinkle _clang_suppress_alloc_
Add the clang::suppress attribute to places where allocation is done and
that rely on the cleanup attribute. Clang analyzer doesn't handle those
(yet), so keep it from giving us false positive.
Lucas De Marchi [Sat, 9 Nov 2024 22:53:22 +0000 (16:53 -0600)]
shared: Ignore clang-analyzer on cleanup attribute
When using the cleanup attribute we know we are not leaking that
allocation. Most of the time the assignment is together with the
declaration, so we can simplify additional clang annotations by making
the cleanup attribute imply clang::suppress.
In cases declaration and assignment are not together, provide
_clang_suppress_alloc_ to annotate the code. That is only defined for
clang analyzer.
Lucas De Marchi [Sat, 9 Nov 2024 22:23:02 +0000 (16:23 -0600)]
build: Stop warning for attribute clang::suppress
That attribute allows us to instruct the Clang Static Analyzer to stop
giving some false positives. However when building the code (with gcc
and clang) they warn that the attribute is ignored. Just ignore as we
know what the attribute is for.
Emil Velikov [Thu, 7 Nov 2024 15:44:30 +0000 (15:44 +0000)]
man: add modprobe.conf.5 manpage link
Seemingly Fedora and friends have been carrying this one for years. Just
add it to kmod itself so that people using multiple distros have
consistent experience.
Emil Velikov [Thu, 7 Nov 2024 15:28:28 +0000 (15:28 +0000)]
meson: install the configuration directories
Install the /{etc,usr/lib}/{depmod,modprobe}.d/ configuration
directories as part of out install action.
Currently a handful of distros (Debian, Gentoo, Fedora, Arch) do that
manually, where we can have it in the upstream project instead.
As a pie in the sky idea, in the future we may choose to enforce
particular permissions, ownership, etc and this should make it a little
less fragile across the ecosystem.
Emil Velikov [Thu, 7 Nov 2024 14:17:28 +0000 (14:17 +0000)]
meson.build: install kmod symlinks to /usr/sbin/
With earlier commit we added support for kmod itself to install the
symlinks to kmod. While it works across the board, some distributions
still support (to varying degree) split /usr/bin and /usr/sbin.
This commit changes the location where those are created and bears no
functional change for merged bin-sbin users. While for split ones, it
follows what distributions are doing to a varying extend:
- Fedora, Alpine - this commit matches exactly what they do
- Debian, Yocto - they have an extra /bin/lsmod -> ../sbin/kmod symlink
- Gentoo - as Debian plus an extra /bin/modinfo -> ../sbin/kmod symlink
Emil Velikov [Tue, 5 Nov 2024 15:07:34 +0000 (15:07 +0000)]
ci: add code coverage via Codecov
Add a simple code coverage pipeline based on the CodeQL one.
Should give us pretty reports in the PRs and web UI with the results. We
can consider having HTML reports on our website (once it's up that is)
in addition or instead of at a future point.
Closes: https://github.com/kmod-project/kmod/issues/61 Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Link: https://github.com/kmod-project/kmod/pull/229 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
The commit reasoning was correct, but did not consider the case where
other third-party files are created. Namely: when generating the code
coverage files.
Thus the gcna files were created in $test_rootdir/$abs_top_builddir
which meant they won't get picked when the coverage info/xml/html files
were created and the statistics reported were quite wrong.
Revert the commit and add an inline comment, so we don't feel tempted to
change it in the future.
Emil Velikov [Tue, 5 Nov 2024 16:22:16 +0000 (16:22 +0000)]
ci/codeql: use Ubuntu 24.04, adjust build flags
While in here drop the docs and manpages flags - both of those combined
take ~1s of CI time - and disable the sanitizers and tests instead.
This means we no longer get pre-existing code problems in the tests,
which is fine considering the number of pre-existing issues in there.
Another nice side effect is that the pipeline time is reduced by ~50%.
Lucas De Marchi [Thu, 7 Nov 2024 17:13:11 +0000 (11:13 -0600)]
build: Drop define not picked by meson
For almost 13 years, since commit 769becb5dbfb ("tools: kmod: Add
handling of compat modinfo") we have a non-spoken joke in the build
system showing "-DANOTHER_BRICK_IN_THE -Wall" in honour of the famous
Pink Floyd song.
With configure flags now being sorted, I'm looking at the logs and
seeing: "-DANOTHER_BRICK_IN_THE -fdata-sections". That makes no sense.
Also the new meson build system did not join the joke. Not fun. Let's
drop it and let this commit serve as recognition of what it was.
Do not access memory out of bounds if the first character read by fgets
is NUL. Treat such a character as EOL instead. This is a purely
defensive measure since /proc/modules should normaly not contain such
characters.
Make sure that symbol names in ELF files are actually NUL terminated.
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/222 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Whenever sizeof(mv->crc) is used, it's called crclen, not offcrc.
Move retrieval of field sizes into its own function.
Prepare this as a cleanup for easier auditing.
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/222 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
This may be useful for anyone trying a non-debug build and serve as
baseline for distros. Even for developers, when benchmarking kmod, it's
better to run a release-oriented kmod rather than the slow one due to
all debug/sanitizers.
By keeping the -D in the command line rather than in a ini file,
we also guarantee meson shows it in the summary, regardless of
https://github.com/mesonbuild/meson/issues/13865.
Closes: https://github.com/kmod-project/kmod/issues/220 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/221
Emil Velikov [Fri, 1 Nov 2024 13:03:46 +0000 (13:03 +0000)]
ci: re-enable sanitizers with Fedora 41
We had the sanitizers disabled on Fedora 40, since the shared library
sanitizers comings with clang were not packaged. With Fedora 41 that has
changed, so let's try re-enabling them.
Emil Velikov [Fri, 1 Nov 2024 13:37:47 +0000 (13:37 +0000)]
scripts/sanitizer-env.sh: check and warn if OUR_PRELOAD is not a file
As seen with the upcoming clang 19 change, the library name has changed.
Enhance the current test to check if the compiler provided string is a
file and produce a warning with some handy tips when that's not the
case.
Emil Velikov [Mon, 4 Nov 2024 13:45:17 +0000 (13:45 +0000)]
scripts/sanitizer-env.sh: convert to heredoc
Convert to heredoc and add leading/trailing blank lines so it stands out
from the rest. It makes for cleaner reading experience both of the
script itself and its output.
Emil Velikov [Thu, 7 Nov 2024 15:14:14 +0000 (15:14 +0000)]
meson: s/modulesi/modules/ typo
Fix the typo in the option description.
Reported-by: Lucas De Marchi <lucas.de.marchi@gmail.com> Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Link: https://github.com/kmod-project/kmod/pull/225 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Emil Velikov [Mon, 4 Nov 2024 18:40:51 +0000 (18:40 +0000)]
meson: default enable compression and openssl
The default for the compressions and openssl is based on the autotools
build ones. With the initial goal to make migration as easy as possible
- identical option names, help messages, defaults...
Although a bunch of these have changed already, plus we want builders to
get support for compressed/signed modules out of the box.
So let's flip the defaults - everyone is welcome to adjust those when
calling `meson setup -D foo=bar`.
Emil Velikov [Thu, 31 Oct 2024 13:16:37 +0000 (13:16 +0000)]
meson: don't escape module_foo in kmod.pc
The kmod.pc file, contains module_signatures and module_compressions
space-separated lists, indicating how kmod is built. For the meson
generated file, any spaces are escaped where the autotools one does not
do that.
Update the meson build to be consistent with the original autotools one
and omit the escaping that we don't want.
Aside: seems like autotools does not escape the directory variables
either, so if the path(s) have any spaces in them pkg-config (pkgconf at
least) produces rubbish, quite rightfully IMHO.
Eg.
$ cat .../autotools-file.pc
prefix=/usr
includedir=${prefix}/include bar
Cflags: -I${includedir}
...
$ pkg-config --cflags autotools-file.pc
bar
$ cat .../meson-file.pc
prefix=/usr
includedir=${prefix}/include\ bar
Cflags: -I${includedir}
...
$ pkg-config --cflags meson-file.pc
-I/usr/include\ bar
This fixes a regression introduced while converting pointer to
offset arithmetics.
The for-loop itself starts at 1 already, so reflect this with the
manually performed offset + length calculation right at the start.
Closes: https://github.com/kmod-project/kmod/issues/214 Fixes: 25ab561b ("libkmod: Use ELF offsets more often") Reported-by: Emil Velikov <emil.l.velikov@gmail.com> Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org> Link: https://github.com/kmod-project/kmod/pull/215 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Return result of kmod_module_new directly in kmod_module_new_from_alias
so this function handles return values like the others.
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/211 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
If kmod_module_parse_depline runs out of memory, it is possible
that not all dependency modules are unlinked.
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/211 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
The module_get_dependencies_noref function may modify content of
given kmod_module struct, so clarify this fact.
Actually we would have to adjust kmod API for total clarification,
but let's start with internally used functions first.
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/211 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
The return value of kmod_module_parse_depline and
module_get_dependencies_noref are never used, and the same is true for
n_dep in struct kmod_module.
Remove them and turn variable n in kmod_module_parse_depline into a
size_t to make sure that it never overflows.
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/211 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
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/211 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
If functions exist which cover the exact explicitly written code, use
them instead.
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/211 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
This is in sync with read_char, which uses getc_unlocked. This and
previous FILE based index adjustments improved FILE based index dump
performance by 8 %.
Emil Velikov [Thu, 24 Oct 2024 12:46:47 +0000 (13:46 +0100)]
meson: disable automatic shell completion on prefix missmatch
Currently one can choose a prefix completely different from the one
bash-completion and fish use, as per their pkg-config file.
In such cases, flag a warning and disable it. People can always manually
provide the completion directory/ies to re-enable.
$ meson setup --prefix=/tmp/example build/
...
WARNING: User provided prefix '/tmp/example' differs from bash-completion one '/usr'. Disabling completion.
...
WARNING: User provided prefix '/tmp/example' differs from fish one '/usr'. Disabling completion.
Many values are never needed, so only parse them on demand. Also keep
pointers into memory-mapped area without copying data into dynamically
sized structs, which allows nodes to be kept on stack.
Improves performance of `modprobe -c` by around 3 %.
Emil Velikov [Mon, 21 Oct 2024 13:08:59 +0000 (14:08 +0100)]
docs: annotate the deprecated API
The kmod_module_get_filtered_blacklist() was deprecated since kmod v6 in
favour of kmod_module_apply_filter().
Add the decoration so gtk-doc includes it in the generated html and also
add a designated index.
It seem that gtk-doc insists on having deprecation guards, so not it
prints an extra warning like:
warning: XXX is deprecated in the inline comments, but no deprecation
guards were found around the declaration. (See the --deprecated-guards
option for gtkdoc-scan.)
Emil Velikov [Tue, 22 Oct 2024 20:28:27 +0000 (21:28 +0100)]
meson: always pass complete path to kmod-symlink.sh
The end-user can provide either relative (to prefix) or an absolute
directory for bindir. Just fold the prefix and bindir with join_path()
which handles this correctly and pass that to kmod-symlink.sh instead of
relying on the MESON_INSTALL_DESTDIR_PREFIX environment variable.
This was previously failing due to trying to create the symlink in the
wrong location:
$ meson setup --prefix /usr --bindir /bin build-gentoo
$ DESTDIR=/tmp/install-gentoo meson install -C build-gentoo/
...
ln: failed to create symbolic link '/tmp/install-gentoo/usr//bin/depmod': No such file or directory
FAILED: install script '/home/ldmartin/p/kmod/scripts/kmod-symlink.sh /bin/depmod' failed with exit code 1.
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Link: https://github.com/kmod-project/kmod/pull/205
[ fix typo, add repro ] Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
On 32 bit systems it's possible to overflow the final calculation of
required memory for symbols retrieved from __ksymtab_strings.
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/198 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Emil Velikov [Sun, 20 Oct 2024 12:39:02 +0000 (13:39 +0100)]
tools/depmod: use separate arrays for alias,xxxdep values
Currently, we walk the info list multiples times each time filtering all
but one key. Just create a few arrays to avoid that, saving 2-3% cycles
at the cost of extra ~500bytes per module.
Add a blank between variable declaration and function calls.
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/196 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Use correct format specifiers for size_t variables.
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/196 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
The contents of s and strings are identical at this point, but iterate
over the correct variable nonetheless.
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/196 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
An empty section is very unlikely, so reorder code to account for it.
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/196 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
The function's purpose can be merged into elf_get_section. Reduces
amount of duplicated code.
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/196 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Its only caller can do the processing directly (kmod_elf_new).
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/196 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
The name of string section is not needed, so it does not have to stored.
If section name is needed, return a char pointer instead of forcing the
caller to handle offset and memory calculations.
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/196 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Returned pointers are converted back to offsets in some functions. It is
more readable to turn offsets into pointers though.
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/196 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
This struct name is never used. Define it just like the other ones in
kmod_elf.
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/196 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
A huge module file could contain more symbols than could be represented
with an int. Use size_t instead.
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/196 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
The range check should be performed in its own function for better
readability and reusability. Also, perform range checks before loops
or otherwise repeated calls by checking whole ranges instead of
single byte areas within said ranges iteratively.
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/196 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Add a cheap but important check to make sure that offsets do not point
outside of memory-mapped area.
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/203 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Calling qsort with NULL argument is invalid, although size 0 would
prevent anything bad from happening. Make sure that UBSAN is not
triggered.
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/193 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Use shared/strbuf instead of manually re-implementing its features.
Reduces the amount of custom code in depmod, simplifies auditing,
reduces binary size, and has the nice benefit of slightly faster
runtime due to memory reusage.
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/193 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>