Seg fault on C example

I’m trying to run this example but I’m getting a segmentation fault, as per the trace below. This example was compiled with the C-SDK from github. The config file is a json created based on this answer, and looks like this:

{"protocol":"tcp", "address":"httpbin.org","port":80}

Best,

valgrind ./host server config.json host  
==151202== Memcheck, a memory error detector
==151202== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==151202== Using Valgrind-3.19.0 and LibVEX; rerun with -h for copyright info
==151202== Command: ./host server config.json host
==151202== 
Running as server
==151202== Invalid read of size 1
==151202==    at 0x484BD06: strlen (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==151202==    by 0x4A12D51: strdup (strdup.c:41)
==151202==    by 0x48BCFA6: ziti_init_opts (in /usr/lib/libziti.so)
==151202==    by 0x48BE1BB: ziti_init (in /usr/lib/libziti.so)
==151202==    by 0x109CDE: main (in /home/fernando/Documents/vortex/ziti/host)
==151202==  Address 0x0 is not stack'd, malloc'd or (recently) free'd
==151202== 
==151202== 
==151202== Process terminating with default action of signal 11 (SIGSEGV): dumping core
==151202==  Access not within mapped region at address 0x0
==151202==    at 0x484BD06: strlen (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==151202==    by 0x4A12D51: strdup (strdup.c:41)
==151202==    by 0x48BCFA6: ziti_init_opts (in /usr/lib/libziti.so)
==151202==    by 0x48BE1BB: ziti_init (in /usr/lib/libziti.so)
==151202==    by 0x109CDE: main (in /home/fernando/Documents/vortex/ziti/host)
==151202==  If you believe this happened as a result of a stack
==151202==  overflow in your program's main thread (unlikely but
==151202==  possible), you can try to increase the size of the
==151202==  main thread stack using the --main-stacksize= flag.
==151202==  The main thread stack size used in this run was 8388608.
==151202== 
==151202== HEAP SUMMARY:
==151202==     in use at exit: 1,304 bytes in 4 blocks
==151202==   total heap usage: 8 allocs, 4 frees, 11,046 bytes allocated
==151202== 
==151202== LEAK SUMMARY:
==151202==    definitely lost: 0 bytes in 0 blocks
==151202==    indirectly lost: 0 bytes in 0 blocks
==151202==      possibly lost: 0 bytes in 0 blocks
==151202==    still reachable: 1,304 bytes in 4 blocks
==151202==         suppressed: 0 bytes in 0 blocks
==151202== Rerun with --leak-check=full to see details of leaked memory
==151202== 
==151202== For lists of detected and suppressed errors, rerun with: -s
==151202== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
[1]    151202 segmentation fault (core dumped)  valgrind ./host server config.json host

Hello and thanks for bringing this issue to our attention!

I think there are a couple of things going on here. The primary issue is that the “config file” that is passed to the host sample program needs to be an identity json file that you’d get from enrolling an identity JWT. You are providing a service config (which would be used when creating the service).

Our code should not segfault when an invalid identity config is provided, so we’ve make an issue to address that. In the meantime can you try supplying an enrolled identity json file?

Where/how can I find/create such JWT config file?

We really need a “here is what you need to do to get started” for application embedded users. I added one for “tunneling based solutions” here Your First Service - Zero Trust Host Access | Ziti which might be helpful for you.

Basically it comes down to using the ziti cli (or ZAC) to make a new identity and then enroll that identity with a tool (like ziti CLI) or with the SDK (C in this case) itself.

Make the Identity with ZAC/ziti CLI:
ziti edge create identity user myFirstIdentity -o my.jwt

Enroll using the CSDK sample which you can find at ziti-sdk-c/tree/main/programs/sample_enroll

Hopefully that helps

1 Like