Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Including a Regular Expression, makes the program crash without even starting #11

Open
hcfcoder opened this issue Mar 18, 2023 · 2 comments

Comments

@hcfcoder
Copy link

hcfcoder commented Mar 18, 2023

It seems that using functionalities of the <regex> header, makes the program crash without even starting to run.

I have created a minimal program to reproduce this issue:
https://gist.github.com/hcfcoder/9d3eb3212ce39bccd5dac95edf097d5a

Basically, adding these 2 codelines makes the program not able to start:

#include <regex>
static std::regex includeRegex = std::regex("\s*#include\s+([\\/A-Za-z0-9\-\.]+)");

I hope this helps.

@hcfcoder
Copy link
Author

A detail that may help (thanks to antangelo for pointing to it): the program crashes when that regex declaration is executed. In my example, as the declaration was global, it is run at the begining of the program, so it crashes even before the main function is run. That is why the program crashes without even begining.

On the other hand, if the declaration is local in a function, the program crashes when that function is called (not at the begining of the execution).

@thrimbor thrimbor transferred this issue from XboxDev/nxdk Mar 24, 2023
@thrimbor
Copy link
Member

It appears the version of libc++ we use has an issue with escaping (#3 may be related). The following is a minimal sample that highlights the issue:

std::regex("\\\\");

libc++'s regex implementation errors while parsing this, calling __throw_regex_error for error_type::error_escape. Because we don't have support for C++ exceptions in nxdk yet, this function calls abort, which then goes through PDCLib and reboots.

GDB log:

GNU gdb (GDB) 13.1
Copyright (C) 2023 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-pc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://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".
(gdb) set arch i386
The target architecture is set to "i386".
(gdb) add-symbol-file main.exe 
add symbol table from file "main.exe"
(y or n) y
Reading symbols from main.exe...
(gdb) target remote 127.0.0.1:1234
Remote debugging using 127.0.0.1:1234
warning: No executable has been specified and target does not support
determining executable automatically.  Try using the "file" command.
0x0000fff0 in ?? ()
(gdb) b _PDCLIB_Exit
Breakpoint 1 at 0x8e0a7: file /home/venom/Sync/xbox_dev/nxdk-nvnetdrv/lib/pdclib/platform/xbox/functions/_PDCLIB/_PDCLIB_Exit.c, line 19.
(gdb) c
Continuing.

Breakpoint 1, _PDCLIB_Exit (status=-1)
    at /home/venom/Sync/xbox_dev/nxdk-nvnetdrv/lib/pdclib/platform/xbox/functions/_PDCLIB/_PDCLIB_Exit.c:19
19          DbgPrint("_PDCLIB_Exit\n");
(gdb) bt
#0  _PDCLIB_Exit (status=-1)
    at /home/venom/Sync/xbox_dev/nxdk-nvnetdrv/lib/pdclib/platform/xbox/functions/_PDCLIB/_PDCLIB_Exit.c:19
#1  0x00087ed7 in _Exit (status=-1)
    at /home/venom/Sync/xbox_dev/nxdk-nvnetdrv/lib/pdclib/functions/stdlib/_Exit.c:17
#2  0x0006be60 in raise (sig=6)
    at /home/venom/Sync/xbox_dev/nxdk-nvnetdrv/lib/pdclib/platform/xbox/functions/signal/raise.c:58
#3  0x00026ed0 in abort ()
    at /home/venom/Sync/xbox_dev/nxdk-nvnetdrv/lib/pdclib/functions/stdlib/abort.c:14
#4  0x00019b82 in ??$__throw_regex_error@$02@__1@std@@YAXXZ ()
    at /home/venom/Sync/xbox_dev/nxdk-nvnetdrv/lib/libcxx/include/regex:992
#5  0x0001a454 in ??$__parse_character_escape@PBD@?$basic_regex@DU?$regex_traits@D@__1@std@@@__1@std@@AAEPBDPBD0PAV?$basic_string@DU?$char_traits@D@__1@std@@V?$allocator@D@23@@12@@Z (this=0xd0044c38, 
    __first=0x98017 "\\/A-Za-z0-9_\\-\\.]+)", __last=0x9802a "", __str=0xd0044a1c)
    at /home/venom/Sync/xbox_dev/nxdk-nvnetdrv/lib/libcxx/include/regex:4551
#6  0x00020896 in ??$__parse_class_escape@PBD@?$basic_regex@DU?$regex_traits@D@__1@std@@@__1@std@@AAEPBDPBD0AAV?$basic_string@DU?$char_traits@D@__1@std@@V?$allocator@D@23@@12@PAV?$__bracket_expression@DU?$regex_traits@D@__1@std@@@12@@Z (this=0xd0044c38, __first=0x98017 "\\/A-Za-z0-9_\\-\\.]+)", 
    __last=0x9802a "", __str=..., __ml=0x2f0220)
    at /home/venom/Sync/xbox_dev/nxdk-nvnetdrv/lib/libcxx/include/regex:3909
#7  0x0001fee5 in ??$__parse_expression_term@PBD@?$basic_regex@DU?$regex_traits@D@__1@std@@@__1@std@@AAEPBDPBD0PAV?$__bracket_expression@DU?$regex_traits@D@__1@std@@@12@@Z (this=0xd0044c38, 
    __first=0x98017 "\\/A-Za-z0-9_\\-\\.]+)", __last=0x9802a "", __ml=0x2f0220)
    at /home/venom/Sync/xbox_dev/nxdk-nvnetdrv/lib/libcxx/include/regex:3811
#8  0x0001fce6 in ??$__parse_follow_list@PBD@?$basic_regex@DU?$regex_traits@D@__1@std@@@__1@std@@AAEPBDPBD0PAV?$__bracket_expression@DU?$regex_traits@D@__1@std@@@12@@Z (this=0xd0044c38, 
    __first=0x98016 "\\\\/A-Za-z0-9_\\-\\.]+)", __last=0x9802a "", __ml=0x2f0220)
    at /home/venom/Sync/xbox_dev/nxdk-nvnetdrv/lib/libcxx/include/regex:3775
#9  0x00019702 in ??$__parse_bracket_expression@PBD@?$basic_regex@DU?$regex_traits@D@__1@std@@@__1@std@@AAEPBDPBD0@Z (this=0xd0044c38, __first=0x98016 "\\\\/A-Za-z0-9_\\-\\.]+)", __last=0x9802a "")
    at /home/venom/Sync/xbox_dev/nxdk-nvnetdrv/lib/libcxx/include/regex:3749
#10 0x0001330c in ??$__parse_atom@PBD@?$basic_regex@DU?$regex_traits@D@__1@std@@@__1@std@@AAEPBDPBD0@Z
    (this=0xd0044c38, __first=0x98015 "[\\\\/A-Za-z0-9_\\-\\.]+)", __last=0x9802a "")
    at /home/venom/Sync/xbox_dev/nxdk-nvnetdrv/lib/libcxx/include/regex:4275
#11 0x00012e9d in ??$__parse_term@PBD@?$basic_regex@DU?$regex_traits@D@__1@std@@@__1@std@@AAEPBDPBD0@Z
    (this=0xd0044c38, __first=0x98015 "[\\\\/A-Za-z0-9_\\-\\.]+)", __last=0x9802a "")
    at /home/venom/Sync/xbox_dev/nxdk-nvnetdrv/lib/libcxx/include/regex:4166
#12 0x00012c8a in ??$__parse_alternative@PBD@?$basic_regex@DU?$regex_traits@D@__1@std@@@__1@std@@AAEPBDPBD0@Z (this=0xd0044c38, __first=0x98015 "[\\\\/A-Za-z0-9_\\-\\.]+)", __last=0x9802a "")
    at /home/venom/Sync/xbox_dev/nxdk-nvnetdrv/lib/libcxx/include/regex:4147
#13 0x0001164d in ??$__parse_ecma_exp@PBD@?$basic_regex@DU?$regex_traits@D@__1@std@@@__1@std@@AAEPBDPBD0@Z (this=0xd0044c38, __first=0x98015 "[\\\\/A-Za-z0-9_\\-\\.]+)", __last=0x9802a "")
    at /home/venom/Sync/xbox_dev/nxdk-nvnetdrv/lib/libcxx/include/regex:4123
#14 0x00013401 in ??$__parse_atom@PBD@?$basic_regex@DU?$regex_traits@D@__1@std@@@__1@std@@AAEPBDPBD0@Z
    (this=0xd0044c38, __first=0x98015 "[\\\\/A-Za-z0-9_\\-\\.]+)", __last=0x9802a "")
    at /home/venom/Sync/xbox_dev/nxdk-nvnetdrv/lib/libcxx/include/regex:4297
#15 0x00012e9d in ??$__parse_term@PBD@?$basic_regex@DU?$regex_traits@D@__1@std@@@__1@std@@AAEPBDPBD0@Z
    (this=0xd0044c38, __first=0x98014 "([\\\\/A-Za-z0-9_\\-\\.]+)", __last=0x9802a "")
    at /home/venom/Sync/xbox_dev/nxdk-nvnetdrv/lib/libcxx/include/regex:4166
#16 0x00012c8a in ??$__parse_alternative@PBD@?$basic_regex@DU?$regex_traits@D@__1@std@@@__1@std@@AAEPBDPBD0@Z (this=0xd0044c38, __first=0x98014 "([\\\\/A-Za-z0-9_\\-\\.]+)", __last=0x9802a "")
    at /home/venom/Sync/xbox_dev/nxdk-nvnetdrv/lib/libcxx/include/regex:4147
#17 0x0001164d in ??$__parse_ecma_exp@PBD@?$basic_regex@DU?$regex_traits@D@__1@std@@@__1@std@@AAEPBDPBD0@Z (this=0xd0044c38, __first=0x98006 "\\s*#include\\s+([\\\\/A-Za-z0-9_\\-\\.]+)", __last=0x9802a "")
    at /home/venom/Sync/xbox_dev/nxdk-nvnetdrv/lib/libcxx/include/regex:4123
#18 0x00011324 in ??$__parse@PBD@?$basic_regex@DU?$regex_traits@D@__1@std@@@__1@std@@AAEPBDPBD0@Z (this=0xd0044c38, __first=0x98006 "\\s*#include\\s+([\\\\/A-Za-z0-9_\\-\\.]+)", __last=0x9802a "")
    at /home/venom/Sync/xbox_dev/nxdk-nvnetdrv/lib/libcxx/include/regex:3073
#19 0x00011153 in ??0?$basic_regex@DU?$regex_traits@D@__1@std@@@__1@std@@QAE@PBDW4syntax_option_type@regex_constants@12@@Z (this=0xd0044c38, __p=0x98006 "\\s*#include\\s+([\\\\/A-Za-z0-9_\\-\\.]+)", 
    __f=std::__1::regex_constants::ECMAScript) at /home/venom/Sync/xbox_dev/nxdk-nvnetdrv/lib/libcxx/include/regex:2544
#20 0x0001104e in main () at /home/venom/Sync/xbox_dev/nxdk-nvnetdrv/samples/hello++/main.cpp:13
#21 0x0009645a in main_wrapper (unused_param=0x0) at /home/venom/Sync/xbox_dev/nxdk-nvnetdrv/lib/pdclib/platform/xbox/crt0.c:43
#22 0x000967b6 in _thread_wrapper@4 (lpThreadParameter=0x2f0008) at /home/venom/Sync/xbox_dev/nxdk-nvnetdrv/lib/pdclib/platform/xbox/functions/threads/thrd_create.c:21
#23 0x0006c1a6 in _WinapiThreadStartup@8 (StartRoutine=0x96780 <_thread_wrapper@4>, StartContext=0x2f0008) at /home/venom/Sync/xbox_dev/nxdk-nvnetdrv/lib/winapi/thread.c:58
#24 0x80026df4 in ?? ()
(gdb) q

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants