Commit a40c6b4 KCM: Use json_loadb() when dealing with sss_iobuf data

1 file Authored by fidencio 2 months ago , Committed by jhrozek 2 months ago ,
KCM: Use json_loadb() when dealing with sss_iobuf data

As sss_iobuf data is *non* NULL terminated, we have to use json_loadb()
passing the data's length instead of just using json_loads().

Due to this issue, when running sssd-kcm under valgrind and performing a
`kinit foo` a bunch of erros like the following one could be seen:
==2638== Conditional jump or move depends on uninitialised value(s)
==2638==    at 0x57DB678: stream_get.part.3 (load.c:172)
==2638==    by 0x57DB9CA: stream_get (load.c:643)
==2638==    by 0x57DB9CA: lex_get (load.c:246)
==2638==    by 0x57DB9CA: lex_scan (load.c:601)
==2638==    by 0x57DC56A: parse_json.constprop.7 (load.c:904)
==2638==    by 0x57DC6AB: json_loads (load.c:959)
==2638==    by 0x11ABEA: ??? (in /usr/libexec/sssd/sssd_kcm)
==2638==    by 0x11AEF0: ??? (in /usr/libexec/sssd/sssd_kcm)
==2638==    by 0x125D4A: ??? (in /usr/libexec/sssd/sssd_kcm)
==2638==    by 0x12623B: ??? (in /usr/libexec/sssd/sssd_kcm)
==2638==    by 0x9BCD71F: epoll_event_loop (tevent_epoll.c:728)
==2638==    by 0x9BCD71F: epoll_event_loop_once (tevent_epoll.c:930)
==2638==    by 0x9BCBBA6: std_event_loop_once (tevent_standard.c:114)
==2638==    by 0x9BC7FEC: _tevent_loop_once (tevent.c:725)
==2638==    by 0x9BC820A: tevent_common_loop_wait (tevent.c:848)

Related to:
https://pagure.io/SSSD/sssd/issue/3687

Signed-off-by: Fabiano FidĂȘncio <fidencio@redhat.com>

Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>

    
 1 @@ -231,6 +231,7 @@
 2   {
 3       json_t *root;
 4       uint8_t *sec_http_list;
 5 +     size_t sec_http_list_len;
 6       json_error_t error;
 7       json_t *element;
 8       errno_t ret;
 9 @@ -244,8 +245,10 @@
10           DEBUG(SSSDBG_CRIT_FAILURE, "No data in output buffer?\n");
11           return EINVAL;
12       }
13 +     sec_http_list_len = sss_iobuf_get_len(outbuf);
14   
15 -     root = json_loads((const char *) sec_http_list, 0, &error);
16 +     root = json_loadb((const char *) sec_http_list,
17 +                       sec_http_list_len, 0, &error);
18       if (root == NULL) {
19           DEBUG(SSSDBG_CRIT_FAILURE,
20                   "Failed to parse JSON payload on line %d: %s\n",