7zip/7z-dont-echo-password.diff
Michel Lind a36dfa5ae6
Update to 25.01
- 25.00+ fixes CVE-2025-11001; Resolves: rhbz#2416011
- Backport Debian patch to disable echo-ing password;
  Resolves: rhbz#2412315

Signed-off-by: Michel Lind <salimma@fedoraproject.org>
2025-11-26 15:48:28 +00:00

75 lines
2 KiB
Diff

From ece9df515b12f9bde2e8150f402db3f394d03db3 Mon Sep 17 00:00:00 2001
From: Wes <5124946+wesinator@users.noreply.github.com>
Date: Tue, 4 Jun 2024 10:18:45 -0400
Subject: [PATCH] Disable local echo display with input passwords in linux
https://salsa.debian.org/debian/7zip/-/commit/7b5e9a72d4579b875906134943fb9590cf165d73
close #10
---
CPP/7zip/UI/Console/UserInputUtils.cpp | 35 ++++++++++++++++++++++++--
1 file changed, 33 insertions(+), 2 deletions(-)
diff --git a/CPP/7zip/UI/Console/UserInputUtils.cpp b/CPP/7zip/UI/Console/UserInputUtils.cpp
index 2adf9dfed..eb44fa00a 100644
--- a/CPP/7zip/UI/Console/UserInputUtils.cpp
+++ b/CPP/7zip/UI/Console/UserInputUtils.cpp
@@ -57,9 +57,18 @@ NUserAnswerMode::EEnum ScanUserYesNoAllQuit(CStdOutStream *outStream)
#ifdef _WIN32
#ifndef UNDER_CE
#define MY_DISABLE_ECHO
+#define MY_DISABLE_ECHO_WIN32
#endif
#endif
+#ifdef unix
+#include <stdio.h>
+#include <termios.h>
+#include <unistd.h>
+#define MY_DISABLE_ECHO
+#define MY_DISABLE_ECHO_UNIX
+#endif
+
static bool GetPassword(CStdOutStream *outStream, UString &psw)
{
if (outStream)
@@ -72,7 +81,7 @@ static bool GetPassword(CStdOutStream *outStream, UString &psw)
outStream->Flush();
}
- #ifdef MY_DISABLE_ECHO
+ #ifdef MY_DISABLE_ECHO_WIN32
const HANDLE console = GetStdHandle(STD_INPUT_HANDLE);
@@ -90,7 +99,29 @@ static bool GetPassword(CStdOutStream *outStream, UString &psw)
const bool res = g_StdIn.ScanUStringUntilNewLine(psw);
if (wasChanged)
SetConsoleMode(console, mode);
-
+
+ #elif defined(MY_DISABLE_ECHO_UNIX)
+
+ int ifd = fileno(stdin);
+ bool wasChanged = false;
+ struct termios old_mode = {};
+ struct termios new_mode = {};
+
+ if (tcgetattr(ifd, &old_mode) == 0) {
+ new_mode = old_mode;
+ new_mode.c_lflag &= ~ECHO;
+
+ wasChanged = true;
+
+ tcsetattr(ifd, TCSAFLUSH, &new_mode);
+ }
+
+ bool res = g_StdIn.ScanUStringUntilNewLine(psw);
+
+ if (wasChanged) {
+ tcsetattr(ifd, TCSAFLUSH, &old_mode);
+ }
+
#else
const bool res = g_StdIn.ScanUStringUntilNewLine(psw);