🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: SQL Injection: all 10 questions

Quiz: SQL Injection · Question 5 of 10

Which subprocess call is safest for running ping on a user-supplied host?

Which subprocess call is safest for running ping on a user-supplied host?

  1. A.os.system("ping -c 1 " + host)
  2. B.subprocess.run(["ping", "-c", "1", host]) after validating host
  3. C.subprocess.run("ping -c 1 " + host, shell=True)
  4. D.eval("ping " + host)
Answer & explanation

Correct answer: subprocess.run(["ping", "-c", "1", host]) after validating host

A list of arguments with no shell means the host can't add extra commands like ; rm -rf.

Can you get the rest right without peeking?

Take the timed Quiz: SQL Injection quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →