简体   繁体   中英

How to access data written in a socket without reading it

I'm working on an embedded system having Linux. A client thread is writing some data in the socket but what server thread is reading on the other side isn't the same as it was written. Which is causing the thread (and parent process) to crash.

I'm new to networking and Linux. I have dumped every piece of data which is being written, it's all fine.

The function trace in gdb shows the following information.

(gdb) 
#0  0x00007f62be8e8670 in getenv () from /lib/libc.so.6
#1  0x00007f62be92057a in __libc_message () from /lib/libc.so.6
#2  0x00007f62be99f927 in __fortify_fail () from /lib/libc.so.6
#3  0x00007f62be99f8f0 in __stack_chk_fail () from /lib/libc.so.6
#4  0x0000000000406471 in reading (sockFd=15) at __line_number_in_the_program__
#5  0x793bcf318b18bb01 in ?? ()
#6  0x117d0300942ff567 in ?? ()
#7  0x0000000100000000 in ?? ()
..
..
..

It goes till #785 with some [random] address.

reading() is the function which processes the read data in the server thread.

I suspect there something going wrong inside the socket. Is there any way to see the data which is in the sockets(client/server) buffer without reading it? Or any other way to debug it further with gdb?

There are already some checks to handle the read data properly but those are also not helping.

You have a stack buffer overflow problem. If you have never heard of the GCC stack protector, now is the time to look it up. Whilst Wireshark is the obvious tool for looking at data in flight, this is not the locus of your problem. Your server should be proof against any and all malicious data read from the network. This is basic good server design and implementation practice. You have a stack buffer overflow problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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