简体   繁体   中英

Buffer overflow detected

Good day, I am having an issue using tcp select in c/c++, the server needs to handle 2500 connections using a single process, but it always connect until 1020 clients, then the connections fails(aborts/buffer overlow detected).I suppose that it is because is trying to open 2500 file descriptors, but with 1020 fd + the master socket + stdin/stdout/stderr, I'm reaching the default limit of files open per process (1024).

I have tried to change the max file open per process in the limits file on debian, but it seems like nothing happened since it stills connecting until 1020.

*** buffer overflow detected ***: ./WildChildrenServer terminated
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x731ff)[0x7f08cb7a31ff]
/lib/x86_64-linux-gnu/libc.so.6(__fortify_fail+0x37)[0x7f08cb8264c7]
/lib/x86_64-linux-gnu/libc.so.6(+0xf46e0)[0x7f08cb8246e0]
/lib/x86_64-linux-gnu/libc.so.6(+0xf6437)[0x7f08cb826437]
./WildChildrenServer[0x405e4b]
./WildChildrenServer[0x40255d]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf5)[0x7f08cb751b45]
./WildChildrenServer[0x402639]
======= Memory map: ========
00400000-00408000 r-xp 00000000 08:05 788806                             /home/labam/Distribuidos/WildChildrenServer/bin/Release/WildChildrenServer
00607000-00608000 r--p 00007000 08:05 788806                             /home/labam/Distribuidos/WildChildrenServer/bin/Release/WildChildrenServer
00608000-00609000 rw-p 00008000 08:05 788806                             /home/labam/Distribuidos/WildChildrenServer/bin/Release/WildChildrenServer
00943000-009a2000 rw-p 00000000 00:00 0                                  [heap]
7f08c0000000-7f08c0021000 rw-p 00000000 00:00 0 
7f08c0021000-7f08c4000000 ---p 00000000 00:00 0 
7f08ca9a6000-7f08ca9b1000 r-xp 00000000 08:05 262665                     /lib/x86_64-linux-gnu/libnss_files-2.19.so
7f08ca9b1000-7f08cabb0000 ---p 0000b000 08:05 262665                     /lib/x86_64-linux-gnu/libnss_files-2.19.so
7f08cabb0000-7f08cabb1000 r--p 0000a000 08:05 262665                     /lib/x86_64-linux-gnu/libnss_files-2.19.so
7f08cabb1000-7f08cabb2000 rw-p 0000b000 08:05 262665                     /lib/x86_64-linux-gnu/libnss_files-2.19.so
7f08cabb2000-7f08cabb5000 r-xp 00000000 08:05 262663                     /lib/x86_64-linux-gnu/libdl-2.19.so
7f08cabb5000-7f08cadb4000 ---p 00003000 08:05 262663                     /lib/x86_64-linux-gnu/libdl-2.19.so
7f08cadb4000-7f08cadb5000 r--p 00002000 08:05 262663                     /lib/x86_64-linux-gnu/libdl-2.19.so
7f08cadb5000-7f08cadb6000 rw-p 00003000 08:05 262663                     /lib/x86_64-linux-gnu/libdl-2.19.so
7f08cadb6000-7f08cadd0000 r-xp 00000000 08:05 262756                     /lib/x86_64-linux-gnu/libz.so.1.2.8
7f08cadd0000-7f08cafcf000 ---p 0001a000 08:05 262756                     /lib/x86_64-linux-gnu/libz.so.1.2.8
7f08cafcf000-7f08cafd0000 r--p 00019000 08:05 262756                     /lib/x86_64-linux-gnu/libz.so.1.2.8
7f08cafd0000-7f08cafd1000 rw-p 0001a000 08:05 262756                     /lib/x86_64-linux-gnu/libz.so.1.2.8
7f08cafd1000-7f08cafe9000 r-xp 00000000 08:05 262671                     /lib/x86_64-linux-gnu/libpthread-2.19.so
7f08cafe9000-7f08cb1e8000 ---p 00018000 08:05 262671                     /lib/x86_64-linux-gnu/libpthread-2.19.so
7f08cb1e8000-7f08cb1e9000 r--p 00017000 08:05 262671                     /lib/x86_64-linux-gnu/libpthread-2.19.so
7f08cb1e9000-7f08cb1ea000 rw-p 00018000 08:05 262671                     /lib/x86_64-linux-gnu/libpthread-2.19.so
7f08cb1ea000-7f08cb1ee000 rw-p 00000000 00:00 0 
7f08cb1ee000-7f08cb4a5000 r-xp 00000000 08:05 1053975                    /usr/lib/x86_64-linux-gnu/libmysqlclient.so.18.0.0
7f08cb4a5000-7f08cb6a5000 ---p 002b7000 08:05 1053975                    /usr/lib/x86_64-linux-gnu/libmysqlclient.so.18.0.0
7f08cb6a5000-7f08cb6ab000 r--p 002b7000 08:05 1053975                    /usr/lib/x86_64-linux-gnu/libmysqlclient.so.18.0.0
7f08cb6ab000-7f08cb72a000 rw-p 002bd000 08:05 1053975                    /usr/lib/x86_64-linux-gnu/libmysqlclient.so.18.0.0
7f08cb72a000-7f08cb730000 rw-p 00000000 00:00 0 
7f08cb730000-7f08cb8cf000 r-xp 00000000 08:05 262678                     /lib/x86_64-linux-gnu/libc-2.19.so
7f08cb8cf000-7f08cbacf000 ---p 0019f000 08:05 262678                     /lib/x86_64-linux-gnu/libc-2.19.so
7f08cbacf000-7f08cbad3000 r--p 0019f000 08:05 262678                     /lib/x86_64-linux-gnu/libc-2.19.so
7f08cbad3000-7f08cbad5000 rw-p 001a3000 08:05 262678                     /lib/x86_64-linux-gnu/libc-2.19.so
7f08cbad5000-7f08cbad9000 rw-p 00000000 00:00 0 
7f08cbad9000-7f08cbaef000 r-xp 00000000 08:05 262660                     /lib/x86_64-linux-gnu/libgcc_s.so.1
7f08cbaef000-7f08cbcee000 ---p 00016000 08:05 262660                     /lib/x86_64-linux-gnu/libgcc_s.so.1
7f08cbcee000-7f08cbcef000 rw-p 00015000 08:05 262660                     /lib/x86_64-linux-gnu/libgcc_s.so.1
7f08cbcef000-7f08cbdef000 r-xp 00000000 08:05 262677                     /lib/x86_64-linux-gnu/libm-2.19.so
7f08cbdef000-7f08cbfee000 ---p 00100000 08:05 262677                     /lib/x86_64-linux-gnu/libm-2.19.so
7f08cbfee000-7f08cbfef000 r--p 000ff000 08:05 262677                     /lib/x86_64-linux-gnu/libm-2.19.so
7f08cbfef000-7f08cbff0000 rw-p 00100000 08:05 262677                     /lib/x86_64-linux-gnu/libm-2.19.so
7f08cbff0000-7f08cc0dc000 r-xp 00000000 08:05 1055513                    /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.20
7f08cc0dc000-7f08cc2dc000 ---p 000ec000 08:05 1055513                    /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.20
7f08cc2dc000-7f08cc2e4000 r--p 000ec000 08:05 1055513                    /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.20
7f08cc2e4000-7f08cc2e6000 rw-p 000f4000 08:05 1055513                    /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.20
7f08cc2e6000-7f08cc2fb000 rw-p 00000000 00:00 0 
7f08cc2fb000-7f08cc3fc000 r-xp 00000000 08:05 1057005                    /usr/lib/libmysqlcppconn.so.7.1.1.3
7f08cc3fc000-7f08cc5fc000 ---p 00101000 08:05 1057005                    /usr/lib/libmysqlcppconn.so.7.1.1.3
7f08cc5fc000-7f08cc60c000 rw-p 00101000 08:05 1057005                    /usr/lib/libmysqlcppconn.so.7.1.1.3
7f08cc60c000-7f08cc62c000 r-xp 00000000 08:05 262661                     /lib/x86_64-linux-gnu/ld-2.19.so
7f08cc80a000-7f08cc811000 rw-p 00000000 00:00 0 
7f08cc828000-7f08cc82c000 rw-p 00000000 00:00 0 
7f08cc82c000-7f08cc82d000 r--p 00020000 08:05 262661                     /lib/x86_64-linux-gnu/ld-2.19.so
7f08cc82d000-7f08cc82e000 rw-p 00021000 08:05 262661                     /lib/x86_64-linux-gnu/ld-2.19.so
7f08cc82e000-7f08cc82f000 rw-p 00000000 00:00 0 
7fff702c3000-7fff702e4000 rw-p 00000000 00:00 0                          [stack]
7fff7038d000-7fff7038f000 r-xp 00000000 00:00 0                          [vdso]
7fff7038f000-7fff70391000 r--p 00000000 00:00 0                          [vvar]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]
Abortado

The file's limit I did set: labam@debian:~/Distribuidos/WildChildrenServer/bin/Release$ ulimit -n 4096

Select arguments are of type "fd_set" and this set us usually limited to 1024 connections. Use "poll" instead.

See this link as reference for other alternatives:

Handling more than 1024 file descriptors, in C on Linux

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