Repository: pwndbg/pwndbg

Issue:
Exceptions when running from folder with space and number in name
### Description

When debugging an application in a folder with a name that includes a space followed by `0<digit>`, a Python traceback is triggered on seemingly every command.

What I think is happening is that pwndbg runs the "info auxv" command in the background every time the user enters a command, and a regular expression in `auxv.py` incorrectly parses the "File name of executable" line, which in this case looks something like this:
```
31   AT_EXECFN            File name of executable        0x7fffffffefde "/home/user/test/x 01/test"
```
There are probably other file- and folder-name patterns that can result in this behavior, too.

### Steps to reproduce

- Make a folder named, for example, "x 01"
- Put any debuggable binary in it (even a basic hello-world works)
- Open it in gdb
- Type "r" to run
- Every gdb command run while the binary is running will now trigger a Python traceback

Here's a full example session that shows everything (sorry that it's kind of long):
```
$ pwd
/home/user/test/x 01
$ cat test.c
#include <stdio.h>
#include <stdlib.h>

void main()
{
    printf("Hello world\n");
    getchar();
}
$ gcc -o test test.c
$ gdb test
GNU gdb (Ubuntu 9.2-0ubuntu1~20.04) 9.2
Copyright (C) 2020 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-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"...
pwndbg: loaded 191 commands. Type pwndbg [filter] for a list.
pwndbg: created $rebase, $ida gdb functions (can be used with print/break)
Reading symbols from test...
(No debugging symbols found in test)
pwndbg> r
Starting program: /home/user/test/x 01/test
Hello world
^C
Program received signal SIGINT, Interrupt.
0x00007ffff7ebe142 in __GI___libc_read (fd=0, buf=0x5555555596b0, nbytes=1024) at ../sysdeps/unix/sysv/linux/read.c:26
26      ../sysdeps/unix/sysv/linux/read.c: No such file or directory.
Exception occurred: Error: invalid literal for int() with base 0: '01' (<class 'ValueError'>)
For more info invoke `set exception-verbose on` and rerun the command
or debug it by yourself with `set exception-debugger on`
Python Exception <class 'ValueError'> invalid literal for int() with base 0: '01':
Exception occurred: Error: invalid literal for int() with base 0: '01' (<class 'ValueError'>)
For more info invoke `set exception-verbose on` and rerun the command
or debug it by yourself with `set exception-debugger on`
Python Exception <class 'ValueError'> invalid literal for int() with base 0: '01':
Exception occurred: Error: invalid literal for int() with base 0: '01' (<class 'ValueError'>)
For more info invoke `set exception-verbose on` and rerun the command
or debug it by yourself with `set exception-debugger on`
Python Exception <class 'ValueError'> invalid literal for int() with base 0: '01':
pwndbg> set exception-debugger on
Set whether to debug exceptions raised in Pwndbg commands to True
Traceback (most recent call last):
  File "/home/user/pwndbg/pwndbg/pwndbg/events.py", line 165, in caller
    func()
  File "/home/user/pwndbg/pwndbg/pwndbg/memoize.py", line 44, in __call__
    value = self.func(*args, **kwargs)
  File "/home/user/pwndbg/pwndbg/pwndbg/stack.py", line 79, in update
    page  = pwndbg.memory.Page(start, stop-start, 6 if not is_executable() else 7, 0, '[stack]')
  File "/home/user/pwndbg/pwndbg/pwndbg/memoize.py", line 44, in __call__
    value = self.func(*args, **kwargs)
  File "/home/user/pwndbg/pwndbg/pwndbg/stack.py", line 127, in is_executable
    ehdr         = pwndbg.elf.exe()
  File "/home/user/pwndbg/pwndbg/pwndbg/proc.py", line 71, in wrapper
    return func(*a, **kw)
  File "/home/user/pwndbg/pwndbg/pwndbg/memoize.py", line 44, in __call__
    value = self.func(*args, **kwargs)
  File "/home/user/pwndbg/pwndbg/pwndbg/elf.py", line 180, in exe
    e = entry()
  File "/home/user/pwndbg/pwndbg/pwndbg/proc.py", line 71, in wrapper
    return func(*a, **kw)
  File "/home/user/pwndbg/pwndbg/pwndbg/memoize.py", line 44, in __call__
    value = self.func(*args, **kwargs)
  File "/home/user/pwndbg/pwndbg/pwndbg/elf.py", line 191, in entry
    entry = pwndbg.auxv.get().AT_ENTRY
  File "/home/user/pwndbg/pwndbg/pwndbg/memoize.py", line 44, in __call__
    value = self.func(*args, **kwargs)
  File "/home/user/pwndbg/pwndbg/pwndbg/auxv.py", line 106, in get
    return use_info_auxv() or walk_stack() or AUXV()
  File "/home/user/pwndbg/pwndbg/pwndbg/auxv.py", line 121, in use_info_auxv
    const, value = int(match.group(1)), int(match.group(2), 0)
ValueError: invalid literal for int() with base 0: '01'

If that is an issue, you can report it on https://github.com/pwndbg/pwndbg/issues
(Please don't forget to search if it hasn't been reported before)                                                                                    
To generate the report and open a browser, you may run `bugreport --run-browser`
PS: Pull requests are welcome                                                                                                                        
> /home/user/pwndbg/pwndbg/pwndbg/auxv.py(121)use_info_auxv()
-> const, value = int(match.group(1)), int(match.group(2), 0)
(Pdb) q
Traceback (most recent call last):
  File "/home/user/pwndbg/pwndbg/pwndbg/prompt.py", line 33, in prompt_hook
    pwndbg.events.after_reload(start=False)
  File "/home/user/pwndbg/pwndbg/pwndbg/events.py", line 216, in after_reload
    f()
  File "/home/user/pwndbg/pwndbg/pwndbg/events.py", line 169, in caller
    raise e
  File "/home/user/pwndbg/pwndbg/pwndbg/events.py", line 165, in caller
    func()
  File "/home/user/pwndbg/pwndbg/pwndbg/memoize.py", line 44, in __call__
    value = self.func(*args, **kwargs)
  File "/home/user/pwndbg/pwndbg/pwndbg/stack.py", line 79, in update
    page  = pwndbg.memory.Page(start, stop-start, 6 if not is_executable() else 7, 0, '[stack]')
  File "/home/user/pwndbg/pwndbg/pwndbg/memoize.py", line 44, in __call__
    value = self.func(*args, **kwargs)
  File "/home/user/pwndbg/pwndbg/pwndbg/stack.py", line 127, in is_executable
    ehdr         = pwndbg.elf.exe()
  File "/home/user/pwndbg/pwndbg/pwndbg/proc.py", line 71, in wrapper
    return func(*a, **kw)
  File "/home/user/pwndbg/pwndbg/pwndbg/memoize.py", line 44, in __call__
    value = self.func(*args, **kwargs)
  File "/home/user/pwndbg/pwndbg/pwndbg/elf.py", line 180, in exe
    e = entry()
  File "/home/user/pwndbg/pwndbg/pwndbg/proc.py", line 71, in wrapper
    return func(*a, **kw)
  File "/home/user/pwndbg/pwndbg/pwndbg/memoize.py", line 44, in __call__
    value = self.func(*args, **kwargs)
  File "/home/user/pwndbg/pwndbg/pwndbg/elf.py", line 191, in entry
    entry = pwndbg.auxv.get().AT_ENTRY
  File "/home/user/pwndbg/pwndbg/pwndbg/memoize.py", line 44, in __call__
    value = self.func(*args, **kwargs)
  File "/home/user/pwndbg/pwndbg/pwndbg/auxv.py", line 106, in get
    return use_info_auxv() or walk_stack() or AUXV()
  File "/home/user/pwndbg/pwndbg/pwndbg/auxv.py", line 121, in use_info_auxv
    const, value = int(match.group(1)), int(match.group(2), 0)
ValueError: invalid literal for int() with base 0: '01'
pwndbg> info auxv
33   AT_SYSINFO_EHDR      System-supplied DSO's ELF header 0x7ffff7fce000
16   AT_HWCAP             Machine-dependent CPU capability hints 0xbfebfbff
6    AT_PAGESZ            System page size               4096
17   AT_CLKTCK            Frequency of times()           100
3    AT_PHDR              Program headers for program    0x555555554040
4    AT_PHENT             Size of program header entry   56
5    AT_PHNUM             Number of program headers      13
7    AT_BASE              Base address of interpreter    0x7ffff7fcf000
8    AT_FLAGS             Flags                          0x0
9    AT_ENTRY             Entry point of program         0x555555555080
11   AT_UID               Real user ID                   1000
12   AT_EUID              Effective user ID              1000
13   AT_GID               Real group ID                  1001
14   AT_EGID              Effective group ID             1001
23   AT_SECURE            Boolean, was exec setuid-like? 0
25   AT_RANDOM            Address of 16 random bytes     0x7fffffffdff9
26   AT_HWCAP2            Extension of AT_HWCAP          0x0
31   AT_EXECFN            File name of executable        0x7fffffffefde "/home/user/test/x 01/test"
15   AT_PLATFORM          String identifying platform    0x7fffffffe009 "x86_64"
0    AT_NULL              End of vector                  0x0
Traceback (most recent call last):
  File "/home/user/pwndbg/pwndbg/pwndbg/events.py", line 165, in caller
    func()
  File "/home/user/pwndbg/pwndbg/pwndbg/memoize.py", line 44, in __call__
    value = self.func(*args, **kwargs)
  File "/home/user/pwndbg/pwndbg/pwndbg/stack.py", line 79, in update
    page  = pwndbg.memory.Page(start, stop-start, 6 if not is_executable() else 7, 0, '[stack]')
  File "/home/user/pwndbg/pwndbg/pwndbg/memoize.py", line 44, in __call__
    value = self.func(*args, **kwargs)
  File "/home/user/pwndbg/pwndbg/pwndbg/stack.py", line 127, in is_executable
    ehdr         = pwndbg.elf.exe()
  File "/home/user/pwndbg/pwndbg/pwndbg/proc.py", line 71, in wrapper
    return func(*a, **kw)
  File "/home/user/pwndbg/pwndbg/pwndbg/memoize.py", line 44, in __call__
    value = self.func(*args, **kwargs)
  File "/home/user/pwndbg/pwndbg/pwndbg/elf.py", line 180, in exe
    e = entry()
  File "/home/user/pwndbg/pwndbg/pwndbg/proc.py", line 71, in wrapper
    return func(*a, **kw)
  File "/home/user/pwndbg/pwndbg/pwndbg/memoize.py", line 44, in __call__
    value = self.func(*args, **kwargs)
  File "/home/user/pwndbg/pwndbg/pwndbg/elf.py", line 191, in entry
    entry = pwndbg.auxv.get().AT_ENTRY
  File "/home/user/pwndbg/pwndbg/pwndbg/memoize.py", line 44, in __call__
    value = self.func(*args, **kwargs)
  File "/home/user/pwndbg/pwndbg/pwndbg/auxv.py", line 106, in get
    return use_info_auxv() or walk_stack() or AUXV()
  File "/home/user/pwndbg/pwndbg/pwndbg/auxv.py", line 121, in use_info_auxv
    const, value = int(match.group(1)), int(match.group(2), 0)
ValueError: invalid literal for int() with base 0: '01'

> /home/user/pwndbg/pwndbg/pwndbg/auxv.py(121)use_info_auxv()
-> const, value = int(match.group(1)), int(match.group(2), 0)
(Pdb) 
```


### My setup

<!--
Show us your gdb/python/pwndbg/OS/IDA Pro version (depending on your case).

NOTE: We are currently supporting only Ubuntu installations.
It is known that pwndbg is not fully working e.g. on Arch Linux (the heap stuff is not working there).
If you would like to change this situation - help us improving pwndbg and supporting other distros!

This can be displayed in pwndbg through `version` command.

If it is somehow unavailable, use:
* `show version` - for gdb
* `py import sys; print(sys.version)` - for python
* pwndbg version/git commit id
-->

Platform: Linux-5.4.0-53-generic-x86_64-with-glibc2.29
Gdb:      9.2
Python:   3.8.5 (default, Jul 28 2020, 12:59:40)  [GCC 9.3.0]
Pwndbg:   1.1.0 build: 29f962c
Capstone: 4.0.1024
Unicorn:  1.0.2
This GDB was configured as follows:
   configure --host=x86_64-linux-gnu --target=x86_64-linux-gnu
             --with-auto-load-dir=$debugdir:$datadir/auto-load
             --with-auto-load-safe-path=$debugdir:$datadir/auto-load
             --with-expat
             --with-gdb-datadir=/usr/share/gdb (relocatable)
             --with-jit-reader-dir=/usr/lib/gdb (relocatable)
             --without-libunwind-ia64
             --with-lzma
             --with-babeltrace
             --without-intel-pt
             --with-mpfr
             --without-xxhash
             --with-python=/usr (relocatable)
             --without-guile
             --disable-source-highlight
             --with-separate-debug-dir=/usr/lib/debug (relocatable)
             --with-system-gdbinit=/etc/gdb/gdbinit

("Relocatable" means the directory can be moved with the GDB installation
tree, and GDB will still find it.)



Discussion:

Resolving patch:
diff --git a/pwndbg/auxv.py b/pwndbg/auxv.py
--- a/pwndbg/auxv.py
+++ b/pwndbg/auxv.py
@@ -113,7 +113,7 @@ def use_info_auxv():
 
     auxv = AUXV()
     for line in lines:
-        match = re.match('([0-9]+) .* (0x[0-9a-f]+|[0-9]+)', line)
+        match = re.match('([0-9]+) .*? (0x[0-9a-f]+|[0-9]+)', line)
         if not match:
             print("Warning: Skipping auxv entry '{}'".format(line))
             continue


Test patch: