summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVadim Bendebury <vbendeb@google.com>2022-09-06 10:26:20 -0700
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-09-07 00:21:58 +0000
commit27ff437ee579e03bc0a584a0be1e11b2629bbffb (patch)
treea3bc980037a60d403b07ef02a08d53c8ad566ca0
parent8cc24f9c7f076d25869a167efdc504b1e49947e1 (diff)
downloadchrome-ec-27ff437ee579e03bc0a584a0be1e11b2629bbffb.tar.gz
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 <vbendeb@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3876011 Tested-by: Vadim Bendebury <vbendeb@chromium.org> Commit-Queue: Vadim Bendebury <vbendeb@chromium.org> Reviewed-by: Mary Ruthven <mruthven@chromium.org> Reviewed-by: Brian Norris <briannorris@chromium.org>
-rw-r--r--extra/usb_updater/gsctool.c16
1 files changed, 10 insertions, 6 deletions
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, &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);
}