# SIGSEGV in fdb\_run\_network()

**URL:** <https://forums.foundationdb.org/t/sigsegv-in-fdb-run-network/3716>\
**Category:** Using FoundationDB\
**Created:** [January 3, 2023, 8:09am UTC](https://forums.foundationdb.org/t/sigsegv-in-fdb-run-network/3716 "2023-01-03T08:09:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mdianjun](https://sea1.discourse-cdn.com/foundationdb/user_avatar/forums.foundationdb.org/mdianjun/32/1456_2.png) [@mdianjun](https://forums.foundationdb.org/u/mdianjun)\
**Post date:** [January 3, 2023, 8:09am UTC](https://forums.foundationdb.org/t/sigsegv-in-fdb-run-network/3716/1 "2023-01-03T08:09:57Z")

</div>

I encountered a SIGSEGV error when calling fdb\_run\_network(), the stack is as follows:

```auto
Program terminated with signal SIGSEGV, Segmentation fault.
#0 __GI_getenv (name=0x7f14dfc58ff0 "B_TLS_CERTIFICATE_FILE") at getenv.c:84
84 getenv.c: No such file or directory.
[Current thread is 1 (Thread 0x7f14cc876700 (LWP 28214))]
(gdb) bt
#0 __GI_getenv (name=0x7f14dfc58ff0 "B_TLS_CERTIFICATE_FILE") at getenv.c:84
#1 0x00007f14df84b723 in fdb_transaction_set_option () from /lib/libfdb_c.so
#2 0x00007f14df86a3a0 in fdb_transaction_set_option () from /lib/libfdb_c.so
#3 0x00007f14df86d00c in fdb_transaction_set_option () from /lib/libfdb_c.so
#4 0x00007f14df813a04 in fdb_transaction_set_option () from /lib/libfdb_c.so
#5 0x00007f14df2785de in fdb_transaction_set_option () from /lib/libfdb_c.so
#6 0x00007f14df6c3228 in fdb_transaction_set_option () from /lib/libfdb_c.so
#7 0x00007f14df6c336b in fdb_transaction_set_option () from /lib/libfdb_c.so
#8 0x00007f14df5f34d0 in fdb_transaction_set_option () from /lib/libfdb_c.so
#9 0x00007f14df81257e in fdb_transaction_set_option () from /lib/libfdb_c.so
#10 0x00007f14df151ef2 in fdb_transaction_set_option () from /lib/libfdb_c.so
#11 0x00007f14df6bbbcf in fdb_transaction_set_option () from /lib/libfdb_c.so
#12 0x00007f14df109b32 in fdb_transaction_set_option () from /lib/libfdb_c.so
#13 0x00007f14df0e5089 in fdb_run_network () from /lib/libfdb_c.so
#14 0x0000559993b248d5 in runFdbNetwork ()
#15 0x00007f14de0a7609 in start_thread (arg=<optimized out>) at pthread_create.c:477
#16 0x00007f14dd5b8133 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

```

There is a fdb parameter `FDB_TLS_CERTIFICATE_FILE`, but the stack shows `B_TLS_CERTIFICATE_FILE`.

I referred to this issue [Issues · grpc/grpc · GitHub](https://github.com/grpc/grpc/issues/21990:)

> it was a buffer overflow of the output variable.

Please give me some suggestions, thanks!

---

<div class="post-metadata">

**Author:** ![mdianjun](https://sea1.discourse-cdn.com/foundationdb/user_avatar/forums.foundationdb.org/mdianjun/32/1456_2.png) [@mdianjun](https://forums.foundationdb.org/u/mdianjun)\
**Post date:** [March 22, 2023, 7:30am UTC](https://forums.foundationdb.org/t/sigsegv-in-fdb-run-network/3716/4 "2023-03-22T07:30:07Z")

</div>

> <https://github.com/grpc/grpc/issues/21990>
>
> Hello All,
> I am seeing this seg fault, I have modified the existing example pro…gram and below is the details of my pgm and the proto file.
> Can you let me know what is the issue here? what am I doing wrong.
> 
> BT
> 
> \`\`\`
> Thread 1 "mytest\_async\_clie" received signal SIGSEGV, Segmentation fault.
> \_\_GI\_getenv (name=0x7ffff570eac1 "CALDOMAIN") at getenv.c:84
> 84	getenv.c: No such file or directory.
> (gdb) where
> \#0 \_\_GI\_getenv (name=0x7ffff570eac1 "CALDOMAIN") at getenv.c:84
> \#1 0x00007ffff5706614 in ares\_init\_options () from /root/grpc/install/lib/libcares.so.2
> \#2 0x00007ffff78a42a7 in grpc\_ares\_ev\_driver\_create\_locked(grpc\_ares\_ev\_driver\*\*, grpc\_pollset\_set\*, int, grpc\_core::Combiner\*, grpc\_ares\_request\*) () from /root/grpc/install/lib/libgrpc.so.9
> \#3 0x00007ffff78a54b4 in grpc\_dns\_lookup\_ares\_continue\_after\_check\_localhost\_and\_ip\_literals\_locked(grpc\_ares\_request\*, char const\*, char const\*, char const\*, grpc\_pollset\_set\*, int, grpc\_core::Combiner\*) ()
> from /root/grpc/install/lib/libgrpc.so.9
> \#4 0x00007ffff78a602f in ?? () from /root/grpc/install/lib/libgrpc.so.9
> \#5 0x00007ffff78a2179 in ?? () from /root/grpc/install/lib/libgrpc.so.9
> \#6 0x00007ffff7862f82 in grpc\_core::ResolvingLoadBalancingPolicy::ResolvingLoadBalancingPolicy(grpc\_core::LoadBalancingPolicy::Args, grpc\_core::TraceFlag\*, std::unique\_ptr\<char, grpc\_core::DefaultDeleteChar\>, bool (\*)(void\*, grpc\_core::Resolver::Result const&, char const\*\*, grpc\_core::RefCountedPtr\<grpc\_core::LoadBalancingPolicy::Config\>\*, grpc\_error\*\*), void\*) () from /root/grpc/install/lib/libgrpc.so.9
> \#7 0x00007ffff784f907 in ?? () from /root/grpc/install/lib/libgrpc.so.9
> \#8 0x00007ffff77cac36 in grpc\_combiner\_continue\_exec\_ctx() () from /root/grpc/install/lib/libgrpc.so.9
> \#9 0x00007ffff77d3ec3 in grpc\_core::ExecCtx::Flush() () from /root/grpc/install/lib/libgrpc.so.9
> \#10 0x00007ffff77f4eed in grpc\_call\_start\_batch () from /root/grpc/install/lib/libgrpc.so.9
> \#11 0x0000555555575f85 in grpc::internal::CallOpSet\<grpc::internal::CallOpSendInitialMetadata, grpc::internal::CallOpSendMessage, grpc::internal::CallOpClientSendClose, grpc::internal::CallOpRecvInitialMetadata, grpc::internal::CallOpRecvMessage\<benu\_cp\_pkts::ReceiveReport\>, grpc::internal::CallOpClientRecvStatus\>::ContinueFillOpsAfterInterception (this=0x5555557b6828)
> at /root/grpc/install/include/grpcpp/impl/codegen/call\_op\_set.h:938
> \#12 0x0000555555575d18 in grpc::internal::CallOpSet\<grpc::internal::CallOpSendInitialMetadata, grpc::internal::CallOpSendMessage, grpc::internal::CallOpClientSendClose, grpc::internal::CallOpRecvInitialMetadata, grpc::internal::CallOpRecvMessage\<benu\_cp\_pkts::ReceiveReport\>, grpc::internal::CallOpClientRecvStatus\>::FillOps (this=0x5555557b6828, call=0x5555557b67f0)
> at /root/grpc/install/include/grpcpp/impl/codegen/call\_op\_set.h:868
> \#13 0x0000555555566411 in grpc::internal::Call::PerformOps (this=0x5555557b67f0, ops=0x5555557b6828) at /root/grpc/install/include/grpcpp/impl/codegen/call.h:69
> \#14 0x00005555555754ef in grpc\_impl::ClientAsyncResponseReader\<benu\_cp\_pkts::ReceiveReport\>::Finish (this=0x5555557b67e0, msg=0x7fffffffd8f0, status=0x7fffffffd930, tag=0x1)
> at /root/grpc/install/include/grpcpp/impl/codegen/async\_unary\_call\_impl.h:150
> \#15 0x000055555557a2fb in myTestCPClient::SendCPPacket (this=0x7fffffffdbc0, request=...) at benu\_async\_client.cc:100
> \#16 0x0000555555579ab2 in main (argc=1, argv=0x7fffffffe488) at benu\_async\_client.cc:161
> 
> \`\`\`
> Code modified from greeter\_async\_client.cc
> 
> \`\`\`
> /\*
> \*
> \* Copyright 2015 gRPC authors.
> \*
> \* Licensed under the Apache License, Version 2.0 (the "License");
> \* you may not use this file except in compliance with the License.
> \* You may obtain a copy of the License at
> \*
> \* http://www.apache.org/licenses/LICENSE-2.0
> \*
> \* Unless required by applicable law or agreed to in writing, software
> \* distributed under the License is distributed on an "AS IS" BASIS,
> \* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> \* See the License for the specific language governing permissions and
> \* limitations under the License.
> \*
> \*/
> 
> \#include \<iostream\>
> \#include \<memory\>
> \#include \<string\>
> 
> \#include \<grpcpp/grpcpp.h\>
> \#include \<grpc/support/log.h\>
> 
> \#ifdef BAZEL\_BUILD
> \#include "examples/protos/helloworld.grpc.pb.h"
> \#else
> \#include "mytestTest.grpc.pb.h"
> \#endif
> 
> using grpc::Channel;
> using grpc::ClientAsyncResponseReader;
> using grpc::ClientContext;
> using grpc::CompletionQueue;
> using grpc::Status;
> using mytest\_cp\_pkts::ReceiveReport;
> using mytest\_cp\_pkts::CPProcessPkt;
> using mytest\_cp\_pkts::CP\_PACKETS\_RX\_TX;
> using mytest\_cp\_pkts::PacketType;
> using mytest\_cp\_pkts::EventType;
> using mytest\_cp\_pkts::Report;
> 
> class myTestCPClient {
> public:
> explicit myTestCPClient(std::shared\_ptr\<Channel\> channel)
> : stub\_(CP\_PACKETS\_RX\_TX::NewStub(channel)) {}
> 
> void string2hexString(char\* input, char\* output, size\_t strLen)
> {
> int loop;
> int i; 
> 
> i=0;
> loop=0;
> 
> //while(input\[loop\] != '\\0')
> while(loop \< strLen)
> {
> sprintf((char\*)(output+i),"%02X", input\[loop\]);
> loop+=1;
> i+=2;
> }
> //insert NULL at the end of the output string
> output\[i++\] = '\\0';
> }
> // Assembles the client's payload, sends it and presents the response back
> // from the server.
> ReceiveReport \* SendCPPacket(const CPProcessPkt& request) {
> // Data we are sending to the server.
> 
> // Container for the data we expect from the server.
> //CPProcessPkt request;
> ReceiveReport reply;
> 
> // Context for the client. It could be used to convey extra information to
> // the server and/or tweak certain RPC behaviors.
> ClientContext context;
> 
> // The producer-consumer queue we use to communicate asynchronously with the
> // gRPC runtime.
> CompletionQueue cq;
> 
> // Storage for the status of the RPC upon completion.
> Status status;
> 
> // stub\_-\>PrepareAsyncSayHello() creates an RPC object, returning
> // an instance to store in "call" but does not actually start the RPC
> // Because we are using the asynchronous API, we need to hold on to
> // the "call" instance in order to get updates on the ongoing RPC.
> std::unique\_ptr\<ClientAsyncResponseReader\<ReceiveReport\> \> rpc(
> stub\_-\>PrepareAsyncPktRequest(&context, request, &cq));
> 
> // StartCall initiates the RPC call
> rpc-\>StartCall();
> 
> // Request that, upon completion of the RPC, "reply" be updated with the
> // server's response; "status" with the indication of whether the operation
> // was successful. Tag the request with the integer 1.
> rpc-\>Finish(&reply, &status, (void\*)1);
> void\* got\_tag;
> bool ok = false;
> // Block until the next result is available in the completion queue "cq".
> // The return value of Next should always be checked. This return value
> // tells us whether there is any kind of event or the cq\_ is shutting down.
> GPR\_ASSERT(cq.Next(&got\_tag, &ok));
> 
> // Verify that the result from "cq" corresponds, by its tag, our previous
> // request.
> GPR\_ASSERT(got\_tag == (void\*)1);
> // ... and that the request was completed successfully. Note that "ok"
> // corresponds solely to the request for updates introduced by Finish().
> GPR\_ASSERT(ok);
> 
> // Act upon the status of the actual RPC.
> if (status.ok()) {
> return &reply;
> } else {
> return NULL;
> }
> }
> 
> private:
> // Out of the passed in Channel comes the stub, stored here, our view of the
> // server's exposed services.
> std::unique\_ptr\<CP\_PACKETS\_RX\_TX::Stub\> stub\_;
> };
> 
> int main(int argc, char\*\* argv) {
> // Instantiate the client. It requires a channel, out of which the actual RPCs
> // are created. This channel models a connection to an endpoint (in this case,
> // localhost at port 50051). We indicate that the channel isn't authenticated
> // (use of InsecureChannelCredentials()).
> std::string server;                         
> if (argc \>= 2)                              
> {
> server = argv\[1\] + std::string(":50051");
> }
> else                                        
> {
> server = "localhost:50051";              
> }
> myTestCPClient client(grpc::CreateChannel(
> server.c\_str(), grpc::InsecureChannelCredentials()));
> char dhcp\_req\[\] = "0050568d52b1005056b561bc08004500017900010000402f5ef80aa000010d0c02b100006558ffffffffffff000003223341810000c808004500014f000100004011799e00000000ffffffff00440043013b00000101060001020304000000000000000000000000000000000000000000000322334100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000638253633501033604ac1c43013204ac1c430e5231011c30303a39303a38383a37373a36363a35363b4454482d535349443b6f021130303a39303a38383a37373a36363a3536ff";
> 
> int dataLen = strlen(dhcp\_req);
> 
> char output\[1024\] = {0};
> client.string2hexString(dhcp\_req, output, strlen(dhcp\_req));
> 
> CPProcessPkt packet;
> 
> packet.set\_packet\_type(PacketType::DHCP);
> packet.set\_event(EventType::EVENT\_NONE);
> packet.set\_dp\_id(19);
> packet.set\_port\_id(3);
> packet.set\_data(output);
> 
> std::string user("world");
> ReceiveReport \*reply = client.SendCPPacket(packet); // The actual RPC call!
> std::cout \<\< "CP\_PACKETS\_RX\_TX received: " \<\< reply-\>processed\_pkt().port\_id() \<\< " dp: " \<\< reply-\>processed\_pkt().dp\_id() \<\< std::endl;
> 
> return 0;
> }
> 
> \`\`\`
> 
> my proto file
> 
> 
> \`\`\`
> // Copyright 2015 myTest
> //
> // Licensed under the Apache License, Version 2.0 (the "License");
> // you may not use this file except in compliance with the License.
> // You may obtain a copy of the License at
> //
> // http://www.apache.org/licenses/LICENSE-2.0
> //
> // Unless required by applicable law or agreed to in writing, software
> // distributed under the License is distributed on an "AS IS" BASIS,
> // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> // See the License for the specific language governing permissions and
> // limitations under the License.
> 
> syntax = "proto3";
> 
> package myTest\_cp\_pkts;
> 
> // Interface exported by the server.
> service CP\_PACKETS\_RX\_TX {
> // A simple RPC.
> //
> // Sends the packet to and from CP and/or DP
> rpc PktRequest(CPProcessPkt) returns (ReceiveReport) {}
> }
> 
> enum PacketType {
> DHCP = 0;
> 
> ARP = 1;
> 
> EVENT = 2;
> };
> 
> // If PacketType is EVENT then the events can be of the following
> 
> enum EventType {
> EVENT\_NONE = 0;
> };
> 
> enum Report {
> RECEIVE\_OK = 0;
> 
> RECEIVE\_FAIL = 1;
> };
> 
> message CPProcessPkt {
> PacketType packet\_type = 1;
> 
> EventType event = 2;
> 
> int32 dp\_id = 3;
> 
> int32 port\_id = 4;
> 
> string data = 5;
> };
> 
> message ReceiveReport {
> Report report = 1;
> 
> CPProcessPkt processed\_pkt = 2;
> };
> 
> \`\`\`

---

<div class="post-metadata">

**Author:** ![mdianjun](https://sea1.discourse-cdn.com/foundationdb/user_avatar/forums.foundationdb.org/mdianjun/32/1456_2.png) [@mdianjun](https://forums.foundationdb.org/u/mdianjun)\
**Post date:** [March 22, 2023, 7:31am UTC](https://forums.foundationdb.org/t/sigsegv-in-fdb-run-network/3716/5 "2023-03-22T07:31:32Z")

</div>

This issue happens a lot:

```auto
(gdb) bt
#0 __GI_getenv (name=0x7f192d2be022 "B_TLS_VERIFY_PEERS") at getenv.c:84
#1 0x00007f192ceb0723 in fdb_transaction_set_option () from /lib/libfdb_c.so
#2 0x00007f192cecf910 in fdb_transaction_set_option () from /lib/libfdb_c.so
#3 0x00007f192ce7869e in fdb_transaction_set_option () from /lib/libfdb_c.so
#4 0x00007f192c8dd5de in fdb_transaction_set_option () from /lib/libfdb_c.so
#5 0x00007f192cd28228 in fdb_transaction_set_option () from /lib/libfdb_c.so
#6 0x00007f192cd2836b in fdb_transaction_set_option () from /lib/libfdb_c.so
#7 0x00007f192cc584d0 in fdb_transaction_set_option () from /lib/libfdb_c.so
#8 0x00007f192ce7757e in fdb_transaction_set_option () from /lib/libfdb_c.so
#9 0x00007f192c7b6ef2 in fdb_transaction_set_option () from /lib/libfdb_c.so
#10 0x00007f192cd20bcf in fdb_transaction_set_option () from /lib/libfdb_c.so
#11 0x00007f192c76eb32 in fdb_transaction_set_option () from /lib/libfdb_c.so
#12 0x00007f192c74a089 in fdb_run_network () from /lib/libfdb_c.so
#13 0x000055579f696505 in runFdbNetwork ()
#14 0x00007f192b465609 in start_thread (arg=<optimized out>) at pthread_create.c:477
#15 0x00007f192a4db133 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

```
