diff --git a/common/simple_auth.c b/common/simple_auth.c index f724111..a67e397 100644 --- a/common/simple_auth.c +++ b/common/simple_auth.c @@ -260,9 +260,15 @@ sha_challenge(int fd, fence_auth_type_t auth, void *key, return 0; } - if (read(fd, response, sizeof(response)) < sizeof(response)) { + ret = read(fd, response, sizeof(response)); + if (ret < 0) { perror("read"); return 0; + } else if (ret < sizeof(response)) { + fprintf(stderr, + "read data from socket is too short(actual: %d, expected: %lu)\n", + ret, sizeof(response)); + return 0; } ret = !memcmp(response, hash, sizeof(response)); @@ -291,6 +297,7 @@ sha_response(int fd, fence_auth_type_t auth, void *key, HASHContext *h; HASH_HashType ht; unsigned int rlen; + int ret; FD_ZERO(&rfds); FD_SET(fd, &rfds); @@ -332,9 +339,16 @@ sha_response(int fd, fence_auth_type_t auth, void *key, HASH_End(h, hash, &rlen, sizeof(hash)); HASH_Destroy(h); - if (write(fd, hash, sizeof(hash)) < sizeof(hash)) { + ret = write(fd, hash, sizeof(hash)); + if (ret < 0) { perror("write"); return 0; + } else if (ret < sizeof(hash)) { + fprintf(stderr, + "Only part of hash is written(actual: %d, expected: %lu)\n", + ret, + sizeof(hash)); + return 0; } return 1;