From 16511c1e230b4cf6d958633651002e6d7193ca5c Mon Sep 17 00:00:00 2001 From: Craig Andrews Date: Wed, 18 May 2022 11:19:31 -0400 Subject: [PATCH] Use exit codes between 0 and 255 (inclusive) Shells express exit codes in the range of 0-255. Anything outside of that range is brought into that range by modding it 256. For example: -1 becomes 255 -2 becomes 254 -3 becomes 253 This need to convert exit codes in shell scripts to use dependency check is unexpected and confusing. For that reason, returning exit codes outside of 0-255 is unusual and generally discouraged. Therefore, use exit codes in the 0-255 range. See: https://tldp.org/LDP/abs/html/exit-status.html --- .../java/org/owasp/dependencycheck/App.java | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/cli/src/main/java/org/owasp/dependencycheck/App.java b/cli/src/main/java/org/owasp/dependencycheck/App.java index d15683424f7..020d00f5b57 100644 --- a/cli/src/main/java/org/owasp/dependencycheck/App.java +++ b/cli/src/main/java/org/owasp/dependencycheck/App.java @@ -116,11 +116,11 @@ public int run(String[] args) { } catch (FileNotFoundException ex) { System.err.println(ex.getMessage()); cli.printHelp(); - return -1; + return 1; } catch (ParseException ex) { System.err.println(ex.getMessage()); cli.printHelp(); - return -2; + return 2; } final String verboseLog = cli.getStringArgument(CliParser.ARGUMENT.VERBOSE_LOG); if (verboseLog != null) { @@ -131,19 +131,19 @@ public int run(String[] args) { final String connStr = cli.getStringArgument(CliParser.ARGUMENT.CONNECTION_STRING); if (connStr != null) { LOGGER.error("Unable to purge the database when using a non-default connection string"); - exitCode = -3; + exitCode = 3; } else { try { populateSettings(cli); } catch (InvalidSettingException ex) { LOGGER.error(ex.getMessage()); LOGGER.debug(ERROR_LOADING_PROPERTIES_FILE, ex); - exitCode = -4; + exitCode = 4; return exitCode; } try (Engine engine = new Engine(Engine.Mode.EVIDENCE_PROCESSING, settings)) { if (!engine.purge()) { - exitCode = -7; + exitCode = 7; return exitCode; } } finally { @@ -159,17 +159,17 @@ public int run(String[] args) { } catch (InvalidSettingException ex) { LOGGER.error(ex.getMessage()); LOGGER.debug(ERROR_LOADING_PROPERTIES_FILE, ex); - exitCode = -4; + exitCode = 4; return exitCode; } try { runUpdateOnly(); } catch (UpdateException ex) { LOGGER.error(ex.getMessage(), ex); - exitCode = -8; + exitCode = 8; } catch (DatabaseException ex) { LOGGER.error(ex.getMessage(), ex); - exitCode = -9; + exitCode = 9; } finally { settings.cleanup(); } @@ -179,7 +179,7 @@ public int run(String[] args) { } catch (InvalidSettingException ex) { LOGGER.error(ex.getMessage(), ex); LOGGER.debug(ERROR_LOADING_PROPERTIES_FILE, ex); - exitCode = -4; + exitCode = 4; return exitCode; } try { @@ -193,17 +193,17 @@ public int run(String[] args) { } catch (DatabaseException ex) { LOGGER.error(ex.getMessage()); LOGGER.debug("database exception", ex); - exitCode = -11; + exitCode = 11; } catch (ReportException ex) { LOGGER.error(ex.getMessage()); LOGGER.debug("report exception", ex); - exitCode = -12; + exitCode = 12; } catch (ExceptionCollection ex) { if (ex.isFatal()) { - exitCode = -13; + exitCode = 13; LOGGER.error("One or more fatal errors occurred"); } else { - exitCode = -14; + exitCode = 14; } for (Throwable e : ex.getExceptions()) { if (e.getMessage() != null) { @@ -302,7 +302,7 @@ private int determineReturnCode(Engine engine, float cvssFailScore) { || (v.getCvssV3() != null && v.getCvssV3().getBaseScore() >= cvssFailScore) || (v.getUnscoredSeverity() != null && SeverityUtil.estimateCvssV2(v.getUnscoredSeverity()) >= cvssFailScore) || (cvssFailScore <= 0.0f)) { //safety net to fail on any if for some reason the above misses on 0 - retCode = 1; + retCode = 11; break; } }