Procházet zdrojové kódy

fix one-byte overflow in legacy getpass function

if the length of the input was equal to the buffer size (128), a fixed
value of zero was written one byte past the end of the static buffer.
Rich Felker před 8 roky
rodič
revize
3ec8b3aeb8
1 změnil soubory, kde provedl 1 přidání a 1 odebrání
  1. 1 1
      src/legacy/getpass.c

+ 1 - 1
src/legacy/getpass.c

@@ -27,7 +27,7 @@ char *getpass(const char *prompt)
 
 	l = read(fd, password, sizeof password);
 	if (l >= 0) {
-		if (l > 0 && password[l-1] == '\n') l--;
+		if (l > 0 && password[l-1] == '\n' || l==sizeof password) l--;
 		password[l] = 0;
 	}