diff --git a/src/common/processing_linux.c b/src/common/processing_linux.c index 7ddd725da..73f72a5a9 100644 --- a/src/common/processing_linux.c +++ b/src/common/processing_linux.c @@ -273,6 +273,10 @@ void ffProcessGetInfoLinux(pid_t pid, FFstrbuf* processName, FFstrbuf* exe, cons ffStrbufEnsureFixedLengthFree(exePath, (uint32_t)length); ffStrbufAppendNS(exePath, (uint32_t)length, buf); } + else + { + ffStrbufSetS(exePath, filePath); + } } #elif defined(__APPLE__) diff --git a/src/detection/terminalshell/terminalshell.c b/src/detection/terminalshell/terminalshell.c index 5ffae3691..e9fa5e3ff 100644 --- a/src/detection/terminalshell/terminalshell.c +++ b/src/detection/terminalshell/terminalshell.c @@ -64,12 +64,9 @@ static bool extractBashVersion(const char* line, FF_MAYBE_UNUSED uint32_t len, v return false; } -static bool getShellVersionBash(FFstrbuf* exe, FFstrbuf* exePath, FFstrbuf* version) +static bool getShellVersionBash(FFstrbuf* exe, FFstrbuf* version) { - const char* path = exePath->chars; - if (*path == '\0') - path = exe->chars; - ffBinaryExtractStrings(path, extractBashVersion, version, (uint32_t) strlen("@(#)Bash version 0.0.0(0) release GNU")); + ffBinaryExtractStrings(exe->chars, extractBashVersion, version, (uint32_t) strlen("@(#)Bash version 0.0.0(0) release GNU")); if (version->length > 0) return true; if(!getExeVersionRaw(exe, version)) @@ -230,13 +227,9 @@ static bool extractZshVersion(const char* line, FF_MAYBE_UNUSED uint32_t len, vo return false; } -static bool getShellVersionZsh(FFstrbuf* exe, FFstrbuf* exePath, FFstrbuf* version) +static bool getShellVersionZsh(FFstrbuf* exe, FFstrbuf* version) { - const char* path = exePath->chars; - if (*path == '\0') - path = exe->chars; - - ffBinaryExtractStrings(path, extractZshVersion, version, (uint32_t) strlen("zsh-0.0-0")); + ffBinaryExtractStrings(exe->chars, extractZshVersion, version, (uint32_t) strlen("zsh-0.0-0")); if (version->length) return true; return getExeVersionGeneral(exe, version); //zsh 5.9 (arm-apple-darwin21.3.0) @@ -263,7 +256,7 @@ static bool getShellVersionWinPowerShell(FFstrbuf* exe, FFstrbuf* version) } #endif -bool fftsGetShellVersion(FFstrbuf* exe, const char* exeName, FFstrbuf* exePath, FFstrbuf* version) +bool fftsGetShellVersion(FFstrbuf* exe, const char* exeName, FFstrbuf* version) { if (!instance.config.general.detectVersion) return false; @@ -271,9 +264,9 @@ bool fftsGetShellVersion(FFstrbuf* exe, const char* exeName, FFstrbuf* exePath, return false; if(ffStrEqualsIgnCase(exeName, "bash")) - return getShellVersionBash(exe, exePath, version); + return getShellVersionBash(exe, version); if(ffStrEqualsIgnCase(exeName, "zsh")) - return getShellVersionZsh(exe, exePath, version); + return getShellVersionZsh(exe, version); if(ffStrEqualsIgnCase(exeName, "fish")) return getShellVersionFish(exe, version); if(ffStrEqualsIgnCase(exeName, "pwsh")) diff --git a/src/detection/terminalshell/terminalshell_linux.c b/src/detection/terminalshell/terminalshell_linux.c index e39ea9ef5..e9dc225a8 100644 --- a/src/detection/terminalshell/terminalshell_linux.c +++ b/src/detection/terminalshell/terminalshell_linux.c @@ -292,14 +292,14 @@ static void getUserShellFromEnv(FFShellResult* result) } } -bool fftsGetShellVersion(FFstrbuf* exe, const char* exeName, FFstrbuf* exePath, FFstrbuf* version); +bool fftsGetShellVersion(FFstrbuf* exe, const char* exeName, FFstrbuf* version); bool fftsGetTerminalVersion(FFstrbuf* processName, FFstrbuf* exe, FFstrbuf* version); static void setShellInfoDetails(FFShellResult* result) { ffStrbufClear(&result->version); - fftsGetShellVersion(&result->exe, result->exeName, &result->exePath, &result->version); + fftsGetShellVersion(result->exePath.length > 0 ? &result->exePath : &result->exe, result->exeName, &result->version); if(ffStrbufEqualS(&result->processName, "pwsh")) ffStrbufInitStatic(&result->prettyName, "PowerShell"); @@ -383,7 +383,7 @@ static void setTerminalInfoDetails(FFTerminalResult* result) else ffStrbufInitCopy(&result->prettyName, &result->processName); - fftsGetTerminalVersion(&result->processName, &result->exe, &result->version); + fftsGetTerminalVersion(&result->processName, result->exePath.length > 0 ? &result->exePath : &result->exe, &result->version); } #if defined(MAXPATH) diff --git a/src/detection/terminalshell/terminalshell_windows.c b/src/detection/terminalshell/terminalshell_windows.c index 8e4e388a9..1fc1ad760 100644 --- a/src/detection/terminalshell/terminalshell_windows.c +++ b/src/detection/terminalshell/terminalshell_windows.c @@ -12,7 +12,7 @@ #include #include -bool fftsGetShellVersion(FFstrbuf* exe, const char* exeName, const FFstrbuf* exePath, FFstrbuf* version); +bool fftsGetShellVersion(FFstrbuf* exe, const char* exeName, FFstrbuf* version); static uint32_t getShellInfo(FFShellResult* result, uint32_t pid) { @@ -332,7 +332,7 @@ const FFShellResult* ffDetectShell(void) strcpy(tmp, result.exeName); char* ext = strrchr(tmp, '.'); if (ext) *ext = '\0'; - fftsGetShellVersion(&result.exe, tmp, &result.exePath, &result.version); + fftsGetShellVersion(result.exePath.length > 0 ? &result.exePath : &result.exe, tmp, &result.version); } return &result; @@ -368,7 +368,7 @@ const FFTerminalResult* ffDetectTerminal(void) if(result.processName.length > 0) { setTerminalInfoDetails(&result); - fftsGetTerminalVersion(&result.processName, &result.exe, &result.version); + fftsGetTerminalVersion(&result.processName, result.exePath.length > 0 ? &result.exePath : &result.exe, &result.version); } return &result;