From 67b720f4511e90c8badbeda6486d5c0521b7ad9e Mon Sep 17 00:00:00 2001 From: Shuhei Matsumoto Date: Wed, 23 Jan 2019 10:01:26 +0900 Subject: [PATCH] examples/sock: Improve error check of input parsing by spdk_strtol Change-Id: I2757d83344e6a3b78b18b3d3678776e84dc26614 Signed-off-by: Shuhei Matsumoto Reviewed-on: https://review.gerrithub.io/c/441637 Tested-by: SPDK CI Jenkins Reviewed-by: Darek Stojaczyk Reviewed-by: wuzhouhui Reviewed-by: Ben Walker Reviewed-by: Changpeng Liu --- examples/sock/hello_world/hello_sock.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/examples/sock/hello_world/hello_sock.c b/examples/sock/hello_world/hello_sock.c index b21412d44..db4811825 100644 --- a/examples/sock/hello_world/hello_sock.c +++ b/examples/sock/hello_world/hello_sock.c @@ -98,7 +98,11 @@ static int hello_sock_parse_arg(int ch, char *arg) g_host = arg; break; case 'P': - g_port = atoi(arg); + g_port = spdk_strtol(arg, 10); + if (g_port < 0) { + fprintf(stderr, "Invalid port ID\n"); + return g_port; + } break; case 'S': g_is_server = 1;