Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FreeBSD Fix getLoadedLibraries() crash #2672

Merged
merged 1 commit into from
Jul 2, 2023

Conversation

mandree
Copy link
Contributor

@mandree mandree commented Jul 1, 2023

FreeBSD's getLoadedLibraries() uses libprocstat(3) to obtain the list of mapped files (libraries). However, the list obtained from procstat_getfiles() does not only return regular files, but might also return anonymous objects that have no entry->fs_path.

Motivation: With exiv2 v0.28, I had also observed crashes with a real TTY, and the entry->fs_path dereference would crash, even if it was only for a test "non-null", so we need something more thorough.

Add a check to only consider entry types of type VNODE (actual file system entries), and also make sure that entry->fs_path is defined (i.e. non-null) so we don't pass a nullptr to the std::string(const char *) constructor when we are reading corrupt data. std::string((const char *)0) on FreeBSD 13.2 - calls strlen() and crashes there.

@ghost
Copy link

ghost commented Jul 1, 2023

👇 Click on the image for a new way to code review

Review these changes using an interactive CodeSee Map

Legend

CodeSee Map legend

@codecov
Copy link

codecov bot commented Jul 1, 2023

Codecov Report

Merging #2672 (4d1b153) into main (9215f74) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##             main    #2672   +/-   ##
=======================================
  Coverage   63.92%   63.92%           
=======================================
  Files         103      103           
  Lines       22305    22305           
  Branches    10795    10795           
=======================================
  Hits        14258    14258           
  Misses       5826     5826           
  Partials     2221     2221           
Impacted Files Coverage Δ
src/version.cpp 88.46% <ø> (ø)

@neheb
Copy link
Collaborator

neheb commented Jul 1, 2023

needs to be formatted

FreeBSD's getLoadedLibraries() uses libprocstat(3) to obtain
the list of mapped files (libraries). However, the list
obtained from procstat_getfiles() does not only return regular files,
but might also return anonymous objects that have no fs->path.

With exiv2 v0.28, I had also observed crashes with a real TTY,
and the entry->fs_path dereference would crash, even if it
was only for a test "non-null", so we need something more thorough.

Add a check to only consider VNODEs (actual file system entries),
and also make sure that entry->fs_path is defined so we don't
pass a nullptr to the std::string(const char *) constructor when
we are reading corrupt data. std::string((const char *)0)
on FreeBSD 13.2 - calls strlen() and crashes there.
@mandree mandree force-pushed the mandree-fix-version-on-freebsd branch from 5219906 to 4d1b153 Compare July 1, 2023 21:33
@neheb neheb merged commit 91af090 into Exiv2:main Jul 2, 2023
109 checks passed
@neheb
Copy link
Collaborator

neheb commented Jul 2, 2023

@Mergifyio backport 0.28.x

@mergify
Copy link
Contributor

mergify bot commented Jul 2, 2023

backport 0.28.x

✅ Backports have been created

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants