Error checking for fgets to remove unused return warnings

pull/172/head
Aaron Jense 2019-10-30 10:59:46 -06:00
parent 0cde0ad3ec
commit ead4080e5b
10 changed files with 57 additions and 22 deletions

View File

@ -250,18 +250,21 @@ int NoEcho(char* key, int size)
nflags.c_lflag |= ECHONL; nflags.c_lflag |= ECHONL;
if (tcsetattr(fileno(stdin), TCSANOW, &nflags) != 0) { if (tcsetattr(fileno(stdin), TCSANOW, &nflags) != 0) {
printf("Error\n"); printf("Error: tcsetattr failed to disable terminal echo\n");
return -1060; return -1060;
} }
printf("Unique Password: "); 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; key[strlen(key) - 1] = 0;
/* restore terminal */ /* restore terminal */
if (tcsetattr(fileno(stdin), TCSANOW, &oflags) != 0) { if (tcsetattr(fileno(stdin), TCSANOW, &oflags) != 0) {
printf("Error\n"); printf("Error: tcsetattr failed to enable terminal echo\n");
return -1070; return -1080;
} }
return 0; return 0;
} }

View File

@ -249,18 +249,22 @@ int NoEcho(char* key, int size)
nflags.c_lflag |= ECHONL; nflags.c_lflag |= ECHONL;
if (tcsetattr(fileno(stdin), TCSANOW, &nflags) != 0) { if (tcsetattr(fileno(stdin), TCSANOW, &nflags) != 0) {
printf("Error\n"); printf("Error: tcsetattr failed to disable terminal echo\n");
return -1060; return -1060;
} }
printf("Unique Password: "); 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; key[strlen(key) - 1] = 0;
/* restore terminal */ /* restore terminal */
if (tcsetattr(fileno(stdin), TCSANOW, &oflags) != 0) { if (tcsetattr(fileno(stdin), TCSANOW, &oflags) != 0) {
printf("Error\n"); printf("Error: tcsetattr failed to enable terminal echo\n");
return -1070; return -1080;
} }
return 0; return 0;
} }

View File

@ -246,18 +246,22 @@ int NoEcho(char* key, int size)
nflags.c_lflag |= ECHONL; nflags.c_lflag |= ECHONL;
if (tcsetattr(fileno(stdin), TCSANOW, &nflags) != 0) { if (tcsetattr(fileno(stdin), TCSANOW, &nflags) != 0) {
printf("Error\n"); printf("Error: tcsetattr failed to disable terminal echo\n");
return -1060; return -1060;
} }
printf("Unique Password: "); 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; key[strlen(key) - 1] = 0;
/* restore terminal */ /* restore terminal */
if (tcsetattr(fileno(stdin), TCSANOW, &oflags) != 0) { if (tcsetattr(fileno(stdin), TCSANOW, &oflags) != 0) {
printf("Error\n"); printf("Error: tcsetattr failed to enable terminal echo\n");
return -1070; return -1080;
} }
return 0; return 0;
} }

View File

@ -88,7 +88,10 @@ int main(int argc, char** argv)
/* Get a message for the server from stdin */ /* Get a message for the server from stdin */
printf("Message for server: "); printf("Message for server: ");
memset(buff, 0, sizeof(buff)); 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)); len = strnlen(buff, sizeof(buff));
/* Send the message to the server */ /* Send the message to the server */

View File

@ -43,7 +43,10 @@ int ClientGreet(int sock, WOLFSSL* ssl)
int ret = 0; /* variable for error checking */ int ret = 0; /* variable for error checking */
printf("Message for server:\t"); 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)) { if (wolfSSL_write(ssl, sendBuff, strlen(sendBuff)) != strlen(sendBuff)) {
/* the message is not able to send, or error trying */ /* the message is not able to send, or error trying */

View File

@ -240,7 +240,10 @@ int main(int argc, char** argv)
/* Get a message for the server from stdin */ /* Get a message for the server from stdin */
printf("Message for server: "); printf("Message for server: ");
memset(buff, 0, sizeof(buff)); 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)); len = strnlen(buff, sizeof(buff));
/* Send the message to the server */ /* Send the message to the server */

View File

@ -161,7 +161,10 @@ int main(int argc, char** argv)
/* Get a message for the server from stdin */ /* Get a message for the server from stdin */
printf("Message for server: "); printf("Message for server: ");
memset(buff, 0, sizeof(buff)); 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)); len = strnlen(buff, sizeof(buff));
/* Send the message to the server */ /* Send the message to the server */

View File

@ -150,7 +150,10 @@ int main(int argc, char** argv)
/* Get a message for the server from stdin */ /* Get a message for the server from stdin */
printf("Message for server: "); printf("Message for server: ");
memset(buff, 0, sizeof(buff)); 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)); len = strnlen(buff, sizeof(buff));
/* Send the message to the server */ /* Send the message to the server */

View File

@ -139,7 +139,10 @@ int main(int argc, char** argv)
/* Get a message for the server from stdin */ /* Get a message for the server from stdin */
printf("Message for server: "); printf("Message for server: ");
memset(buff, 0, sizeof(buff)); 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)); len = strnlen(buff, sizeof(buff));
/* Send the message to the server */ /* Send the message to the server */
@ -230,7 +233,10 @@ int main(int argc, char** argv)
/* Get a message for the server from stdin */ /* Get a message for the server from stdin */
printf("Message for server: "); printf("Message for server: ");
memset(buff, 0, sizeof(buff)); 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)); len = strnlen(buff, sizeof(buff));
/* Send the message to the server */ /* Send the message to the server */

View File

@ -136,7 +136,10 @@ int main(int argc, char** argv)
/* Get a message for the server from stdin */ /* Get a message for the server from stdin */
printf("Message for server: "); printf("Message for server: ");
memset(buff, 0, sizeof(buff)); 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)); len = strnlen(buff, sizeof(buff));
/* Send the message to the server */ /* Send the message to the server */