mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Use external_call to get password via eval_password command
Signed-off-by: Pierre Mazière <pierre.maziere@gmx.com>
This commit is contained in:
parent
d92c576aa5
commit
fad77d9d70
@ -194,32 +194,30 @@ account_eval_password(ProfAccount *account)
|
|||||||
assert(account != NULL);
|
assert(account != NULL);
|
||||||
assert(account->eval_password != NULL);
|
assert(account->eval_password != NULL);
|
||||||
|
|
||||||
// Evaluate as shell command to retrieve password
|
gchar **output = NULL;
|
||||||
GString *cmd = g_string_new("");
|
gchar **argv = g_strsplit(account->eval_password, " ", 0);
|
||||||
g_string_append_printf(cmd, "%s 2>/dev/null", account->eval_password);
|
|
||||||
|
|
||||||
FILE *stream = popen(cmd->str, "r");
|
if (!call_external(argv, &output, NULL)) {
|
||||||
g_string_free(cmd, TRUE);
|
g_strfreev(argv);
|
||||||
if (stream) {
|
argv = NULL;
|
||||||
// Limit to READ_BUF_SIZE bytes to prevent overflows in the case of a poorly chosen command
|
return FALSE;
|
||||||
account->password = g_malloc(READ_BUF_SIZE);
|
}
|
||||||
if (!account->password) {
|
|
||||||
log_error("Failed to allocate enough memory to read eval_password output");
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
account->password = fgets(account->password, READ_BUF_SIZE, stream);
|
|
||||||
pclose(stream);
|
|
||||||
if (!account->password) {
|
|
||||||
log_error("No result from eval_password.");
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
// strip trailing newline
|
g_strfreev(argv);
|
||||||
if (g_str_has_suffix(account->password, "\n")) {
|
|
||||||
account->password[strlen(account->password)-1] = '\0';
|
if (!output || !output[0]) {
|
||||||
}
|
log_error("Failed to read eval_password output");
|
||||||
} else {
|
g_strfreev(output);
|
||||||
log_error("popen failed when running eval_password.");
|
output = NULL;
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
account->password = strdup(output[0]);
|
||||||
|
g_strfreev(output);
|
||||||
|
output = NULL;
|
||||||
|
|
||||||
|
if (!account->password) {
|
||||||
|
log_error("Failed to allocate enough memory to read eval_password output");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user