From 27ff437ee579e03bc0a584a0be1e11b2629bbffb Mon Sep 17 00:00:00 2001 From: Vadim Bendebury Date: Tue, 6 Sep 2022 10:26:20 -0700 Subject: gsctool: fix compilation problems It turns out that due to a bug in ./Makefile gsctool is always compiled with -O0. Fixing the make file bug highlighted a bug in gsctool code where a return value of getline() was left unchecked. This patch fixes the gsctool compilation problem. BUG=b:245028043 TEST=Verified that gsctool now builds successfully with -O3. Verified that attempts to set password are properly failed when entered passwords are of different length and succeed otherwise. Change-Id: I8a3f337f3d40ff14a23162fab796b5b02f6cc664 Signed-off-by: Vadim Bendebury Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3876011 Tested-by: Vadim Bendebury Commit-Queue: Vadim Bendebury Reviewed-by: Mary Ruthven Reviewed-by: Brian Norris --- extra/usb_updater/gsctool.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'extra/usb_updater/gsctool.c') diff --git a/extra/usb_updater/gsctool.c b/extra/usb_updater/gsctool.c index 04432462eb..f40bf25da2 100644 --- a/extra/usb_updater/gsctool.c +++ b/extra/usb_updater/gsctool.c @@ -1968,8 +1968,9 @@ static uint32_t common_process_password(struct transfer_descriptor *td, uint32_t rv; char *password = NULL; char *password_copy = NULL; - size_t copy_len = 0; - size_t len = 0; + ssize_t copy_len; + ssize_t len; + size_t zero = 0; struct termios oldattr, newattr; /* Suppress command line echo while password is being entered. */ @@ -1981,20 +1982,23 @@ static uint32_t common_process_password(struct transfer_descriptor *td, /* With command line echo suppressed request password entry twice. */ printf("Enter password:"); - len = getline(&password, &len, stdin); + len = getline(&password, &zero, stdin); printf("Re-enter password:"); - getline(&password_copy, ©_len, stdin); + zero = 0; + copy_len = getline(&password_copy, &zero, stdin); /* Restore command line echo. */ tcsetattr(STDIN_FILENO, TCSANOW, &oldattr); /* Empty password will still have the newline. */ - if ((len <= 1) || !password_copy) { + if ((len <= 1) || !password_copy || (copy_len != len)) { + fprintf(stderr, "Error reading password\n"); if (password) free(password); if (password_copy) free(password_copy); - fprintf(stderr, "Error reading password\n"); + if ((copy_len >= 0) && (len >= 0) && (copy_len != len)) + fprintf(stderr, "Password length mismatch\n"); exit(update_error); } -- cgit v1.2.1