summaryrefslogtreecommitdiff
path: root/passwd/apr_getpass.c
diff options
context:
space:
mode:
authorwrowe <wrowe@13f79535-47bb-0310-9956-ffa450edef68>2001-06-10 17:48:46 +0000
committerwrowe <wrowe@13f79535-47bb-0310-9956-ffa450edef68>2001-06-10 17:48:46 +0000
commitfd5eba229119d8129cf9b50e5fe5f2947c94b747 (patch)
tree1dacd1a14c7c4c9bb3d18271f87dc1bcd74913f8 /passwd/apr_getpass.c
parent738c282885703a9b1ee839d9e6cb9c023cc6bca5 (diff)
downloadlibapr-fd5eba229119d8129cf9b50e5fe5f2947c94b747.tar.gz
Even user created buffer overflows are ugly (ever leave something leaning
on the keyboard :-?) git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@61745 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'passwd/apr_getpass.c')
-rw-r--r--passwd/apr_getpass.c13
1 files changed, 5 insertions, 8 deletions
diff --git a/passwd/apr_getpass.c b/passwd/apr_getpass.c
index 8d012255e..c6dfb5c5b 100644
--- a/passwd/apr_getpass.c
+++ b/passwd/apr_getpass.c
@@ -113,11 +113,7 @@ static char *getpass(const char *prompt)
static char password[MAX_STRING_LEN];
fputs(prompt, stderr);
- gets((char *) &password);
-
- if (strlen((char *) &password) > (MAX_STRING_LEN - 1)) {
- password[MAX_STRING_LEN - 1] = '\0';
- }
+ fgets((char *) &password, sizeof(password), stdin);
return (char *) &password;
}
@@ -140,7 +136,7 @@ static char *getpass(const char *prompt)
if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &attr) != 0)
return NULL;
while ((password[n] = getchar()) != '\n') {
- if (password[n] >= ' ' && password[n] <= '~') {
+ if (n < sizeof(password) - 1 && password[n] >= ' ' && password[n] <= '~') {
n++;
} else {
fprintf(stderr,"\n");
@@ -175,7 +171,7 @@ static char *getpass(const char *prompt)
fputs(prompt, stderr);
while ((password[n] = _getch()) != '\r') {
- if (password[n] >= ' ' && password[n] <= '~') {
+ if (n < sizeof(password) - 1 && password[n] >= ' ' && password[n] <= '~') {
n++;
printf("*");
}
@@ -211,7 +207,8 @@ static char *getpass(const char *prompt)
*
* Restrictions: Truncation also occurs according to the host system's
* getpass() semantics, or at position 255 if our own version is used,
- * but the caller is *not* made aware of it.
+ * but the caller is *not* made aware of it unless their own buffer is
+ * smaller than our own.
*/
APR_DECLARE(apr_status_t) apr_password_get(const char *prompt, char *pwbuf, size_t *bufsiz)