From df114df05f8fdb8b3086608ed2d0bf5012b236b5 Mon Sep 17 00:00:00 2001 From: Olaf Meeuwissen Date: Sat, 28 Dec 2019 18:46:02 +0900 Subject: [PATCH] scanimage: Replace string length computations by temporary strings This creates temporary strings that correspond to the colon-delimited username and password that are read from file in `auth_callback()`. The null-terminated strings are used directly to determine lengths. --- frontend/scanimage.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/frontend/scanimage.c b/frontend/scanimage.c index f716d8292..70b5e0f68 100644 --- a/frontend/scanimage.c +++ b/frontend/scanimage.c @@ -208,25 +208,29 @@ auth_callback (SANE_String_Const resource, char *colon1 = strchr (tmp, ':'); if (colon1 != NULL) { + char *tmp_username = tmp; + *colon1 = '\0'; + char *colon2 = strchr (colon1 + 1, ':'); if (colon2 != NULL) { + char *tmp_password = colon1 + 1; + *colon2 = '\0'; if ((strncmp (colon2 + 1, resource, len) == 0) && ((int) strlen (colon2 + 1) == len)) { - - if ((colon1 - tmp) < SANE_MAX_USERNAME_LEN) + if (strlen (tmp_username) < SANE_MAX_USERNAME_LEN) { - if ((colon2 - (colon1 + 1)) < SANE_MAX_PASSWORD_LEN) + if (strlen (tmp_password) < SANE_MAX_PASSWORD_LEN) { - strncpy (username, tmp, colon1 - tmp); - username[colon1 - tmp] = 0; + strncpy (username, tmp_username, strlen (tmp_username)); + username[strlen (tmp_username)] = 0; - strncpy (password, colon1 + 1, colon2 - (colon1 + 1)); - password[colon2 - (colon1 + 1)] = 0; + strncpy (password, tmp_password, strlen (tmp_password)); + password[strlen (tmp_password)] = 0; query_user = 0; break;