From bd0e921dd21f0b8663b6b4d00a345d210e6496a5 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Thu, 16 May 2024 15:54:20 +0300 Subject: [PATCH] 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 --- kdepasswd/passwd.cpp | 2 +- kdepasswd/process.cpp | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/kdepasswd/passwd.cpp b/kdepasswd/passwd.cpp index ddcb5719..59b012bb 100644 --- a/kdepasswd/passwd.cpp +++ b/kdepasswd/passwd.cpp @@ -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) { diff --git a/kdepasswd/process.cpp b/kdepasswd/process.cpp index b18343b3..9ba5905d 100644 --- a/kdepasswd/process.cpp +++ b/kdepasswd/process.cpp @@ -336,19 +336,21 @@ int PtyProcess::exec(const QByteArray &command, const QList &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(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. }