Makes parsing of values off of stdin more robust by initializing the buffers initial and checking the returns from scanf. Also, provides for a null domain by using '.' to make it easier to pipe values into xfreerdp.
(cherry picked from commit 74306c93cb
)
This commit is contained in:
parent
db9651f48e
commit
e8daef6574
@ -722,34 +722,42 @@ int freerdp_parse_args(rdpSettings* settings, int argc, char** argv,
|
||||
/* username */
|
||||
if (NULL == settings->username) {
|
||||
char input[512];
|
||||
input[0] = '\0';
|
||||
printf("username: ");
|
||||
scanf("%511s", input);
|
||||
settings->username = xstrdup(input);
|
||||
if (scanf("%511s", input) > 0) {
|
||||
settings->username = xstrdup(input);
|
||||
}
|
||||
}
|
||||
/* password */
|
||||
if (NULL == settings->password) {
|
||||
settings->password = xmalloc(512 * sizeof(char));
|
||||
if (isatty(STDIN_FILENO))
|
||||
freerdp_passphrase_read("password: ", settings->password, 512, settings->from_stdin);
|
||||
else
|
||||
{
|
||||
printf("password: ");
|
||||
scanf("%511s", settings->password);
|
||||
char input[512];
|
||||
input[0] = '\0';
|
||||
printf("password: ");
|
||||
if (scanf("%511s", input) > 0) {
|
||||
settings->password = xstrdup(input);
|
||||
}
|
||||
}
|
||||
/* domain */
|
||||
if (NULL == settings->domain) {
|
||||
char input[512];
|
||||
input[0] = '\0';
|
||||
printf("domain (control-D to skip): ");
|
||||
scanf("%511s", input);
|
||||
settings->domain = xstrdup(input);
|
||||
if (scanf("%511s", input) > 0) {
|
||||
/* Try to catch the cases where the string is NULL-ish right
|
||||
at the get go */
|
||||
if (input[0] != '\0' || (input[0] == ' ' && input[1] == '\0')) {
|
||||
settings->domain = xstrdup(input);
|
||||
}
|
||||
}
|
||||
}
|
||||
/* hostname */
|
||||
if (NULL == settings->hostname) {
|
||||
char input[512];
|
||||
input[0] = '\0';
|
||||
printf("hostname: ");
|
||||
scanf("%511s", input);
|
||||
freerdp_parse_hostname(settings, input);
|
||||
if (scanf("%511s", input) > 0) {
|
||||
freerdp_parse_hostname(settings, input);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user