[PATCH] src: Print error and exit for empty string

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Print error message and exit. For e.g.

nft -c "  "
nft: no command specified

Without this patch, it segfaults.

Fixes: https://bugzilla.netfilter.org/show_bug.cgi?id=1215
Signed-off-by: Harsha Sharma <harshasharmaiitr@xxxxxxxxx>
---
 src/main.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/src/main.c b/src/main.c
index 353b87b..58de873 100644
--- a/src/main.c
+++ b/src/main.c
@@ -170,7 +170,7 @@ int main(int argc, char * const *argv)
 	bool interactive = false;
 	unsigned int debug_mask;
 	unsigned int len;
-	int i, val, rc;
+	int i, val, rc, nchar = 0;
 
 	nft = nft_ctx_new(NFT_CTX_DEFAULT);
 
@@ -271,6 +271,16 @@ int main(int argc, char * const *argv)
 				strcat(buf, " ");
 		}
 		strcat(buf, "\n");
+
+		for (unsigned int i = 0; i != strlen(buf); i++) {
+			if (buf[i] != ' ')
+				nchar++;
+		}
+
+		if (nchar < 2) {
+			fprintf(stderr, "%s: no command specified\n", argv[0]);
+			exit(EXIT_FAILURE);
+		}
 		rc = !!nft_run_cmd_from_buffer(nft, buf, len + 2);
 	} else if (filename != NULL) {
 		rc = !!nft_run_cmd_from_filename(nft, filename);
-- 
2.14.1

--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Netfitler Users]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux