UNCLASSIFIED

Skip to content
Snippets Groups Projects
Commit 88ea8707 authored by Andrew Parker's avatar Andrew Parker
Browse files

add missing error checking

parent e4520fcb
No related merge requests found
......@@ -99,6 +99,8 @@ send_file(int sockfd, FILE *fp, size_t fsize)
size_t to_send = 0;
char * tmp = NULL;
errno = 0; // reset errno
// check value of tmp to ensure calloc worked as expected
tmp = calloc(MAX_MSG_SIZE, sizeof(char));
if (NULL == tmp)
......@@ -113,6 +115,11 @@ send_file(int sockfd, FILE *fp, size_t fsize)
{
to_send = fread(tmp, sizeof(char), MAX_MSG_SIZE, fp);
bytes_sent += send(sockfd, tmp, to_send, 0);
if (0 != errno)
{
perror("Error Sending File");
goto CLEANUP;
}
DEBUG_PRINT(("Send %ld bytes\n", bytes_sent));
memset(tmp, 0, MAX_MSG_SIZE); // NOLINT memset is fine, shut up - Drew
if (0 == to_send)
......@@ -189,7 +196,11 @@ interactive_send(void *sockfd)
if (fds[0].revents)
{
to_send = read(STDIN_FILENO, tmp, MAX_MSG_SIZE);
send(sfd, tmp, to_send, 0);
if (0 > send(sfd, tmp, to_send, 0))
{
fprintf(stderr, "Broken Pipe; Stopping\n");
running = false;
}
}
}
......@@ -301,7 +312,7 @@ client(char *destination, char *port, char const *filename, bool inter_con)
if (in_st.st_size != bytes_sent)
{
fprintf(stderr,
"Failed to send full file; send %ld bytes\n",
"Failed to send full file; sent %ld bytes\n",
bytes_sent);
did_error = true;
goto CLEANUP;
......
......@@ -82,7 +82,10 @@ main(int argc, char **argv)
}
// convert number for bounds checking purposes
convert_num(port, &port_num);
if (false == convert_num(port, &port_num))
{
goto INVALID_ARGS;
}
// UINT16_MAX is largest possible port (2^16-1)
if ((NULL == destination) || (UINT16_MAX < port_num) || (0 == port_num))
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment