Skip to content
Snippets Groups Projects
Commit d20a9afc authored by Benedikt Steinbusch's avatar Benedikt Steinbusch
Browse files

fix out of bounds exception on 0 length pread and pwrite messages

parent 599587ba
Branches
Tags
No related merge requests found
Pipeline #59540 passed
...@@ -12,4 +12,8 @@ ...@@ -12,4 +12,8 @@
- `boost::variant` has been replaced by `std::variant` and Boost is no longer needed as a dependency - `boost::variant` has been replaced by `std::variant` and Boost is no longer needed as a dependency
- If no explicit choice is made via `CMAKE_POSITION_INDEPENDENT_CODE`, the client library defaults to being built as position independent code - If no explicit choice is made via `CMAKE_POSITION_INDEPENDENT_CODE`, the client library defaults to being built as position independent code
### Fixed
- Pread and pwrite messages of length 0 were handled incorrectly by the server, leading to an out of bounds exception
[Unreleased]: https://gitlab.version.fz-juelich.de/SIONlib/SIONfwd/-/compare/v1.0.0...main [Unreleased]: https://gitlab.version.fz-juelich.de/SIONlib/SIONfwd/-/compare/v1.0.0...main
...@@ -362,7 +362,7 @@ struct CommunicatorReceiver { ...@@ -362,7 +362,7 @@ struct CommunicatorReceiver {
std::vector<char> buf = (args.nbyte() > 0) ? communicator_.receive_data(args.nbyte()) : std::vector<char>{}; std::vector<char> buf = (args.nbyte() > 0) ? communicator_.receive_data(args.nbyte()) : std::vector<char>{};
ssize_t written = 0; ssize_t written = 0;
while (true) { while (true) {
ssize_t k = pwrite(args.fd(), &buf.at(written), args.nbyte() - written, args.offset() + written); ssize_t k = pwrite(args.fd(), (args.nbyte() > 0) ? &buf.at(written) : nullptr, args.nbyte() - written, args.offset() + written);
if (k == -1) { if (k == -1) {
if (errno != EINTR) { if (errno != EINTR) {
written = -1; written = -1;
...@@ -385,7 +385,7 @@ struct CommunicatorReceiver { ...@@ -385,7 +385,7 @@ struct CommunicatorReceiver {
std::vector<char> buf(args.nbyte()); std::vector<char> buf(args.nbyte());
ssize_t read = 0; ssize_t read = 0;
while (true) { while (true) {
ssize_t k = pread(args.fd(), &buf.at(read), args.nbyte() - read, args.offset() + read); ssize_t k = pread(args.fd(), (args.nbyte() > 0) ? &buf.at(read) : nullptr, args.nbyte() - read, args.offset() + read);
if (k == -1) { if (k == -1) {
if (errno != EINTR) { if (errno != EINTR) {
read = -1; read = -1;
......
...@@ -26,6 +26,10 @@ int main(int argc, char *argv[]) { ...@@ -26,6 +26,10 @@ int main(int argc, char *argv[]) {
fprintf(stderr, "wrote %" PRId64 " bytes to %d\n", written, fd); fprintf(stderr, "wrote %" PRId64 " bytes to %d\n", written, fd);
assert(written == strlen(wbuf)); assert(written == strlen(wbuf));
written = sionfwd_pwrite(fd, wbuf, 0, 0);
fprintf(stderr, "wrote %" PRId64 " bytes to %d\n", written, fd);
assert(written == 0);
int status = sionfwd_flush(fd); int status = sionfwd_flush(fd);
fprintf(stderr, "flushed file descriptor %d\n", fd); fprintf(stderr, "flushed file descriptor %d\n", fd);
assert(status == 0); assert(status == 0);
...@@ -51,6 +55,10 @@ int main(int argc, char *argv[]) { ...@@ -51,6 +55,10 @@ int main(int argc, char *argv[]) {
assert(read == strlen(wbuf)); assert(read == strlen(wbuf));
assert(strcmp(wbuf, rbuf) == 0); assert(strcmp(wbuf, rbuf) == 0);
read = sionfwd_pread(fd, rbuf, 0, 0);
fprintf(stderr, "read %" PRId64 " bytes from %d\n", read, fd);
assert(read == 0);
status = sionfwd_close(fd); status = sionfwd_close(fd);
fprintf(stderr, "closed file descriptor %d with status %d\n", fd, status); fprintf(stderr, "closed file descriptor %d with status %d\n", fd, status);
assert(status == 0); assert(status == 0);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment