aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--LICENSE2
-rw-r--r--internal.h2
-rw-r--r--liberror-libc.h5
-rw-r--r--recv.c39
-rw-r--r--set_error_one_file.c2
5 files changed, 47 insertions, 3 deletions
diff --git a/LICENSE b/LICENSE
index c437151..f85dd82 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,6 +1,6 @@
ISC License
-© 2019 Mattias Andrée <maandree@kth.se>
+© 2019, 2021 Mattias Andrée <maandree@kth.se>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
diff --git a/internal.h b/internal.h
index 9f1119a..9bc9a26 100644
--- a/internal.h
+++ b/internal.h
@@ -23,4 +23,4 @@
#define HIDDEN GCC_ATTRIBUTES(__visibility__("hidden"))
-HIDDEN void liberror_libc_set_error_one_file(const char[256], const char[64], const char *, int, const char *);
+HIDDEN void liberror_libc_set_error_one_file(const char *, const char *, const char *, int, const char *);
diff --git a/liberror-libc.h b/liberror-libc.h
index 9a67245..3ca2b67 100644
--- a/liberror-libc.h
+++ b/liberror-libc.h
@@ -7,6 +7,9 @@
#include <unistd.h>
+#define LIBERROR_LIBC_ERRROR_SHORT_READ -1
+
+
int liberror_abs(int);
void liberror_abs_failed(int);
/* void *liberror_aligned_alloc(size_t, size_t); TODO */
@@ -31,7 +34,9 @@ void liberror_raise_failed(int);
void *liberror_realloc(void *, size_t);
void liberror_realloc_failed(void *, size_t);
ssize_t liberror_recv(int, void *, size_t, int, const char *);
+ssize_t liberror_recv_require(int, void *, size_t, int, size_t min, size_t max, const char *);
void liberror_recv_failed(int, void *, size_t, int, const char *);
+void liberror_recv_short(int, void *, size_t, int, size_t min, size_t max, ssize_t returned, const char *);
/* void *liberror_posix_memalign(void **, size_t, size_t); TODO */
ssize_t liberror_send(int, const void *, size_t, int, const char *);
void liberror_send_failed(int, const void *, size_t, int, const char *);
diff --git a/recv.c b/recv.c
index 03985ba..549a9f2 100644
--- a/recv.c
+++ b/recv.c
@@ -112,6 +112,30 @@ liberror_recv_failed(int fd, void *buf, size_t n, int flags, const char *fname)
}
+void
+liberror_recv_short(int fd, void *buf, size_t n, int flags, size_t min, size_t max, ssize_t returned, const char *fname)
+{
+ const char *desc;
+ struct liberror_error *error;
+ int saved_errno = errno;
+ liberror_save_backtrace(NULL);
+ if (returned < 0 || (size_t)returned < min) {
+ desc = "Received message was shorter than expected";
+ } else if (returned > max) {
+ desc = "Received message was larger than expected";
+ } else {
+ desc = "Received message was of an unexpected size";
+ }
+ liberror_set_error(desc, "recv", "liberror-libc", LIBERROR_LIBC_ERRROR_SHORT_READ);
+ error = liberror_get_error();
+ error->details_type = LIBERROR_DETAILS_ONE_FILE;
+ error->details.one_file.fd = fd;
+ error->details.one_file.name = fname ? strdup(fname) : NULL;
+ error->details.one_file.role = "Socket file";
+ errno = saved_errno;
+}
+
+
ssize_t
liberror_recv(int fd, void *buf, size_t n, int flags, const char *fname)
{
@@ -122,3 +146,18 @@ liberror_recv(int fd, void *buf, size_t n, int flags, const char *fname)
liberror_recv_failed(fd, buf, n, flags, fname);
return -1;
}
+
+
+ssize_t
+liberror_recv_require(int fd, void *buf, size_t n, int flags, size_t min, size_t max, const char *fname)
+{
+ ssize_t r = recv(fd, buf, n, flags);
+ if (r >= min && r <= max)
+ return r;
+ liberror_save_backtrace(NULL);
+ if (r < 0)
+ liberror_recv_failed(fd, buf, n, flags, fname);
+ else
+ liberror_recv_short(fd, buf, n, flags, min, max, r, fname);
+ return -1;
+}
diff --git a/set_error_one_file.c b/set_error_one_file.c
index b9b46d1..04fef36 100644
--- a/set_error_one_file.c
+++ b/set_error_one_file.c
@@ -3,7 +3,7 @@
void
-liberror_libc_set_error_one_file(const char desc[256], const char source[64], const char *frole, int fd, const char *fname)
+liberror_libc_set_error_one_file(const char *desc, const char *source, const char *frole, int fd, const char *fname)
{
struct liberror_error *error;
int saved_errno = errno;