Skip to content

Commit de5a105

Browse files
committed
always log SecurityExceptions
1 parent ec6c86d commit de5a105

3 files changed

Lines changed: 152 additions & 83 deletions

File tree

FlashpointSecurePlayer/EnvironmentVariables.cs

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,12 @@ private string GetValue(EnvironmentVariablesElement environmentVariablesElement)
4949

5050
try {
5151
value = Environment.GetEnvironmentVariable(environmentVariablesElement.Name, EnvironmentVariableTarget.Process);
52-
} catch (ArgumentException) {
53-
throw new InvalidEnvironmentVariablesException("Failed to get the \"" + environmentVariablesElement.Name + "\" Environment Variable.");
54-
} catch (SecurityException) {
52+
} catch (SecurityException ex) {
53+
LogExceptionToLauncher(ex);
5554
throw new TaskRequiresElevationException("Getting the \"" + environmentVariablesElement.Name + "\" Environment Variable requires elevation.");
55+
} catch (Exception ex) {
56+
LogExceptionToLauncher(ex);
57+
throw new InvalidEnvironmentVariablesException("Failed to get the \"" + environmentVariablesElement.Name + "\" Environment Variable.");
5658
}
5759

5860
Regex regex = null;
@@ -112,10 +114,12 @@ private string GetValue(EnvironmentVariablesElement environmentVariablesElement)
112114
try {
113115
// we need to find the compatibility layers so we can check later if the ones we want are already set
114116
compatibilityLayerValue = Environment.GetEnvironmentVariable(__COMPAT_LAYER, EnvironmentVariableTarget.Process);
115-
} catch (ArgumentException) {
116-
throw new InvalidEnvironmentVariablesException("Failed to get the \"" + __COMPAT_LAYER + "\" Environment Variable.");
117-
} catch (SecurityException) {
117+
} catch (SecurityException ex) {
118+
LogExceptionToLauncher(ex);
118119
throw new TaskRequiresElevationException("Getting the \"" + __COMPAT_LAYER + "\" Environment Variable requires elevation.");
120+
} catch (Exception ex) {
121+
LogExceptionToLauncher(ex);
122+
throw new InvalidEnvironmentVariablesException("Failed to get the \"" + __COMPAT_LAYER + "\" Environment Variable.");
119123
}
120124

121125
ProgressManager.CurrentGoal.Start(modificationsElement.EnvironmentVariables.Count + modificationsElement.EnvironmentVariables.Count);
@@ -146,10 +150,12 @@ private string GetValue(EnvironmentVariablesElement environmentVariablesElement)
146150
Find = environmentVariablesElement.Find,
147151
Value = Environment.GetEnvironmentVariable(environmentVariablesElement.Name, EnvironmentVariableTarget.Process)
148152
};
149-
} catch (ArgumentException) {
150-
throw new InvalidEnvironmentVariablesException("Failed to get the \"" + environmentVariablesElement.Name + "\" Environment Variable.");
151-
} catch (SecurityException) {
153+
} catch (SecurityException ex) {
154+
LogExceptionToLauncher(ex);
152155
throw new TaskRequiresElevationException("Getting the \"" + environmentVariablesElement.Name + "\" Environment Variable requires elevation.");
156+
} catch (Exception ex) {
157+
LogExceptionToLauncher(ex);
158+
throw new InvalidEnvironmentVariablesException("Failed to get the \"" + environmentVariablesElement.Name + "\" Environment Variable.");
153159
}
154160

155161
activeModificationsElement.EnvironmentVariables.Set(activeEnvironmentVariablesElement);
@@ -178,10 +184,12 @@ private string GetValue(EnvironmentVariablesElement environmentVariablesElement)
178184

179185
try {
180186
Environment.SetEnvironmentVariable(environmentVariablesElement.Name, Environment.ExpandEnvironmentVariables(value), EnvironmentVariableTarget.Process);
181-
} catch (ArgumentException) {
182-
throw new InvalidEnvironmentVariablesException("Failed to set the \"" + environmentVariablesElement.Name + "\" Environment Variable.");
183-
} catch (SecurityException) {
187+
} catch (SecurityException ex) {
188+
LogExceptionToLauncher(ex);
184189
throw new TaskRequiresElevationException("Setting the \"" + environmentVariablesElement.Name + "\" Environment Variable requires elevation.");
190+
} catch (Exception ex) {
191+
LogExceptionToLauncher(ex);
192+
throw new InvalidEnvironmentVariablesException("Failed to set the \"" + environmentVariablesElement.Name + "\" Environment Variable.");
185193
}
186194

187195
// now throw up a restart in Web Browser Mode for Compatibility Settings
@@ -267,10 +275,12 @@ public void Deactivate(MODIFICATIONS_REVERT_METHOD modificationsRevertMethod = M
267275
// compatibility settings
268276
try {
269277
compatibilityLayerValue = Environment.GetEnvironmentVariable(__COMPAT_LAYER, EnvironmentVariableTarget.Process);
270-
} catch (ArgumentException) {
271-
throw new InvalidEnvironmentVariablesException("Failed to get the \"" + __COMPAT_LAYER + "\" Environment Variable.");
272-
} catch (SecurityException) {
278+
} catch (SecurityException ex) {
279+
LogExceptionToLauncher(ex);
273280
throw new TaskRequiresElevationException("Getting the \"" + __COMPAT_LAYER + "\" Environment Variable requires elevation.");
281+
} catch (Exception ex) {
282+
LogExceptionToLauncher(ex);
283+
throw new InvalidEnvironmentVariablesException("Failed to get the \"" + __COMPAT_LAYER + "\" Environment Variable.");
274284
}
275285

276286
// we get this right away here
@@ -307,10 +317,12 @@ public void Deactivate(MODIFICATIONS_REVERT_METHOD modificationsRevertMethod = M
307317
if (modificationsRevertMethod == MODIFICATIONS_REVERT_METHOD.DELETE_ALL) {
308318
try {
309319
Environment.SetEnvironmentVariable(activeEnvironmentVariablesElement.Name, null, EnvironmentVariableTarget.Process);
310-
} catch (ArgumentException) {
311-
throw new InvalidEnvironmentVariablesException("Failed to delete the \"" + environmentVariablesElement.Name + "\" Environment Variable.");
312-
} catch (SecurityException) {
320+
} catch (SecurityException ex) {
321+
LogExceptionToLauncher(ex);
313322
throw new TaskRequiresElevationException("Deleting the \"" + environmentVariablesElement.Name + "\" Environment Variable requires elevation.");
323+
} catch (Exception ex) {
324+
LogExceptionToLauncher(ex);
325+
throw new InvalidEnvironmentVariablesException("Failed to delete the \"" + environmentVariablesElement.Name + "\" Environment Variable.");
314326
}
315327
} else {
316328
// don't reset Compatibility Settings if we're restarting for Web Browser Mode
@@ -320,10 +332,12 @@ public void Deactivate(MODIFICATIONS_REVERT_METHOD modificationsRevertMethod = M
320332
|| modeElement.Name != ModeElement.NAME.WEB_BROWSER) {
321333
try {
322334
Environment.SetEnvironmentVariable(activeEnvironmentVariablesElement.Name, activeEnvironmentVariablesElement.Value, EnvironmentVariableTarget.Process);
323-
} catch (ArgumentException) {
324-
throw new InvalidEnvironmentVariablesException("Failed to set the \"" + environmentVariablesElement.Name + "\" Environment Variable.");
325-
} catch (SecurityException) {
335+
} catch (SecurityException ex) {
336+
LogExceptionToLauncher(ex);
326337
throw new TaskRequiresElevationException("Setting the \"" + environmentVariablesElement.Name + "\" Environment Variable requires elevation.");
338+
} catch (Exception ex) {
339+
LogExceptionToLauncher(ex);
340+
throw new InvalidEnvironmentVariablesException("Failed to set the \"" + environmentVariablesElement.Name + "\" Environment Variable.");
327341
}
328342
}
329343
}

FlashpointSecurePlayer/FlashpointSecurePlayerGUI.cs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1445,11 +1445,14 @@ await ImportActiveXAsync(delegate (string text) {
14451445

14461446
try {
14471447
fullHTDOCSFilePath = Path.GetFullPath(htdocsFilePath);
1448-
} catch (PathTooLongException) {
1449-
throw new ArgumentException("The path is too long to \"" + htdocsFilePath + "\".");
1450-
} catch (SecurityException) {
1448+
} catch (SecurityException ex) {
1449+
LogExceptionToLauncher(ex);
14511450
throw new TaskRequiresElevationException("Getting the Full Path to \"" + htdocsFilePath + "\" requires elevation.");
1452-
} catch (NotSupportedException) {
1451+
} catch (PathTooLongException ex) {
1452+
LogExceptionToLauncher(ex);
1453+
throw new ArgumentException("The path is too long to \"" + htdocsFilePath + "\".");
1454+
} catch (NotSupportedException ex) {
1455+
LogExceptionToLauncher(ex);
14531456
throw new ArgumentException("The path \"" + htdocsFilePath + "\" is not supported.");
14541457
}
14551458

@@ -1482,13 +1485,13 @@ await ImportActiveXAsync(delegate (string text) {
14821485
Environment.SetEnvironmentVariable(FP_ARGUMENTS, String.IsNullOrEmpty(Arguments) ? " " : Arguments, EnvironmentVariableTarget.Process);
14831486
Environment.SetEnvironmentVariable(FP_HTDOCS_FILE, String.IsNullOrEmpty(htdocsFile) ? " " : htdocsFile, EnvironmentVariableTarget.Process);
14841487
Environment.SetEnvironmentVariable(FP_HTDOCS_FILE_DIR, String.IsNullOrEmpty(htdocsFileDirectory) ? " " : htdocsFileDirectory, EnvironmentVariableTarget.Process);
1485-
} catch (ArgumentException ex) {
1486-
LogExceptionToLauncher(ex);
1487-
Application.Exit();
1488-
return;
14891488
} catch (SecurityException ex) {
14901489
LogExceptionToLauncher(ex);
14911490
throw new TaskRequiresElevationException("Setting the Environment Variables requires elevation.");
1491+
} catch (Exception ex) {
1492+
LogExceptionToLauncher(ex);
1493+
Application.Exit();
1494+
return;
14921495
}
14931496

14941497
ProgressManager.ShowOutput();
@@ -1521,6 +1524,9 @@ await ImportActiveXAsync(delegate (string text) {
15211524
Application.Exit();
15221525
return;
15231526
}
1527+
} catch (ArgumentException ex) {
1528+
LogExceptionToLauncher(ex);
1529+
Application.Exit();
15241530
}
15251531
}
15261532

0 commit comments

Comments
 (0)