Add timeout to run_command_write_fd and replace popen by execvpe 58/179558/6
authorMateusz Moscicki <m.moscicki2@partner.samsung.com>
Wed, 16 May 2018 06:23:00 +0000 (08:23 +0200)
committerMateusz Moscicki <m.moscicki2@partner.samsung.com>
Wed, 30 May 2018 13:00:25 +0000 (15:00 +0200)
commit51cdc2c06af4fc4bcae017a61485a428529a1a02
tree237fbb929e5e22e752fecee999a7ebb9c0655bac
parente80ae266d95e2bba3d9d16a9e7815faf8804fffd
Add timeout to run_command_write_fd and replace popen by execvpe

dump_systemstate runs many external commands. When one hungs,
dump_systemstate will block the crash-worker.

execvpe replaced popen because popen passes command to /bin/sh, and this
can potentially allow to run the malicious command if attacker can
modify the fragment of cmd, e.g:

  void read_file(char *filename)
  {
      ...
      sprintf(buff, "cat %s", filename);
      popen(buff, "r");
      ...
  }

  main()
  {
      char filename[] = "/etc/passwd;rm -rf /";
      read_file(filename);
  }

Change-Id: Id7b37c058869c27d3c4d282d9d2dd30d5b9ec80c
src/dump_systemstate/dump_systemstate.c
src/shared/util.c
src/shared/util.h