summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Holland <samuel@sholland.org>2018-01-14 23:37:33 -0600
committerSamuel Holland <samuel@sholland.org>2018-01-15 00:43:49 -0600
commita6ab56ce62bc3c9fa4c63f2f13a3d5f3ea403f19 (patch)
tree397a1f643928870c64dd5ffbf5d267add0cca1da
parent8b7099b1e4ecca1357051142b589eaf24e29051c (diff)
downloadgcompat-a6ab56ce62bc3c9fa4c63f2f13a3d5f3ea403f19.tar.gz
gcompat-a6ab56ce62bc3c9fa4c63f2f13a3d5f3ea403f19.tar.bz2
gcompat-a6ab56ce62bc3c9fa4c63f2f13a3d5f3ea403f19.tar.xz
gcompat-a6ab56ce62bc3c9fa4c63f2f13a3d5f3ea403f19.zip
socket: Implement checked socket functions from LSB
Signed-off-by: Samuel Holland <samuel@sholland.org>
-rw-r--r--Makefile1
-rw-r--r--libgcompat/socket.c31
2 files changed, 32 insertions, 0 deletions
diff --git a/Makefile b/Makefile
index e377355..98f87ad 100644
--- a/Makefile
+++ b/Makefile
@@ -16,6 +16,7 @@ LIBGCOMPAT_SRC = \
libgcompat/resource.c \
libgcompat/setjmp.c \
libgcompat/signal.c \
+ libgcompat/socket.c \
libgcompat/stdio.c \
libgcompat/stdlib.c \
libgcompat/string.c \
diff --git a/libgcompat/socket.c b/libgcompat/socket.c
new file mode 100644
index 0000000..927ebe4
--- /dev/null
+++ b/libgcompat/socket.c
@@ -0,0 +1,31 @@
+#include <assert.h> /* assert */
+#include <stddef.h> /* NULL */
+#include <sys/socket.h> /* recv, recvfrom */
+
+/**
+ * Receive a message from a connected socket, with buffer overflow checking.
+ *
+ * LSB 5.0: LSB-Core-generic/baselib---recv-chk-1.html
+ */
+ssize_t __recv_chk(int fd, void *buf, size_t len, size_t buflen, int flags)
+{
+ assert(buf != NULL);
+ assert(buflen >= len);
+
+ return recv(fd, buf, len, flags);
+}
+
+/**
+ * Receive a message from a socket, with buffer overflow checking.
+ *
+ * LSB 5.0: LSB-Core-generic/baselib---recvfrom-chk-1.html
+ */
+ssize_t __recvfrom_chk(int fd, void *buf, size_t len, size_t buflen, int flags,
+ struct sockaddr *address, socklen_t *address_len)
+{
+ assert(buf != NULL);
+ assert(buflen >= len);
+ assert(address != NULL ? address_len != NULL : address_len == NULL);
+
+ return recvfrom(fd, buf, len, flags, address, address_len);
+}