From: Sung-hun Kim Date: Thu, 14 Dec 2023 01:49:34 +0000 (+0900) Subject: monitor: Add error handling codes X-Git-Tag: accepted/tizen/8.0/unified/20250108.155923~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8eaaa4e3e77947e78a8eb9b05808407e21789411;p=platform%2Fcore%2Fsystem%2Fpass.git monitor: Add error handling codes Since the request-handler code does not handle error cases, the pass daemon killed with segmentation fault. See the below gdb output: Program terminated with signal SIGSEGV, Segmentation fault. #0 handle_request (client=client@entry=0x7f680008d0, request=request@entry=0x7f72ffc270 "17") at /usr/src/debug/pass-2.0.0-1.aarch64/src/monitor/request-handler.c:877 877 /usr/src/debug/pass-2.0.0-1.aarch64/src/monitor/request-handler.c: No such file or directory. [Current thread is 1 (LWP 5465)] >>> bt #0 handle_request (client=client@entry=0x7f680008d0, request=request@entry=0x7f72ffc270 "17") at /usr/src/debug/pass-2.0.0-1.aarch64/src/monitor/request-handler.c:877 #1 0x000000558df6eda0 in request_handler_func (data=0x7f680008d0, result=) at /usr/src/debug/pass-2.0.0-1.aarch64/src/monitor/request-handler.c:1012 #2 0x000000558df5bb28 in __thread_loop_main (_ctx=0x7f68001170) at /usr/src/debug/pass-2.0.0-1.aarch64/src/util/thread.c:45 #3 0x0000007f833b882c in ?? () from /lib64/libpthread.so.0 #4 0x0000007f83319eac in thread_start () at ../sysdeps/unix/sysv/linux/aarch64/clone.S:78 I added an error handling code with NULL check for the variable `array`. Change-Id: I93bc4a23903c2c7d7fc9315d238d2c5addddc445 Signed-off-by: Sung-hun Kim --- diff --git a/src/monitor/request-handler.c b/src/monitor/request-handler.c index b05202c..182ac95 100644 --- a/src/monitor/request-handler.c +++ b/src/monitor/request-handler.c @@ -869,11 +869,21 @@ static int handle_request(struct request_client *client, char *request) break; case REQUEST_GET_VALUE_ARRAY: { - struct syscommon_resman_array_value *array; + struct syscommon_resman_array_value *array = NULL; int i; ret = handle_request_get_value_array(client, args, &array); + if (ret) + break; + + if (!array) { + /* A weird case, return value is zero but the array is NULL. + * Since it can make a segfault, just break out */ + _E("array is NULL"); + break; + } + if (array->length == 0) { ADD_RESPONSE(response, buffer_len, "%d|%d|$", array->type, array->length);