awslabs / amazon-kinesis-video-streams-webrtc-sdk-c

Amazon Kinesis Video Streams Webrtc SDK is for developers to install and customize realtime communication between devices and enable secure streaming of video, audio to Kinesis Video Streams.
https://awslabs.github.io/amazon-kinesis-video-streams-webrtc-sdk-c/group__PublicMemberFunctions.html
Apache License 2.0
1.03k stars 309 forks source link

[Bug]: kvsWebrtcClientMasterGstSample segfaults when attempting to use IoT Credentials #2050

Open MattCairns opened 1 month ago

MattCairns commented 1 month ago

Please confirm you have already done the following

Describe the bug

With IOT_CORE_ENABLE_CREDENTIALS set the samples crash with a segfault on aarch64 (Nvidia Jetson).

The following env variables are set:

export AWS_IOT_CORE_CREDENTIAL_ENDPOINT=xxxxx.credentials.iot.us-west-2.amazonaws.com
export AWS_IOT_CORE_CERT=/usr/local/etc/camera/certs/certificate.pem
export AWS_IOT_CORE_PRIVATE_KEY=/usr/local/etc/camera/certs/private.key
export AWS_KVS_CACERT_PATH=/usr/local/etc/camera/certs/webrtccacert.pem
export AWS_IOT_CORE_ROLE_ALIAS=IoTRole
export AWS_IOT_CORE_THING_NAME=test_channel
export AWS_DEFAULT_REGION=us-west-2

Expected Behavior

The samples do not segfault

Current Behavior

Verbose output:

[2024/08/29 18:33:17:2509] N: LWS: 4.2.1-v4.2.2, loglevel 7
[2024/08/29 18:33:17:2511] N: NET CLI H1 H2 WS ConMon IPv6-absent
[2024/08/29 18:33:17:2511] W: lws_create_context: LWS_WITHOUT_EXTENSIONS but extensions ptr set
[2024/08/29 18:33:17:2513] N:  ++ [wsi|0|pipe] (1)
[2024/08/29 18:33:17:2514] N:  ++ [vh|0|netlink] (1)
Segmentation fault

GDB Backtrace:

eng@jetson:~$ sudo -E gdb --args kvsWebrtcClientMasterGstSample testtest video-only testsrc
GNU gdb (Ubuntu 9.2-0ubuntu1~20.04.2) 9.2
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "aarch64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from kvsWebrtcClientMasterGstSample...
(No debugging symbols found in kvsWebrtcClientMasterGstSample)
(gdb) r
Starting program: /usr/local/bin/kvsWebrtcClientMasterGstSample testtest video-only testsrc
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/aarch64-linux-gnu/libthread_db.so.1".
[2024/08/29 17:38:56:4936] N: lws_create_context: LWS: 4.3.3-v4.3.3, NET CLI H1 H2 WS ConMon IPv6-absent
[2024/08/29 17:38:56:4938] W: lws_create_context: WITHOUT_EXTENSIONS but exts ptr set
[2024/08/29 17:38:56:4939] N: __lws_lc_tag:  ++ [wsi|0|pipe] (1)
[2024/08/29 17:38:56:4940] N: __lws_lc_tag:  ++ [vh|0|netlink] (1)

Program received signal SIGSEGV, Segmentation fault.
__strlen_generic () at ../sysdeps/aarch64/multiarch/../strlen.S:205
205     ../sysdeps/aarch64/multiarch/../strlen.S: No such file or directory.
(gdb) bt
#0  __strlen_generic () at ../sysdeps/aarch64/multiarch/../strlen.S:205
#1  0x0000fffff7b22674 in __vfprintf_internal
    (s=s@entry=0xffffffff9628, format=format@entry=0xaaaaaad77968 "|%s", ap=..., mode_flags=mode_flags@entry=2)
    at vfprintf-internal.c:1688
#2  0x0000fffff7b340a8 in __vsnprintf_internal
    (string=0xffffffff994f "|\034", maxlen=<optimized out>, format=0xaaaaaad77968 "|%s", args=..., mode_flags=2)
    at vsnprintf.c:114
#3  0x0000fffff7ba5a94 in ___vsnprintf_chk
   Python Exception <class 'gdb.MemoryError'> Cannot access memory at address 0x1041554455445500:
 (s=<optimized out>, maxlen=<optimized out>, flag=<optimized out>, slen=<optimized out>, format=<optimized out>, ap=#4  0x0000aaaaaab42bf8 in lws_snprintf ()
#5  0x0000aaaaaab4b470 in lws_create_vhost ()
#6  0x0000aaaaaab419e8 in lws_create_context ()
#7  0x0000aaaaaab35dd0 in blockingLwsCall ()
#8  0x0000aaaaaab33f58 in iotCurlHandler ()
#9  0x0000aaaaaab342a4 in createIotCredentialProviderWithTime ()
#10 0x0000aaaaaab352f4 in createLwsIotCredentialProviderWithTime ()
#11 0x0000aaaaaab35320 in createLwsIotCredentialProvider ()
#12 0x0000aaaaaaaf4a24 in createSampleConfiguration ()
#13 0x0000aaaaaaaf0084 in main ()

Reproduction Steps

Uncomment IOT_CORE_ENABLE_CREDENTIALS

diff --git a/samples/Samples.h b/samples/Samples.h
index 5b77ab9..315669c 100644
--- a/samples/Samples.h
+++ b/samples/Samples.h
@@ -65,7 +65,7 @@ extern "C" {
 #define IOT_CORE_CERTIFICATE_ID      ((PCHAR) "AWS_IOT_CORE_CERTIFICATE_ID")

 /* Uncomment the following line in order to enable IoT credentials checks in the provided samples */
-// #define IOT_CORE_ENABLE_CREDENTIALS  1
+#define IOT_CORE_ENABLE_CREDENTIALS  1

 #define MASTER_DATA_CHANNEL_MESSAGE "This message is from the KVS Master"
 #define VIEWER_DATA_CHANNEL_MESSAGE "This message is from the KVS Viewer"

Run with the required environment variables set for IoT Certificates.

WebRTC C SDK version being used

master, v1.10.2

Compiler and Version used

GCC 9.4.0

Operating System and version

Ubuntu 22.04

Platform being used

aarch64

sirknightj commented 1 week ago

Hi @MattCairns, could you try using the 1.10.3 branch?

The issue should be fixed in https://github.com/awslabs/amazon-kinesis-video-streams-pic/pull/229, which 1.10.3 should contain the fix.