Error checking for fgets to remove unused return warnings
parent
0cde0ad3ec
commit
ead4080e5b
|
@ -250,18 +250,21 @@ int NoEcho(char* key, int size)
|
|||
nflags.c_lflag |= ECHONL;
|
||||
|
||||
if (tcsetattr(fileno(stdin), TCSANOW, &nflags) != 0) {
|
||||
printf("Error\n");
|
||||
printf("Error: tcsetattr failed to disable terminal echo\n");
|
||||
return -1060;
|
||||
}
|
||||
|
||||
printf("Unique Password: ");
|
||||
fgets(key, size, stdin);
|
||||
if (fgets(key, size, stdin) == NULL) {
|
||||
printf("Error: fgets failed to retrieve secure key input\n");
|
||||
return -1070;
|
||||
}
|
||||
key[strlen(key) - 1] = 0;
|
||||
|
||||
/* restore terminal */
|
||||
if (tcsetattr(fileno(stdin), TCSANOW, &oflags) != 0) {
|
||||
printf("Error\n");
|
||||
return -1070;
|
||||
printf("Error: tcsetattr failed to enable terminal echo\n");
|
||||
return -1080;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ int GenerateKey(RNG* rng, byte* key, int size, byte* salt, int pad)
|
|||
|
||||
/* stretches key */
|
||||
ret = wc_PBKDF2(key, key, strlen((const char*)key), salt, SALT_SIZE, 4096,
|
||||
size, WC_SHA256);
|
||||
size, WC_SHA256);
|
||||
if (ret != 0)
|
||||
return -1030;
|
||||
|
||||
|
@ -182,7 +182,7 @@ int AesDecrypt(Aes* aes, byte* key, int size, FILE* inFile, FILE* outFile)
|
|||
|
||||
/* replicates old key if keys match */
|
||||
ret = wc_PBKDF2(key, key, strlen((const char*)key), salt, SALT_SIZE, 4096,
|
||||
size, WC_SHA256);
|
||||
size, WC_SHA256);
|
||||
if (ret != 0)
|
||||
return -1050;
|
||||
|
||||
|
@ -249,18 +249,22 @@ int NoEcho(char* key, int size)
|
|||
nflags.c_lflag |= ECHONL;
|
||||
|
||||
if (tcsetattr(fileno(stdin), TCSANOW, &nflags) != 0) {
|
||||
printf("Error\n");
|
||||
printf("Error: tcsetattr failed to disable terminal echo\n");
|
||||
return -1060;
|
||||
}
|
||||
|
||||
printf("Unique Password: ");
|
||||
fgets(key, size, stdin);
|
||||
if (fgets(key, size, stdin) == NULL) {
|
||||
printf("Error: fgets failed to retrieve secure key input\n");
|
||||
return -1070;
|
||||
}
|
||||
|
||||
key[strlen(key) - 1] = 0;
|
||||
|
||||
/* restore terminal */
|
||||
if (tcsetattr(fileno(stdin), TCSANOW, &oflags) != 0) {
|
||||
printf("Error\n");
|
||||
return -1070;
|
||||
printf("Error: tcsetattr failed to enable terminal echo\n");
|
||||
return -1080;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -246,18 +246,22 @@ int NoEcho(char* key, int size)
|
|||
nflags.c_lflag |= ECHONL;
|
||||
|
||||
if (tcsetattr(fileno(stdin), TCSANOW, &nflags) != 0) {
|
||||
printf("Error\n");
|
||||
printf("Error: tcsetattr failed to disable terminal echo\n");
|
||||
return -1060;
|
||||
}
|
||||
|
||||
printf("Unique Password: ");
|
||||
fgets(key, size, stdin);
|
||||
if (fgets(key, size, stdin) == NULL) {
|
||||
printf("Error: fgets failed to retrieve secure key input\n");
|
||||
return -1070;
|
||||
}
|
||||
|
||||
key[strlen(key) - 1] = 0;
|
||||
|
||||
/* restore terminal */
|
||||
if (tcsetattr(fileno(stdin), TCSANOW, &oflags) != 0) {
|
||||
printf("Error\n");
|
||||
return -1070;
|
||||
printf("Error: tcsetattr failed to enable terminal echo\n");
|
||||
return -1080;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -88,7 +88,10 @@ int main(int argc, char** argv)
|
|||
/* Get a message for the server from stdin */
|
||||
printf("Message for server: ");
|
||||
memset(buff, 0, sizeof(buff));
|
||||
fgets(buff, sizeof(buff), stdin);
|
||||
if (fgets(buff, sizeof(buff), stdin) == NULL) {
|
||||
fprintf(stderr, "ERROR: failed to get message for server\n");
|
||||
return -1;
|
||||
}
|
||||
len = strnlen(buff, sizeof(buff));
|
||||
|
||||
/* Send the message to the server */
|
||||
|
|
|
@ -43,7 +43,10 @@ int ClientGreet(int sock, WOLFSSL* ssl)
|
|||
int ret = 0; /* variable for error checking */
|
||||
|
||||
printf("Message for server:\t");
|
||||
fgets(sendBuff, MAXDATASIZE, stdin);
|
||||
if (fgets(sendBuff, MAXDATASIZE, stdin) == NULL) {
|
||||
printf("Input error: No message for server");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (wolfSSL_write(ssl, sendBuff, strlen(sendBuff)) != strlen(sendBuff)) {
|
||||
/* the message is not able to send, or error trying */
|
||||
|
|
|
@ -240,7 +240,10 @@ int main(int argc, char** argv)
|
|||
/* Get a message for the server from stdin */
|
||||
printf("Message for server: ");
|
||||
memset(buff, 0, sizeof(buff));
|
||||
fgets(buff, sizeof(buff), stdin);
|
||||
if (fgets(buff, sizeof(buff), stdin) == NULL) {
|
||||
fprintf(stderr, "ERROR: failed to get message for server\n");
|
||||
return -1;
|
||||
}
|
||||
len = strnlen(buff, sizeof(buff));
|
||||
|
||||
/* Send the message to the server */
|
||||
|
|
|
@ -161,7 +161,10 @@ int main(int argc, char** argv)
|
|||
/* Get a message for the server from stdin */
|
||||
printf("Message for server: ");
|
||||
memset(buff, 0, sizeof(buff));
|
||||
fgets(buff, sizeof(buff), stdin);
|
||||
if (fgets(buff, sizeof(buff), stdin) == NULL) {
|
||||
fprintf(stderr, "ERROR: failed to get message for server\n");
|
||||
return -1;
|
||||
}
|
||||
len = strnlen(buff, sizeof(buff));
|
||||
|
||||
/* Send the message to the server */
|
||||
|
|
|
@ -150,7 +150,10 @@ int main(int argc, char** argv)
|
|||
/* Get a message for the server from stdin */
|
||||
printf("Message for server: ");
|
||||
memset(buff, 0, sizeof(buff));
|
||||
fgets(buff, sizeof(buff), stdin);
|
||||
if (fgets(buff, sizeof(buff), stdin) == NULL) {
|
||||
fprintf(stderr, "ERROR: failed to get message for server\n");
|
||||
return -1;
|
||||
}
|
||||
len = strnlen(buff, sizeof(buff));
|
||||
|
||||
/* Send the message to the server */
|
||||
|
|
|
@ -139,7 +139,10 @@ int main(int argc, char** argv)
|
|||
/* Get a message for the server from stdin */
|
||||
printf("Message for server: ");
|
||||
memset(buff, 0, sizeof(buff));
|
||||
fgets(buff, sizeof(buff), stdin);
|
||||
if (fgets(buff, sizeof(buff), stdin) == NULL) {
|
||||
fprintf(stderr, "ERROR: failed to to get message for server\n");
|
||||
return -1;
|
||||
}
|
||||
len = strnlen(buff, sizeof(buff));
|
||||
|
||||
/* Send the message to the server */
|
||||
|
@ -230,7 +233,10 @@ int main(int argc, char** argv)
|
|||
/* Get a message for the server from stdin */
|
||||
printf("Message for server: ");
|
||||
memset(buff, 0, sizeof(buff));
|
||||
fgets(buff, sizeof(buff), stdin);
|
||||
if (fgets(buff, sizeof(buff), stdin) == NULL) {
|
||||
fprintf(stderr, "ERROR: failed to get message for server\n");
|
||||
return -1;
|
||||
}
|
||||
len = strnlen(buff, sizeof(buff));
|
||||
|
||||
/* Send the message to the server */
|
||||
|
|
|
@ -136,7 +136,10 @@ int main(int argc, char** argv)
|
|||
/* Get a message for the server from stdin */
|
||||
printf("Message for server: ");
|
||||
memset(buff, 0, sizeof(buff));
|
||||
fgets(buff, sizeof(buff), stdin);
|
||||
if (fgets(buff, sizeof(buff), stdin) == NULL) {
|
||||
fprintf(stderr, "ERROR: failed to get message for server\n");
|
||||
return -1;
|
||||
}
|
||||
len = strnlen(buff, sizeof(buff));
|
||||
|
||||
/* Send the message to the server */
|
||||
|
|
Loading…
Reference in New Issue