nserver

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

commit 883bebb1b80bf3709bae9c7b46c184b0b992d7e0
parent f0814b28079775b4fcee2e79a82b5403f3452bd8
Author: rsiddharth <s@ricketyspace.net>
Date:   Thu, 28 Nov 2019 00:27:27 -0500

nserver: nserve.c: Update check_cmd_size.

* nserver/src/nserve.c (check_cmd_size): Update valid cmd size
constraint. If command size is zero; send close connection message.
* nserver/src/nserve.h (CMD_SIZE): Remove constant.
(CMD_MIN_SIZE, CMD_MAX_SIZE): New constants.

Diffstat:
nserver/src/nserve.c | 15++++++++++-----
nserver/src/nserve.h | 3++-
2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/nserver/src/nserve.c b/nserver/src/nserve.c @@ -45,14 +45,19 @@ int check_cmd_size(char *cmd, int sock) check(cmd != NULL, "cmd is NULL"); size_t len = strlen(cmd); - if (len <= CMD_SIZE) { + debug("cmd size $%s$ %ld\n", cmd, len); + if (len >= CMD_MIN_SIZE && len <= CMD_MAX_SIZE) { return 0; + } else if (len == 0) { + char *q = "closing connection\n"; + size_t bytes = barfsock(q, strlen(q), sock); + check(bytes == strlen(q), "send sock failed"); + } else { + char *err = "cmd size invalid\n"; + size_t bytes = barfsock(err, strlen(err), sock); + check(bytes == strlen(err), "send sock failed"); } - char *err = "error: command invalid: size > 120 characters\n"; - size_t bytes = barfsock(err, strlen(err), sock); - check(bytes == strlen(err), "check_cmd_size: send failed"); - return 1; error: return -1; diff --git a/nserver/src/nserve.h b/nserver/src/nserve.h @@ -10,7 +10,8 @@ #include <dbg.h> #include <ringbuffer.h> -#define CMD_SIZE 120 +#define CMD_MIN_SIZE 5 +#define CMD_MAX_SIZE 120 void nserve(int sock);