ensure null terminated str
This commit is contained in:
parent
5a5f1b8bfb
commit
a4b101cea8
@ -37,14 +37,14 @@ void readpass(char *buffer, int buflen)
|
||||
struct termios tt, ttback;
|
||||
memset(&ttback, 0, sizeof(ttback));
|
||||
if (tcgetattr(ttyfd, &ttback) < 0) {
|
||||
printf("tcgetattr failed: %s\n", strerror(errno));
|
||||
fprintf(stderr, "tcgetattr failed: %s\n", strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
memcpy(&tt, &ttback, sizeof(ttback));
|
||||
tt.c_lflag &= ~(ICANON|ECHO);
|
||||
if (tcsetattr(ttyfd, TCSANOW, &tt) < 0) {
|
||||
printf("tcsetattr failed: %s\n", strerror(errno));
|
||||
fprintf(stderr, "tcsetattr failed: %s\n", strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@ -74,6 +74,7 @@ int main(void)
|
||||
unsigned int seed;
|
||||
|
||||
readpass(str, 256);
|
||||
str[255] = 0;
|
||||
|
||||
// the time used to type the pass is entropy
|
||||
srand(time(NULL));
|
||||
|
Loading…
Reference in New Issue
Block a user