kdepasswd: correct arguments copying in PtyProcess::exec()

the first argument is supposed to be the program path (it was not even set
before), the other arguments were pointing to a QByteArray copy that was
free()-ed..

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2024-05-16 15:54:20 +03:00
parent ac98f37023
commit bd0e921dd2
2 changed files with 11 additions and 9 deletions

View file

@ -98,7 +98,7 @@ int PasswdProcess::exec(const char *oldpass, const char *newpass, int check)
ret = ConversePasswd(oldpass, newpass, check);
if (ret < 0) {
kDebug(1512) << "Conversation with passwd failed. pid = " << pid();
kDebug(1512) << "Conversation with passwd failed. pid = " << pid() << ret;
}
if ((waitForChild() != 0) && !check) {

View file

@ -336,19 +336,21 @@ int PtyProcess::exec(const QByteArray &command, const QList<QByteArray> &args)
path = QFile::encodeName(file);
}
const char **argp = (const char **)malloc((args.count()+2)*sizeof(char *));
int i = 1;
argp[i] = path;
foreach (QByteArray it, args) {
argp[i] = it;
char **argp = new char*[args.count() + 2];
int i = 0;
argp[i] = qstrdup(path.constData());
i++;
foreach (const QByteArray &it, args) {
argp[i] = qstrdup(it.constData());
i++;
}
argp[i] = NULL;
execv(path, const_cast<char **>(argp));
free(argp);
execv(path, argp);
delete[] argp;
kError(1512) << "execv(" << path << "):" << ::strerror(errno);
const int savederrno = errno;
kError(1512) << "execv(" << path << "):" << ::strerror(savederrno);
_exit(1);
return -1; // Shut up compiler. Never reached.
}