Skip to content

Commit 2eba761

Browse files
committed
IO (OpenBSD): fixes incorrect glob usage
1 parent 4b5e1a8 commit 2eba761

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Bugfixes:
2929
* Fixes incorrect glibc dependency in polyfilled DEB packages (#1983, Linux)
3030
* Fixes corrupted binaries in polyfilled RPM packages (#1990, Linux)
3131
* Fixes crashes on ancient Android kernels (#1993, Disk, Android)
32+
* Fixes incorrect usage of `glob(3)` (OpenBSD)
3233
* Prefers resolutions reported by RandR mode info, fixing incorrect resolutions on XFCE when DPI scaling is enabled (Display, Linux)
3334
* Various code cleanups and minor fixes
3435

CMakeLists.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1743,6 +1743,7 @@ elseif(ANDROID)
17431743
target_link_libraries(libfastfetch
17441744
PRIVATE "m"
17451745
)
1746+
# https://github.com/termux/termux-packages/pull/7056
17461747
CHECK_LIBRARY_EXISTS(-l:libandroid-wordexp.a wordexp "" HAVE_LIBANDROID_WORDEXP_STATIC)
17471748
if(HAVE_LIBANDROID_WORDEXP_STATIC)
17481749
target_link_libraries(libfastfetch
@@ -1819,10 +1820,6 @@ if(NOT WIN32)
18191820
if(HAVE_WORDEXP)
18201821
target_compile_definitions(libfastfetch PRIVATE FF_HAVE_WORDEXP=1)
18211822
endif()
1822-
CHECK_INCLUDE_FILE("glob.h" HAVE_GLOB)
1823-
if(HAVE_GLOB)
1824-
target_compile_definitions(libfastfetch PRIVATE FF_HAVE_GLOB=1)
1825-
endif()
18261823
if(ENABLE_THREADS AND CMAKE_USE_PTHREADS_INIT)
18271824
CHECK_INCLUDE_FILE("pthread_np.h" HAVE_PTHREAD_NP)
18281825
if(HAVE_PTHREAD_NP)

src/common/io/io_unix.c

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,9 @@
1515

1616
#if FF_HAVE_WORDEXP
1717
#include <wordexp.h>
18-
#elif FF_HAVE_GLOB
19-
#warning "<wordexp.h> is not available, use <glob.h> instead"
20-
#include <glob.h>
2118
#else
22-
#warning "Neither <wordexp.h> nor <glob.h> is available"
19+
#warning "<wordexp.h> is not available, use glob(3) instead"
20+
#include <glob.h>
2321
#endif
2422

2523
static void createSubfolders(const char* fileName)
@@ -136,14 +134,14 @@ bool ffAppendFileBufferRelative(int dfd, const char* fileName, FFstrbuf* buffer)
136134
return ffAppendFDBuffer(fd, buffer);
137135
}
138136

139-
bool ffPathExpandEnv(FF_MAYBE_UNUSED const char* in, FF_MAYBE_UNUSED FFstrbuf* out)
137+
bool ffPathExpandEnv(const char* in, FFstrbuf* out)
140138
{
141139
bool result = false;
142140

143-
#if FF_HAVE_WORDEXP // https://github.com/termux/termux-packages/pull/7056
141+
#if FF_HAVE_WORDEXP
144142

145143
wordexp_t exp;
146-
if (wordexp(in, &exp, 0) != 0)
144+
if (wordexp(in, &exp, 0) != 0) // WARN: 0 = no safety flags; command substitution allowed
147145
return false;
148146

149147
if (exp.we_wordc >= 1)
@@ -154,16 +152,23 @@ bool ffPathExpandEnv(FF_MAYBE_UNUSED const char* in, FF_MAYBE_UNUSED FFstrbuf* o
154152

155153
wordfree(&exp);
156154

157-
#elif FF_HAVE_GLOB
155+
#else
158156

159157
glob_t gb;
160-
if (glob(in, GLOB_NOSORT | GLOB_TILDE, NULL, &gb) != 0)
158+
if (glob(in, GLOB_NOSORT
159+
#ifdef GLOB_TILDE
160+
| GLOB_TILDE
161+
#endif
162+
#ifdef GLOB_BRACE
163+
| GLOB_BRACE
164+
#endif
165+
, NULL, &gb) != 0)
161166
return false;
162167

163-
if (gb.gl_matchc >= 1)
168+
if (gb.gl_pathc >= 1)
164169
{
165170
result = true;
166-
ffStrbufSetS(out, gb.gl_pathv[gb.gl_matchc > 1 ? ffTimeGetNow() % gb.gl_matchc : 0]);
171+
ffStrbufSetS(out, gb.gl_pathv[gb.gl_pathc > 1 ? ffTimeGetNow() % (unsigned) gb.gl_pathc : 0]);
167172
}
168173

169174
globfree(&gb);

0 commit comments

Comments
 (0)