nserver

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

commit 66377d4496381cf5e0f942023414f08b70019ecd
parent 495a6aff9251d5dc059c2ce1363ecbe10f3ae7a4
Author: rsiddharth <s@ricketyspace.net>
Date:   Thu, 28 Nov 2019 02:18:39 -0500

nserver: ncmd.c: Updat sanitize.

* nserver/src/ncmd.c (sanitize): Replace the first '\n' with '\0'
instead of the last.

Diffstat:
nserver/src/ncmd.c | 11++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/nserver/src/ncmd.c b/nserver/src/ncmd.c @@ -4,12 +4,17 @@ int sanitize(char *cmd) { check(cmd != NULL, "cmd is NULL"); - size_t len = strlen(cmd); + int len = strlen(cmd); check(len > 0, "cmd empty"); - // strip newline character at the end. - cmd[len - 1] = '\0'; + // replace newline character with NUL. + for (int i = 0; i < len; i++) { + if (cmd[i] == '\n') { + cmd[i] = '\0'; + break; + } + } return 0; error: return -1;