简体   繁体   English

带有 sscanf 和线程的 sigpipe

[英]sigpipe with sscanf and threading

DESCRIPTION描述

I made a C server mod for cube 2: Sauerbraten https://github.com/deathstar/QServCollect我为立方体 2 制作了一个 C 服务器 mod:Sauerbraten https://github.com/deathstar/QServCollect

all the code can be found at the link above所有代码都可以在上面的链接中找到

The IRC Bot eventually stops sending the ping/pong data on the opened socket. IRC Bot 最终停止在打开的套接字上发送 ping/pong 数据。 The process is threaded and since the main thread is joined through PTHREAD_CREATE_JOINABLE, it dies when the IRC bot dies.该进程是线程化的,并且由于主线程是通过 PTHREAD_CREATE_JOINABLE 加入的,因此当 IRC bot 终止时它也会终止。 This causes the entire server to crash, and I am just trying to debug it.这导致整个服务器崩溃,我只是想调试它。 Any help would be appreciated.任何帮助将不胜感激。

KEY钥匙

Ircbot code: ircbot/ircbot.cpp, ircbot/ircbot.h ircbot 代码:ircbot/ircbot.cpp、ircbot/ircbot.h

Main thread: engine/server.cpp主线程:engine/server.cpp

LLDB DEBUG REPORT LLDB 调试报告

Process 7933 stopped
* thread #1: tid = 0xa4b8d, 0x00007fff83e4010a libsystem_kernel.dylib`__semwait_signal + 10, queue = 'com.apple.main-thread', stop reason = signal SIGPIPE
    frame #0: 0x00007fff83e4010a libsystem_kernel.dylib`__semwait_signal + 10
libsystem_kernel.dylib`__semwait_signal:
->  0x7fff83e4010a <+10>: jae    0x7fff83e40114            ; <+20>
    0x7fff83e4010c <+12>: movq   %rax, %rdi
    0x7fff83e4010f <+15>: jmp    0x7fff83e3a7f2            ; cerror
    0x7fff83e40114 <+20>: retq  

SERVER LOG服务器日志

PING :NuclearFallout.WA.US.GameSurge.net

SENT: PONG :NuclearFallout.WA.US.GameSurge.net

PING :NuclearFallout.WA.US.GameSurge.net

SENT: PONG :NuclearFallout.WA.US.GameSurge.net

[ OK ] looking up sauerbraten.org...
master server registration failed: failed pinging server
[ OK ] looking up sauerbraten.org...

The problem was that a function (specifically sscanf) was overloaded with data.问题是一个函数(特别是 sscanf)被数据重载了。 I needed to do a strlen(buff) to check the buffer size of the data going into the function.我需要做一个 strlen(buff) 来检查进入函数的数据的缓冲区大小。 Essentially it was getting much more data than it could handle and it would cause a crash eventually because of it.从本质上讲,它获得的数据远远超过其处理能力,最终会因此导致崩溃。

If you are implementing threading, make sure to use thread safe implementations.如果您要实现线程,请确保使用线程安全实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM