lib: improve access checks on themes

This commit is contained in:
Vaxry 2024-03-26 15:26:26 +00:00
parent 1a1fcfb58d
commit d3876f3477
1 changed files with 33 additions and 8 deletions

View File

@ -49,14 +49,21 @@ static std::string getFirstTheme(PHYPRCURSORLOGFUNC logfn) {
for (auto& dir : userThemeDirs) { for (auto& dir : userThemeDirs) {
const auto FULLPATH = HOME + dir; const auto FULLPATH = HOME + dir;
if (!std::filesystem::exists(FULLPATH)) if (!themeAccessible(FULLPATH) || !std::filesystem::exists(FULLPATH)) {
Debug::log(HC_LOG_TRACE, logfn, "Skipping path {} because it's inaccessible.", FULLPATH);
continue; continue;
}
// loop over dirs and see if any has a manifest.hl // loop over dirs and see if any has a manifest.hl
for (auto& themeDir : std::filesystem::directory_iterator(FULLPATH)) { for (auto& themeDir : std::filesystem::directory_iterator(FULLPATH)) {
if (!themeDir.is_directory()) if (!themeDir.is_directory())
continue; continue;
if (!themeAccessible(themeDir.path().string())) {
Debug::log(HC_LOG_TRACE, logfn, "Skipping theme {} because it's inaccessible.", themeDir.path().string());
continue;
}
const auto MANIFESTPATH = themeDir.path().string() + "/manifest.hl"; const auto MANIFESTPATH = themeDir.path().string() + "/manifest.hl";
if (std::filesystem::exists(MANIFESTPATH)) { if (std::filesystem::exists(MANIFESTPATH)) {
@ -68,17 +75,24 @@ static std::string getFirstTheme(PHYPRCURSORLOGFUNC logfn) {
for (auto& dir : systemThemeDirs) { for (auto& dir : systemThemeDirs) {
const auto FULLPATH = dir; const auto FULLPATH = dir;
if (!std::filesystem::exists(FULLPATH)) if (!themeAccessible(FULLPATH) || !std::filesystem::exists(FULLPATH)) {
Debug::log(HC_LOG_TRACE, logfn, "Skipping path {} because it's inaccessible.", FULLPATH);
continue; continue;
}
// loop over dirs and see if any has a manifest.hl // loop over dirs and see if any has a manifest.hl
for (auto& themeDir : std::filesystem::directory_iterator(FULLPATH)) { for (auto& themeDir : std::filesystem::directory_iterator(FULLPATH)) {
if (!themeDir.is_directory()) if (!themeDir.is_directory())
continue; continue;
if (!themeAccessible(themeDir.path().string())) {
Debug::log(HC_LOG_TRACE, logfn, "Skipping theme {} because it's inaccessible.", themeDir.path().string());
continue;
}
const auto MANIFESTPATH = themeDir.path().string() + "/manifest.hl"; const auto MANIFESTPATH = themeDir.path().string() + "/manifest.hl";
if (std::filesystem::exists(MANIFESTPATH)) { if (!std::filesystem::exists(MANIFESTPATH)) {
Debug::log(HC_LOG_INFO, logfn, "getFirstTheme: found {}", themeDir.path().string()); Debug::log(HC_LOG_INFO, logfn, "getFirstTheme: found {}", themeDir.path().string());
return themeDir.path().stem().string(); return themeDir.path().stem().string();
} }
@ -97,14 +111,21 @@ static std::string getFullPathForThemeName(const std::string& name, PHYPRCURSORL
for (auto& dir : userThemeDirs) { for (auto& dir : userThemeDirs) {
const auto FULLPATH = HOME + dir; const auto FULLPATH = HOME + dir;
if (!std::filesystem::exists(FULLPATH)) if (!themeAccessible(FULLPATH) || !std::filesystem::exists(FULLPATH)) {
Debug::log(HC_LOG_TRACE, logfn, "Skipping path {} because it's inaccessible.", FULLPATH);
continue; continue;
}
// loop over dirs and see if any has a manifest.hl // loop over dirs and see if any has a manifest.hl
for (auto& themeDir : std::filesystem::directory_iterator(FULLPATH)) { for (auto& themeDir : std::filesystem::directory_iterator(FULLPATH)) {
if (!themeDir.is_directory()) if (!themeDir.is_directory())
continue; continue;
if (!themeAccessible(themeDir.path().string())) {
Debug::log(HC_LOG_TRACE, logfn, "Skipping theme {} because it's inaccessible.", themeDir.path().string());
continue;
}
const auto MANIFESTPATH = themeDir.path().string() + "/manifest.hl"; const auto MANIFESTPATH = themeDir.path().string() + "/manifest.hl";
if (name.empty()) { if (name.empty()) {
@ -138,16 +159,20 @@ static std::string getFullPathForThemeName(const std::string& name, PHYPRCURSORL
for (auto& dir : systemThemeDirs) { for (auto& dir : systemThemeDirs) {
const auto FULLPATH = dir; const auto FULLPATH = dir;
if (!std::filesystem::exists(FULLPATH)) if (!themeAccessible(FULLPATH) || !std::filesystem::exists(FULLPATH)) {
Debug::log(HC_LOG_TRACE, logfn, "Skipping path {} because it's inaccessible.", FULLPATH);
continue; continue;
}
// loop over dirs and see if any has a manifest.hl // loop over dirs and see if any has a manifest.hl
for (auto& themeDir : std::filesystem::directory_iterator(FULLPATH)) { for (auto& themeDir : std::filesystem::directory_iterator(FULLPATH)) {
if (!themeDir.is_directory()) if (!themeDir.is_directory())
continue; continue;
if (!themeAccessible(themeDir.path().string())) if (!themeAccessible(themeDir.path().string())) {
Debug::log(HC_LOG_TRACE, logfn, "Skipping theme {} because it's inaccessible.", themeDir.path().string());
continue; continue;
}
const auto MANIFESTPATH = themeDir.path().string() + "/manifest.hl"; const auto MANIFESTPATH = themeDir.path().string() + "/manifest.hl";
@ -589,7 +614,7 @@ static cairo_status_t readPNG(void* data, unsigned char* output, unsigned int le
DATA->readNeedle += toRead; DATA->readNeedle += toRead;
if (DATA->readNeedle >= DATA->dataLen) { if (DATA->readNeedle >= DATA->dataLen) {
delete[] (char*)DATA->data; delete[](char*) DATA->data;
DATA->data = nullptr; DATA->data = nullptr;
} }
@ -718,7 +743,7 @@ std::optional<std::string> CHyprcursorImplementation::loadTheme() {
IMAGE->cairoSurface = cairo_image_surface_create_from_png_stream(::readPNG, IMAGE); IMAGE->cairoSurface = cairo_image_surface_create_from_png_stream(::readPNG, IMAGE);
if (const auto STATUS = cairo_surface_status(IMAGE->cairoSurface); STATUS != CAIRO_STATUS_SUCCESS) { if (const auto STATUS = cairo_surface_status(IMAGE->cairoSurface); STATUS != CAIRO_STATUS_SUCCESS) {
delete[] (char*)IMAGE->data; delete[](char*) IMAGE->data;
IMAGE->data = nullptr; IMAGE->data = nullptr;
return "Failed reading cairoSurface, status " + std::to_string((int)STATUS); return "Failed reading cairoSurface, status " + std::to_string((int)STATUS);
} }