otland / forgottenserver

A free and open-source MMORPG server emulator written in C++
https://otland.net
GNU General Public License v2.0
1.59k stars 1.06k forks source link

[Bug]: Segmentation fault at g_RSA.loadPEM("key.pem"); #3628

Open Rexikon opened 3 years ago

Rexikon commented 3 years ago

Before creating an issue, please ensure:

Steps to reproduce (include any configuration/script required to reproduce)

Issue can be easilly reproducted at fresh centos 8 install (from cloud or vps)

  1. CentOS Linux release 8.4.2105
  2. sed -i 's/enabled=0/enabled=1/g' -PowerTools.repo
  3. dnf install epel-release
  4. dnf install git boost-devel make cmake3 cryptopp-devel gcc-c++ gmp-devel lua-devel luajit mariadb-devel pugixml-devel fmt
  5. yum install fmt-devel.x86_64
  6. mkdir build && cd build
  7. cmake -DCMAKE_BUILD_TYPE=Debug ..

Expected behaviour

Server starts normally

Actual behaviour

Hi, I'm trying to run this on CentOS Linux release 8.4.2105, but it fails at g_RSA.loadPEM("key.pem"); I ran this as root to be sure that isn't privilege issue. I use default key file, and tried to create own file with random text data - its fails too. I have debugged it manually by adding comments and it is falling at: /src/rsa.cpp line 55 for (std::string line; std::getline(file, line); oss << line); Tried to read and print line by line, but it fails: if (file.is_open()) { std::string line; while (std::getline(file, line)) { SPDLOG_INFO("line {}", line.c_str()); } file.close(); }

GDB LOG


GNU gdb (GDB) Red Hat Enterprise Linux 8.2-15.el8
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./tfs...done.
(gdb) run
Starting program: /root/forgottenserver/tfs 
Missing separate debuginfos, use: yum debuginfo-install glibc-2.28-151.el8.x86_64
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".

Program received signal SIGSEGV, Segmentation fault.
0x0000000000000000 in ?? ()
(gdb) bt full
#0  0x0000000000000000 in ?? ()
No symbol table info available.
#1  0x00007ffff77a64d6 in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_construct_aux<char const*> (__end=0x7ffff77b21e7 "", __beg=<synthetic pointer>, 
    this=0x7ffff79b7160 <(anonymous namespace)::windows_invalid_chars>) at /usr/include/c++/8/bits/basic_string.h:252
No locals.
#2  std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_construct<char const*> (__end=0x7ffff77b21e7 "", __beg=<synthetic pointer>, this=0x7ffff79b7160 <(anonymous namespace)::windows_invalid_chars>)
    at /usr/include/c++/8/bits/basic_string.h:255
No locals.
#3  std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string (__a=..., __n=39, __s=<synthetic pointer>, this=0x7ffff79b7160 <(anonymous namespace)::windows_invalid_chars>)
    at /usr/include/c++/8/bits/basic_string.h:502
No locals.
#4  __static_initialization_and_destruction_0 (__initialize_p=1, __priority=65535) at libs/filesystem/src/portability.cpp:41
No locals.
#5  _GLOBAL__sub_I_portability.cpp(void) () at libs/filesystem/src/portability.cpp:119
No locals.
#6  0x00007ffff7ddf8ba in call_init.part () from /lib64/ld-linux-x86-64.so.2
No symbol table info available.
#7  0x00007ffff7ddf9ba in _dl_init () from /lib64/ld-linux-x86-64.so.2
No symbol table info available.
#8  0x00007ffff7dd0fda in _dl_start_user () from /lib64/ld-linux-x86-64.so.2
No symbol table info available.
#9  0x0000000000000001 in ?? ()
No symbol table info available.
#10 0x00007fffffffdd6c in ?? ()
No symbol table info available.
#11 0x0000000000000000 in ?? ()
No symbol table info available.```
soul4soul commented 3 years ago

Is the line ending of the key.pem correct? Since I cloned TFS on Windows and run the server using WSL the key.pem file had the wrong line endings. When I had that happen the server wouldn't start.

Rexikon commented 3 years ago

Is the line ending of the key.pem correct? Since I cloned TFS on Windows and run the server using WSL the key.pem file had the wrong line endings. When I had that happen the server wouldn't start.

Checked and this file have /n line endings, so it's correct. Used dos2unix on key.pem

cat -A key.pem -----BEGIN RSA PRIVATE KEY-----$ MIICXAIBAAKBgQCbZGkDtFsHrJVlaNhzU71xZROd15QHA7A+bdB5OZZhtKg3qmBWHXzLlFL6AIBZ$ SQmIKrW8pYoaGzX4sQWbcrEhJhHGFSrT27PPvuetwUKnXT11lxUJwyHFwkpb1R/UYPAbThW+sN4Z$ MFKKXT8VwePL9cQB1nd+EKyqsz2+jVt/9QIDAQABAoGAQovTtTRtr3GnYRBvcaQxAvjIV9ZUnFRm$ C7Y3i1KwJhOZ3ozmSLrEEOLqTgoc7R+sJ1YzEiDKbbete11EC3gohlhW56ptj0WDf+7ptKOgqiEy$ Kh4qt1sYJeeGz4GiiooJoeKFGdtk/5uvMR6FDCv6H7ewigVswzf330Q3Ya7+jYECQQERBxsga6+5$ x6IofXyNF6QuMqvuiN/pUgaStUOdlnWBf/T4yUpKvNS1+I4iDzqGWOOSR6RsaYPYVhj9iRABoKyx$ AkEAkbNzB6vhLAWht4dUdGzaREF3p4SwNcu5bJRa/9wCLSHaS9JaTq4lljgVPp1zyXyJCSCWpFnl$ 0WvK3Qf6nVBIhQJBANS7rK8+ONWQbxENdZaZ7Rrx8HUTwSOS/fwhsGWBbl1Qzhdq/6/sIfEHkfeH$ 1hoH+IlpuPuf21MdAqvJt+cMwoECQF1LyBOYduYGcSgg6u5mKVldhm3pJCA+ZGxnjuGZEnet3qeA$ eb05++112fyvO85ABUun524z9lokKNFh45NKLjUCQGshzV43P+RioiBhtEpB/QFzijiS4L2HKNu1$ tdhudnUjWkaf6jJmQS/ppln0hhRMHlk9Vus/bPx7LtuDuo6VQDo=$ -----END RSA PRIVATE KEY-----$ $

yamaken93 commented 3 years ago

I don't understand why you got such a problem where is a try catch around loading the pem file https://github.com/otland/forgottenserver/blob/8cc1f3d51c6f4c90ce66b6d3122ce4388d709fe8/src/otserv.cpp#L192.

Rexikon commented 3 years ago

I don't understand why you got such a problem where is a try catch around loading the pem file

I see, but there is problem to run this on centos...

EPuncker commented 3 years ago

hey @Rexikon is this still happening or did you find a solution?

Rexikon commented 3 years ago

hey @Rexikon is this still happening or did you found a solution?

Still same error

gesior commented 3 years ago

@Rexikon Are we talking about TFS bug or problem with some basic C++ library on CentOS 8? Loading string finish in SIGSEGV?!

Can you prepare Dockerfile to reproduce it?

ramon-bernardo commented 5 months ago

Maybe https://github.com/otland/forgottenserver/pull/4655 solved this problem, no?

@ranisalt

ranisalt commented 5 months ago

Probably, but this was also running a modified version of the repo, SPDLOG_INFO is not present there at that point in time https://github.com/otland/forgottenserver/blob/474b959f8bae491afe10d2e7fa4919722e594ce3/src/rsa.cpp