-
Notifications
You must be signed in to change notification settings - Fork 323
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix for issue 685 #122
fix for issue 685 #122
Conversation
ssh-keygen prompt the user if he/she want to override the existing file, but exit
contrib/win32/win32compat/misc.c
Outdated
cp++; | ||
} while ((actual_read < n - 1) && *str_tmp != '\n'); | ||
|
||
if (actual_read > n - 1) { | ||
/* shouldn't happen. but handling in case */ | ||
errno = EINVAL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a error log
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added
contrib/win32/win32compat/misc.c
Outdated
} | ||
else | ||
break; | ||
cp++; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cp should be incremented by the strlen(str_tmp)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
contrib/win32/win32compat/misc.c
Outdated
} | ||
|
||
if((actual_read + strlen(str_tmp)) < n) { | ||
memcpy(cp, str_tmp, strlen(str_tmp) + 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why +1? is it for '\0'?
If yes then we can do it in the end before returning.. not required for every byte.. this might confuse us.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, for '\0'.
@@ -283,33 +283,49 @@ char* | |||
w32_fgets(char *str, int n, FILE *stream) { | |||
HANDLE h = (HANDLE)_get_osfhandle(_fileno(stream)); | |||
wchar_t* str_w = NULL; | |||
char *ret = NULL, *str_tmp = NULL; | |||
char *ret = NULL, *str_tmp = NULL, *cp = NULL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ret is not required. we can return str itself?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, according to https://linux.die.net/man/3/fgets, only return str on success; will return NULL on error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean, ret variable is not required.. we can still use str variable itself..at the start of the function initialize str to NULL and everywhere return str..
Its a minor comment, fix as you like.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, str is pre-allocated memory in caller function
contrib/win32/win32compat/misc.c
Outdated
goto cleanup; | ||
} | ||
|
||
if((actual_read + strlen(str_tmp)) < n) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can remove this if/else and add it as part of the while condition..
} while ( (actual_read = (actual_read + strlen(str_tmp)) && *str_tmp != '\n');
though line 321 is required.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, we need to check it before copying. strlen(str_tmp) may be more than the remaining length of str, we may copy more than n.
@@ -283,33 +283,49 @@ char* | |||
w32_fgets(char *str, int n, FILE *stream) { | |||
HANDLE h = (HANDLE)_get_osfhandle(_fileno(stream)); | |||
wchar_t* str_w = NULL; | |||
char *ret = NULL, *str_tmp = NULL; | |||
char *ret = NULL, *str_tmp = NULL, *cp = NULL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean, ret variable is not required.. we can still use str variable itself..at the start of the function initialize str to NULL and everywhere return str..
Its a minor comment, fix as you like.
free(str_tmp); | ||
if (fgetws(str_w, 2, stream) == NULL) | ||
goto cleanup; | ||
if ((str_tmp = utf16_to_utf8(str_w)) == NULL) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utf16_to_utf8 will alloc memory for each call. To optimize, you may create a static buffer (to accommodate 2 utf-8 character, max 8 bytes) and call WideCharToMultiByte directly)
do { | ||
if (str_tmp) | ||
free(str_tmp); | ||
if (fgetws(str_w, 2, stream) == NULL) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will not work for UTF-16 charactors that will occupy 2 wide chars (or 4 bytes)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Create a new issue to address comments below
fix for issue that ssh-keygen exit after prompt the user if he/she want to override the existing file.
PowerShell/Win32-OpenSSH#685