← Quiz: Command Injection and Path Traversal: all 10 questions
Quiz: Command Injection and Path Traversal · Question 2 of 10
Which call is the safe way to run ping with a user-supplied host in Python?
Which call is the safe way to run ping with a user-supplied host in Python?
- A.os.system("ping -c 1 " + host)
- B.subprocess.run(f"ping -c 1 {host}", shell=True)
- C.subprocess.run(["ping", "-c", "1", host])
- D.eval("ping " + host)
Answer & explanation
Correct answer: subprocess.run(["ping", "-c", "1", host])
A list of arguments starts the program directly, and host stays a single argument.
Can you get the rest right without peeking?
Take the timed Quiz: Command Injection and Path Traversal quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →