Skip to content

Commit eacb22a

Browse files
committed
fix(detection/terminalshell): use absolute path to shell if available
1 parent 1c2c664 commit eacb22a

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

src/detection/terminalshell/terminalshell.c

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,9 @@ static bool extractBashVersion(const char* line, FF_MAYBE_UNUSED uint32_t len, v
6464
return false;
6565
}
6666

67-
static bool getShellVersionBash(FFstrbuf* exe, FFstrbuf* exePath, FFstrbuf* version)
67+
static bool getShellVersionBash(FFstrbuf* exe, FFstrbuf* version)
6868
{
69-
const char* path = exePath->chars;
70-
if (*path == '\0')
71-
path = exe->chars;
72-
ffBinaryExtractStrings(path, extractBashVersion, version, (uint32_t) strlen("@(#)Bash version 0.0.0(0) release GNU"));
69+
ffBinaryExtractStrings(exe->chars, extractBashVersion, version, (uint32_t) strlen("@(#)Bash version 0.0.0(0) release GNU"));
7370
if (version->length > 0) return true;
7471

7572
if(!getExeVersionRaw(exe, version))
@@ -230,13 +227,9 @@ static bool extractZshVersion(const char* line, FF_MAYBE_UNUSED uint32_t len, vo
230227
return false;
231228
}
232229

233-
static bool getShellVersionZsh(FFstrbuf* exe, FFstrbuf* exePath, FFstrbuf* version)
230+
static bool getShellVersionZsh(FFstrbuf* exe, FFstrbuf* version)
234231
{
235-
const char* path = exePath->chars;
236-
if (*path == '\0')
237-
path = exe->chars;
238-
239-
ffBinaryExtractStrings(path, extractZshVersion, version, (uint32_t) strlen("zsh-0.0-0"));
232+
ffBinaryExtractStrings(exe->chars, extractZshVersion, version, (uint32_t) strlen("zsh-0.0-0"));
240233
if (version->length) return true;
241234

242235
return getExeVersionGeneral(exe, version); //zsh 5.9 (arm-apple-darwin21.3.0)
@@ -270,10 +263,13 @@ bool fftsGetShellVersion(FFstrbuf* exe, const char* exeName, FFstrbuf* exePath,
270263
if(ffStrEqualsIgnCase(exeName, "sh")) // #849
271264
return false;
272265

266+
if (exePath->length > 0)
267+
exe = exePath;
268+
273269
if(ffStrEqualsIgnCase(exeName, "bash"))
274-
return getShellVersionBash(exe, exePath, version);
270+
return getShellVersionBash(exe, version);
275271
if(ffStrEqualsIgnCase(exeName, "zsh"))
276-
return getShellVersionZsh(exe, exePath, version);
272+
return getShellVersionZsh(exe, version);
277273
if(ffStrEqualsIgnCase(exeName, "fish"))
278274
return getShellVersionFish(exe, version);
279275
if(ffStrEqualsIgnCase(exeName, "pwsh"))

0 commit comments

Comments
 (0)