Skip to content

Commit

Permalink
Use exit codes between 0 and 255 (inclusive)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
candrews committed May 18, 2022
1 parent fdb5c2d commit 16511c1
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions cli/src/main/java/org/owasp/dependencycheck/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 {
Expand All @@ -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();
}
Expand All @@ -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 {
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
}
}
Expand Down

0 comments on commit 16511c1

Please sign in to comment.