From 3a25462844da31be9a4ef64cc8a1aa7a67ea0ee5 Mon Sep 17 00:00:00 2001 From: Yan Wang <68562925+yanw-bq@users.noreply.github.com> Date: Wed, 7 Jul 2021 15:08:00 -0700 Subject: [PATCH] add one more keyword that needs to be masked (#101) * add one more keyword that needs to be masked * improve hide_password() --- src/odfesqlodbc/drvconn.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/odfesqlodbc/drvconn.c b/src/odfesqlodbc/drvconn.c index e60d85b49..6af0e927e 100644 --- a/src/odfesqlodbc/drvconn.c +++ b/src/odfesqlodbc/drvconn.c @@ -49,27 +49,25 @@ extern HINSTANCE s_hModule; /* Saved module handle. */ char *hide_password(const char *str) { char *outstr, *pwdp; - const char *pwd_key = "PWD="; - const char *aad_secret_key = "AADClientSecret="; if (!str) return NULL; outstr = strdup(str); if (!outstr) return NULL; - if (pwdp = stristr(outstr, pwd_key), pwdp) { - char *p; - for (p = pwdp + strlen(pwd_key); *p && *p != ';'; p++) - *p = 'x'; - } + const char *str_to_hide[] = {"PWD=", "SecretAccessKey=", "AADClientSecret="}; + size_t size = sizeof(str_to_hide)/sizeof(str_to_hide[0]); - if (pwdp = stristr(outstr, aad_secret_key), pwdp) { - char *p; + for (size_t i = 0; i < size; ++i) { + if (pwdp = stristr(outstr, str_to_hide[i]), pwdp) { + char *p; - for (p = pwdp + strlen(aad_secret_key); *p && *p != ';'; p++) - *p = 'x'; + for (p = pwdp + strlen(str_to_hide[i]); *p && *p != ';'; p++) + *p = 'x'; + } } + return outstr; }