nserver

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | LICENSE

commit 9a1bac7fc8ecbc2c47b72a9df4b72dfabfe058bd
parent 651f8a9ea23498d5adde77b89d94d85f654672b4
Author: rsiddharth <s@ricketyspace.net>
Date:   Thu, 21 Nov 2019 21:11:51 -0500

nserve: Add check_cmd_size.

* nserver/src/nserve.c (check_cmd_size): New function.
* nserver/src/nserve.h (CMD_SIZE): New constant.

Diffstat:
nserver/src/nserve.c | 19+++++++++++++++++++
nserver/src/nserve.h | 3+++
2 files changed, 22 insertions(+), 0 deletions(-)

diff --git a/nserver/src/nserve.c b/nserver/src/nserve.c @@ -25,6 +25,25 @@ int barfsock(char *buf, size_t buf_sz, int sock) return -1; } + +int check_cmd_size(char *cmd, int sock) +{ + check(cmd != NULL, "cmd is NULL"); + + size_t len = strlen(cmd); + if (len <= CMD_SIZE) { + return 0; + } + + char *err = "error: command invalid: size > 120 characters\n"; + send(sock, err, strlen(err), 0); + + return 1; + error: + return -1; +} + + void nserve(int sock) { size_t buf_sz = 200; diff --git a/nserver/src/nserve.h b/nserver/src/nserve.h @@ -2,6 +2,7 @@ #define _nserve_h #include <stdlib.h> +#include <string.h> #include <unistd.h> #include <sys/socket.h> @@ -9,6 +10,8 @@ #include <dbg.h> #include <ringbuffer.h> +#define CMD_SIZE 120 + void nserve(int sock); #endif