🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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?

  1. A.os.system("ping -c 1 " + host)
  2. B.subprocess.run(f"ping -c 1 {host}", shell=True)
  3. C.subprocess.run(["ping", "-c", "1", host])
  4. 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 →