nserver

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

commit f0814b28079775b4fcee2e79a82b5403f3452bd8
parent e38f0dbadd2e4fef15ecfbc746c29b42a478b65d
Author: rsiddharth <s@ricketyspace.net>
Date:   Thu, 28 Nov 2019 00:26:18 -0500

nserver: nserve.c: Add sanitize.

* nserver/src/nserve.c (sanitize): New function.

Diffstat:
nserver/src/nserve.c | 14++++++++++++++
1 file changed, 14 insertions(+), 0 deletions(-)

diff --git a/nserver/src/nserve.c b/nserver/src/nserve.c @@ -25,6 +25,20 @@ int barfsock(char *buf, size_t buf_sz, int sock) return -1; } +int sanitize(char *cmd) +{ + check(cmd != NULL, "cmd is NULL"); + + size_t len = strlen(cmd); + check(len > 0, "cmd empty"); + + // strip newline character at the end. + cmd[len - 1] = '\0'; + + return 0; + error: + return -1; +} int check_cmd_size(char *cmd, int sock) {