diff options
author | Sung-hun Kim <sfoon.kim@samsung.com> | 2023-12-14 10:49:34 +0900 |
---|---|---|
committer | Sung-hun Kim <sfoon.kim@samsung.com> | 2023-12-14 11:58:58 +0900 |
commit | a4b7210e99dd65501e70203144cf34e08e7e7d56 (patch) | |
tree | ad4ab24b5a8527ae9c211b9a47c125a604fff51b | |
parent | fd99f701e288e8240939b152ac340981c15f1143 (diff) | |
download | pass-a4b7210e99dd65501e70203144cf34e08e7e7d56.tar.gz pass-a4b7210e99dd65501e70203144cf34e08e7e7d56.tar.bz2 pass-a4b7210e99dd65501e70203144cf34e08e7e7d56.zip |
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=<optimized out>) 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 <sfoon.kim@samsung.com>
-rw-r--r-- | src/monitor/request-handler.c | 12 |
1 files changed, 11 insertions, 1 deletions
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); |