James Park
James Park

Reputation: 195

TypeError: execv() arg 2 must contain only strings

so ,in python, when I try to execute the following code.

from subprocess import *
args = "A"*99

args = list(args)
args[ord('A')] = "\x00"
args[ord('B')] = "\x20\x0a\x0d"
proc= Popen(["./input2"]+args,stdin=PIPE,stderr=STDOUT)

I get

TypeError: execv() arg 2 must contain only strings

So I did some research and realize if there is any integer formatted argument in Popen() it will give me the error. But I don't know which argument can possibly be an integer.

FYI: if I comment out

args[ord('A')] = "\x00"
args[ord('B')] = "\x20\x0a\x0d"

this code, the error doesn't appear at all.

Upvotes: 0

Views: 1928

Answers (2)

rhodeo
rhodeo

Reputation: 191

This is more appropriate as a comment, but I don't have enough reps yet. I was going through this challenge and faced the exact problem. Turns out you can simply do a args[ord('A')] = "" to avoid that error.

Upvotes: 2

martin.macko.47
martin.macko.47

Reputation: 897

Arguments to Popen may not contain the NUL char \x00.

For instance this works:

Popen(["/bin/echo", "Hello"])

But this does not:

Popen(["/bin/echo", "Hello\x00"])

Upvotes: 0

Related Questions