ソースを参照

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 8 年 前
コミット
3ec8b3aeb8
1 ファイル変更1 行追加1 行削除
  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;
 	}