diff options
author | Simon Rozman <simon@rozman.si> | 2019-05-06 15:01:21 +0200 |
---|---|---|
committer | Simon Rozman <simon@rozman.si> | 2019-05-06 16:01:07 +0200 |
commit | bcca006c9a92bd251dd8805b71fe66725fbc7f29 (patch) | |
tree | 77eb23519946743dda0925b951226d017bc5aaf6 /installer/serviceevaluation.js | |
parent | updater: move into manager (diff) | |
download | wireguard-windows-bcca006c9a92bd251dd8805b71fe66725fbc7f29.tar.xz wireguard-windows-bcca006c9a92bd251dd8805b71fe66725fbc7f29.zip |
installer: simplify tmpfile cleanup
Signed-off-by: Simon Rozman <simon@rozman.si>
Diffstat (limited to '')
-rw-r--r-- | installer/serviceevaluation.js | 39 |
1 files changed, 18 insertions, 21 deletions
diff --git a/installer/serviceevaluation.js b/installer/serviceevaluation.js index bf2a700c..4a5b663e 100644 --- a/installer/serviceevaluation.js +++ b/installer/serviceevaluation.js @@ -20,32 +20,29 @@ function logMessage(msg) { function runWithNoWindowFlash(command) { //TODO: Seems pretty unlikely that this temp file is secure... var tmpfile = fso.BuildPath(fso.GetSpecialFolder(2), fso.GetTempName()); - //TODO: Obviously cmd and tmpfile are unescaped here... - var cmd = fso.BuildPath(fso.GetSpecialFolder(1), "cmd.exe") + " /c " + command + " > " + tmpfile; - var ret = wsh.Run(cmd, 0, true); - if (ret != 0) { - logMessage("Command " + cmd + " exited with error " + ret.toString()); - try { - fso.DeleteFile(tmpfile); - } catch (e) {} - return ""; - } - var txt; try { - var file = fso.OpenTextFile(tmpfile, 1); - txt = file.ReadAll(); - file.Close(); - } catch (e) { - logMessage("Unable to read temporary file " + tmpfile + " for command " + cmd + ": " + e.toString()); + //TODO: Obviously cmd and tmpfile are unescaped here... + var cmd = fso.BuildPath(fso.GetSpecialFolder(1), "cmd.exe") + " /c " + command + " > " + tmpfile; + var ret = wsh.Run(cmd, 0, true); + if (ret != 0) { + logMessage("Command " + cmd + " exited with error " + ret.toString()); + return ""; + } + var txt; + try { + var file = fso.OpenTextFile(tmpfile, 1); + txt = file.ReadAll(); + file.Close(); + } catch (e) { + logMessage("Unable to read temporary file " + tmpfile + " for command " + cmd + ": " + e.toString()); + return ""; + } + return txt; + } finally { try { fso.DeleteFile(tmpfile); } catch (e) {} - return ""; } - try { - fso.DeleteFile(tmpfile); - } catch(e) {} - return txt; } function EvaluateWireGuardServices() { |