aws / aws-iot-device-sdk-embedded-C

SDK for connecting to AWS IoT from a device using embedded C.
MIT License
978 stars 624 forks source link

Crash on shadow delta callback #17

Closed revmischa closed 8 years ago

revmischa commented 8 years ago
Process 76876 stopped
* thread #1: tid = 0x2853f7, 0x00007fff89f5f152 libsystem_c.dylib`strlen + 18, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x843d0)
    frame #0: 0x00007fff89f5f152 libsystem_c.dylib`strlen + 18
libsystem_c.dylib`strlen:
->  0x7fff89f5f152 <+18>: pcmpeqb (%rdi), %xmm0
    0x7fff89f5f156 <+22>: pmovmskb %xmm0, %esi
    0x7fff89f5f15a <+26>: andq   $0xf, %rcx
    0x7fff89f5f15e <+30>: orq    $-0x1, %rax
(lldb) bt
* thread #1: tid = 0x2853f7, 0x00007fff89f5f152 libsystem_c.dylib`strlen + 18, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x843d0)
  * frame #0: 0x00007fff89f5f152 libsystem_c.dylib`strlen + 18
    frame #1: 0x000000010007dbba cloudcam`jsoneq(json="{\"version\":82,\"timestamp\":1461818894,\"state\":{\"upload_endpoint\":{\"url\":\"[blah blah]/\",\"fields\":{\"policy\":\"[blah blah]\",\"x-amz-security-token\":\"[blah blah]"..., tok=0x00000001000a4550, s="") + 42 at aws_iot_json_utils.c:35
    frame #2: 0x0000000100081bff cloudcam`isJsonKeyMatchingAndUpdateValue(pJsonDocument="{\"version\":82,\"timestamp\":1461818894,\"state\":{\"upload_endpoint\":{\"url\":\"[blah blah]/\",\"fields\":{\"policy\":\"[blah blah]....\",\"AWSAccessKeyId\":\"[blah blah]\",\"x-amz-security-token\":\"[blah blah]"..., pJsonHandler=0x0000000000000000, tokenCount=59, pDataStruct=0x00007fff5fbfe968, pDataLength=0x00007fff5fbfe6d0, pDataPosition=0x00007fff5fbfe6d4) + 95 at aws_iot_shadow_json.c:371
    frame #3: 0x000000010008262e cloudcam`shadow_delta_callback(params=MQTTCallbackParams @ 0x00007fff5fbfe700) + 558 at aws_iot_shadow_records.c:475
    frame #4: 0x000000010007c82e cloudcam`pahoMessageCallback(md=0x00007fff5fbfe780) + 270 at aws_iot_mqtt_embedded_client_wrapper.c:101
    frame #5: 0x000000010000539a cloudcam`deliverMessage(c=0x00000001000a13f8, topicName=0x00007fff5fbfe828, message=0x00007fff5fbfe810) + 330 at MQTTClient.c:277
    frame #6: 0x0000000100005f2d cloudcam`handlePublish(c=0x00000001000a13f8, timer=0x00007fff5fbfe8d8) + 189 at MQTTClient.c:433
    frame #7: 0x00000001000061c2 cloudcam`cycle(c=0x00000001000a13f8, timer=0x00007fff5fbfe8d8, packet_type="\x03\x14\x96!W") + 194 at MQTTClient.c:510

Using v1.1.2. Code is at https://github.com/revmischa/cloudcam/tree/master/src

chaurah commented 8 years ago

Hi revmischa, Could you give me some more information about how this issue happened? Can I simply build and run your code and it will crash? I tried that and I did not get any errors so I might be missing a step somewhere. Also, I would recommend you do not upload your root CA certificate and config file with endpoint to a public github repo. The endpoint is specific to your account and should not be shared. Anyone who wants to use your code should provide his/her endpoint and certificates.

Rahul

revmischa commented 8 years ago

The root CA is the same for everyone isn't it? Fixed my crash today: https://github.com/revmischa/cloudcam/commit/d3300c539ff4d3b795a6f1c7cce0dd39c0746be9 It is a little unexpected that you need to keep the struct passed to aws_iot_shadow_register_delta around. If you let it deallocate then it crashes on the callback. This should probably at least be mentioned in the documentation.

chaurah commented 8 years ago

It doesn't need to be. We support creating your own certificates as well for example. That sounds like a good recommendation to add to the documentation. As a general rule, the Embedded C SDK doesn't do any dynamic memory allocation. So any data that is passed in will need to be retained on the application side as well as long as it is expected to be used. I will look into making this clearer in the documentation for the next release. But am glad to hear that you found the issue :) Please let us know if you have any other questions. Thank you for using AWS IoT.

Rahul