From: autoantwort <41973254+autoantwort@users.noreply.github.com> Date: Wed, 10 Sep 2025 16:48:42 +0000 (+0200) Subject: test: Handle GetVolumePathName errors, prevent access violation (#1626) X-Git-Tag: v4.12~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4cb8702a7bb52ed859564822011958a62c3582f2;p=thirdparty%2Fccache.git test: Handle GetVolumePathName errors, prevent access violation (#1626) For example GetVolumePathName returns `F:/git_projects` on my computer which does not fit in a char[4]. As a result GetVolumePathName returns an error and a std::string is initialized from uninitialized memory which may not contain a '\0' resulting in out of bounds memory reads. Co-authored-by: Leander Schulten --- diff --git a/unittest/test_argprocessing.cpp b/unittest/test_argprocessing.cpp index 4c2a97f4..41c5d46b 100644 --- a/unittest/test_argprocessing.cpp +++ b/unittest/test_argprocessing.cpp @@ -48,10 +48,11 @@ get_root() #ifndef _WIN32 return "/"; #else - char volume[4]; // "C:\" - GetVolumePathName( - util::pstr(*fs::current_path()).c_str(), volume, sizeof(volume)); - return volume; + auto cwd = fs::current_path(); + if (!cwd) { + FAIL("get_root failed: ", cwd.error()); + } + return cwd->root_path().generic_u8string(); #endif }