From fcead5ed7666d7c9f860d89c84e6276a76a6a666 Mon Sep 17 00:00:00 2001 From: bagajjal Date: Mon, 12 Feb 2018 11:49:33 -0800 Subject: [PATCH] Fixed issue with starting sshd in debug mode with a "./" (./sshd.exe -d) PowerShell/Win32-OpenSSH#1045 --- contrib/win32/win32compat/misc.c | 5 ++++- contrib/win32/win32compat/w32fd.c | 17 ++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/contrib/win32/win32compat/misc.c b/contrib/win32/win32compat/misc.c index 89c27ea2f..79eb1b601 100644 --- a/contrib/win32/win32compat/misc.c +++ b/contrib/win32/win32compat/misc.c @@ -1460,10 +1460,13 @@ int is_absolute_path(char *path) { int retVal = 0; + if(*path == '\"') /* skip double quote if path is "c:\abc" */ + path++; + if (*path == '/' || *path == '\\' || (*path != '\0' && isalpha(*path) && path[1] == ':') || ((strlen(path) >= strlen(PROGRAM_DATA)) && (memcmp(path, PROGRAM_DATA, strlen(PROGRAM_DATA)) == 0))) retVal = 1; - + return retVal; } diff --git a/contrib/win32/win32compat/w32fd.c b/contrib/win32/win32compat/w32fd.c index 66bb44a28..f2e46d14a 100644 --- a/contrib/win32/win32compat/w32fd.c +++ b/contrib/win32/win32compat/w32fd.c @@ -37,6 +37,7 @@ #include "inc\fcntl.h" #include "inc\sys\un.h" #include "inc\utf.h" +#include "inc\stdio.h" #include "w32fd.h" #include "signal_internal.h" @@ -953,16 +954,14 @@ spawn_child_internal(char* cmd, char *const argv[], HANDLE in, HANDLE out, HANDL int add_module_path = 0, ret = -1; /* should module path be added */ - do { - if (!cmd) - break; - t = cmd; - if (*t == '\"') - t++; - if (t[0] == '\0' || t[0] == '\\' || t[0] == '.' || t[1] == ':') - break; + if (!cmd) { + error("%s invalid argument cmd:%s", __func__, cmd); + return -1; + } + + t = cmd; + if (!is_absolute_path(t)) add_module_path = 1; - } while (0); /* compute total cmdline len*/ if (add_module_path)