From bcca006c9a92bd251dd8805b71fe66725fbc7f29 Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Mon, 6 May 2019 15:01:21 +0200 Subject: installer: simplify tmpfile cleanup Signed-off-by: Simon Rozman --- installer/serviceevaluation.js | 39 ++++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 21 deletions(-) (limited to 'installer') 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() { -- cgit v1.2.3-59-g8ed1b