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;
|
struct termios tt, ttback;
|
||||||
memset(&ttback, 0, sizeof(ttback));
|
memset(&ttback, 0, sizeof(ttback));
|
||||||
if (tcgetattr(ttyfd, &ttback) < 0) {
|
if (tcgetattr(ttyfd, &ttback) < 0) {
|
||||||
printf("tcgetattr failed: %s\n", strerror(errno));
|
fprintf(stderr, "tcgetattr failed: %s\n", strerror(errno));
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(&tt, &ttback, sizeof(ttback));
|
memcpy(&tt, &ttback, sizeof(ttback));
|
||||||
tt.c_lflag &= ~(ICANON|ECHO);
|
tt.c_lflag &= ~(ICANON|ECHO);
|
||||||
if (tcsetattr(ttyfd, TCSANOW, &tt) < 0) {
|
if (tcsetattr(ttyfd, TCSANOW, &tt) < 0) {
|
||||||
printf("tcsetattr failed: %s\n", strerror(errno));
|
fprintf(stderr, "tcsetattr failed: %s\n", strerror(errno));
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,6 +74,7 @@ int main(void)
|
|||||||
unsigned int seed;
|
unsigned int seed;
|
||||||
|
|
||||||
readpass(str, 256);
|
readpass(str, 256);
|
||||||
|
str[255] = 0;
|
||||||
|
|
||||||
// the time used to type the pass is entropy
|
// the time used to type the pass is entropy
|
||||||
srand(time(NULL));
|
srand(time(NULL));
|
||||||
|
Loading…
Reference in New Issue
Block a user