lib/sdp.c: Validate attribute search return value
authorAravind Machiry <machiry@cs.ucsb.edu>
Mon, 28 Sep 2020 06:44:46 +0000 (23:44 -0700)
committerAyush Garg <ayush.garg@samsung.com>
Fri, 11 Mar 2022 13:38:33 +0000 (19:08 +0530)
The calls to gen_[searchseq|attridseq]_seq functions return negative
value on failure. The return value should be checked to gracefully
exit with a proper exit code.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
lib/sdp.c

index 532039a..a27cd3a 100755 (executable)
--- a/lib/sdp.c
+++ b/lib/sdp.c
@@ -3419,6 +3419,12 @@ int sdp_service_search_req(sdp_session_t *session, const sdp_list_t *search,
        /* add service class IDs for search */
        seqlen = gen_searchseq_pdu(pdata, search);
 
+       if (seqlen < 0) {
+               errno = EINVAL;
+               status = -1;
+               goto end;
+       }
+
        SDPDBG("Data seq added : %d", seqlen);
 
        /* set the length and increment the pointer */
@@ -3841,6 +3847,11 @@ int sdp_service_search_async(sdp_session_t *session, const sdp_list_t *search, u
        /* add service class IDs for search */
        seqlen = gen_searchseq_pdu(pdata, search);
 
+       if (seqlen < 0) {
+               t->err = EINVAL;
+               goto end;
+       }
+
        SDPDBG("Data seq added : %d", seqlen);
 
        /* now set the length and increment the pointer */
@@ -4054,6 +4065,11 @@ int sdp_service_search_attr_async(sdp_session_t *session, const sdp_list_t *sear
        /* add service class IDs for search */
        seqlen = gen_searchseq_pdu(pdata, search);
 
+       if (seqlen < 0) {
+               t->err = EINVAL;
+               goto end;
+       }
+
        SDPDBG("Data seq added : %d", seqlen);
 
        /* now set the length and increment the pointer */