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

NameError: global name 'numb' is not defined #974

Closed
rofl0r opened this issue May 5, 2017 · 21 comments
Closed

NameError: global name 'numb' is not defined #974

rofl0r opened this issue May 5, 2017 · 21 comments
Assignees
Labels
Milestone

Comments

@rofl0r
Copy link

rofl0r commented May 5, 2017

Traceback (most recent call last):
  File "foo.py", line 907, in <module>
    inp = sys.stdin.readline().strip().decode('utf-8')
  File "/lib/python2.7/site-packages/pwnlib/term/readline.py", line 412, in readline
    return readline(size)
  File "/lib/python2.7/site-packages/pwnlib/term/readline.py", line 376, in readline
    keymap.handle_input()
  File "/lib/python2.7/site-packages/pwnlib/term/keymap.py", line 20, in handle_input
    self.send(key.get())
  File "/lib/python2.7/site-packages/pwnlib/term/key.py", line 164, in get
    k = _peek()
  File "/lib/python2.7/site-packages/pwnlib/term/key.py", line 159, in _peek
    return _peek_ti() or _peek_csi() or _peek_simple()
  File "/lib/python2.7/site-packages/pwnlib/term/key.py", line 393, in _peek_csi
    return _peekkey_ss3(2)
  File "/lib/python2.7/site-packages/pwnlib/term/key.py", line 372, in _peekkey_ss3
    _cbuf = _cbuf[numb:] # XXX: numb is not defined
NameError: global name 'numb' is not defined

this happens when i press + and enter on the numeric block without having numlock on.
also kinda weird even that this is handled by pwnlib, since i call a function from sys.

@rofl0r
Copy link
Author

rofl0r commented May 5, 2017

from that point on stdin is dead, any try to access it causes this exception, even if caught.

@rofl0r
Copy link
Author

rofl0r commented May 5, 2017

this happens quite a lot since sometimes when i enter a command into my program i instinctively hit enter on the numpad. from that point on my application becomes unusable and i have to kill it. no workaround found so far.

@zachriggle
Copy link
Member

I can't reproduce this. Please provide steps that I can reproduce in the docker image.

>>> from pwn import *
>>> inp = sys.stdin.readline().strip().decode('utf-8')
asdfasdfasdf
>>> inp
u'asdfasdfasdf'

To run in Docker:

$ docker pull pwntools/pwntools:stable
$ docker run -it pwntools/pwntools:stable
pwntools@e5bc67ee7449:~$ python
Python 2.7.12 (default, Nov 19 2016, 06:48:10)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from pwn import *
>>> sys.stdin.readline().strip().decode("utf-8")
Hello, world!
u'Hello, world!'

@zachriggle zachriggle added the bug label May 5, 2017
@zachriggle zachriggle self-assigned this May 5, 2017
@zachriggle zachriggle added this to the Someday milestone May 5, 2017
@rofl0r
Copy link
Author

rofl0r commented May 5, 2017

this causes the bug for me:
test.py

from pwn import *
import sys

inp = sys.stdin.readline().strip().decode('utf-8')

python test.py
hit + on numeric block with numlock off

i'm sorry but i cannot use docker, since my custom linux distribution based on musl libc doesn't yet bundle a go compiler. but even if it's not reproducible on a mainstream distro, the bug is real as can be seen from the fat XXX in the comment...

@rofl0r
Copy link
Author

rofl0r commented May 5, 2017

note that i cannot reproduce the issue either in an interactive python session - it must be run from a script

@rofl0r
Copy link
Author

rofl0r commented May 5, 2017

a member of my team just tried it on debian, and he was able to reproduce the issue running the above script. sigh of relief

@zachriggle
Copy link
Member

I still cannot reproduce this on either macOS or Ubuntu 16.04.

$ pwn update
[*] You have the latest version of Pwntools (3.5.1)
$ cat x.py
from pwn import *
import sys

inp = sys.stdin.readline().strip().decode('utf-8')
print(repr(inp))
$ python x.py
asdfasdfasdf
u'asdfasdfasdf'

@zachriggle
Copy link
Member

I don't have any computers with a full keyboard, so no number pad to hit the + key on, or to turn NumLock off.

@rofl0r
Copy link
Author

rofl0r commented May 5, 2017

it should be sufficient to just hit "+" on numeric block. my friends debian version is

$ cat /etc/debian_version
8.5

@rofl0r
Copy link
Author

rofl0r commented May 5, 2017

damn, in that case i guess you won't be able to reproduce it! no usb keyboard lying around somewhere ?

@zachriggle
Copy link
Member

Nope! :-\

@zachriggle
Copy link
Member

In any case, this is in the term code which I don't touch.

@zachriggle zachriggle assigned br0ns and unassigned zachriggle May 5, 2017
@zachriggle
Copy link
Member

It looks like that code (minus the XXX warning, which was added later) comes from ab3d128

commit ab3d128a776ec29faf281f33644fecdb32e79d3e
Author: Morten Brøns-Pedersen <[email protected]>
Date:   Wed Apr 30 14:30:21 2014 +0200

    started working on pwnlib v. 2.0

@rofl0r
Copy link
Author

rofl0r commented May 6, 2017

hey @br0ns , do you have an idea why this code is interfering with my invocation of sys code ? this looks like quite a nasty hook to me.

@zachriggle
Copy link
Member

zachriggle commented May 7, 2017 via email

@rofl0r
Copy link
Author

rofl0r commented May 7, 2017

thanks! when looking at the issues/PRs here, i have the feeling that assigning @br0ns to a task is about the same as closing it with EWONTFIX.. :)

@rofl0r
Copy link
Author

rofl0r commented May 7, 2017

@zachriggle: is there a way to set this from code, rather than changing the environment or script args ? i'd rather do context.term_mode = False in my code and have the issue fixed once and for all, than having to start my program from a shell wrapper so i dont forget to set the env var.

@zachriggle
Copy link
Member

zachriggle commented May 7, 2017 via email

br0ns added a commit to br0ns/pwntools that referenced this issue May 10, 2017
@br0ns
Copy link
Contributor

br0ns commented May 10, 2017

I've made a PR with an attempt at a fix: #978

The code is based on libtermkey.

zachriggle pushed a commit to zachriggle/pwntools that referenced this issue May 10, 2017
@rofl0r
Copy link
Author

rofl0r commented May 10, 2017

cool! i confirm that the issue is now fixed. if numlock is off, and "+" is being pressed "+k" is shown in the terminal instead of crashing. thank you!

zachriggle added a commit that referenced this issue May 10, 2017
@zachriggle
Copy link
Member

Merged to stable in #979; this fix will be in 3.6.1

rofl0r added a commit to sabotage-linux/sabotage that referenced this issue May 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants