Skip to content

Commit

Permalink
Consolidate raising errors in SSL_CONF_cmd()
Browse files Browse the repository at this point in the history
Reviewed-by: Neil Horman <nhorman@openssl.org>
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
(Merged from #23048)

(cherry picked from commit 430dcbd)
  • Loading branch information
t8m committed Dec 19, 2023
1 parent 3f67f86 commit f21f02e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
24 changes: 16 additions & 8 deletions ssl/ssl_conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -870,9 +870,12 @@ static int ctrl_switch_option(SSL_CONF_CTX *cctx, const ssl_conf_cmd_tbl * cmd)
/* Find index of command in table */
size_t idx = cmd - ssl_conf_cmds;
const ssl_switch_tbl *scmd;

/* Sanity check index */
if (idx >= OSSL_NELEM(ssl_cmd_switches))
if (idx >= OSSL_NELEM(ssl_cmd_switches)) {
ERR_raise(ERR_LIB_SSL, ERR_R_INTERNAL_ERROR);
return 0;
}
/* Obtain switches entry with same index */
scmd = ssl_cmd_switches + idx;
ssl_set_option(cctx, scmd->name_flags, scmd->option_value, 1);
Expand All @@ -888,28 +891,33 @@ int SSL_CONF_cmd(SSL_CONF_CTX *cctx, const char *cmd, const char *value)
}

if (!ssl_conf_cmd_skip_prefix(cctx, &cmd))
return -2;
goto unknown_cmd;

runcmd = ssl_conf_cmd_lookup(cctx, cmd);

if (runcmd) {
int rv;
int rv = -3;

if (runcmd->value_type == SSL_CONF_TYPE_NONE) {
return ctrl_switch_option(cctx, runcmd);
}
if (value == NULL)
return -3;
goto bad_value;
rv = runcmd->cmd(cctx, value);
if (rv > 0)
return 2;
if (rv == -2)
return -2;
if (rv != -2)
rv = 0;

bad_value:
if (cctx->flags & SSL_CONF_FLAG_SHOW_ERRORS)
ERR_raise_data(ERR_LIB_SSL, SSL_R_BAD_VALUE,
"cmd=%s, value=%s", cmd, value);
return 0;
"cmd=%s, value=%s", cmd,
value != NULL ? value : "<EMPTY>");
return rv;
}

unknown_cmd:
if (cctx->flags & SSL_CONF_FLAG_SHOW_ERRORS)
ERR_raise_data(ERR_LIB_SSL, SSL_R_UNKNOWN_CMD_NAME, "cmd=%s", cmd);

Expand Down
7 changes: 1 addition & 6 deletions ssl/ssl_mcnf.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,8 @@ static int ssl_do_config(SSL *s, SSL_CTX *ctx, const char *name, int system)

conf_ssl_get_cmd(cmds, i, &cmdstr, &arg);
rv = SSL_CONF_cmd(cctx, cmdstr, arg);
if (rv <= 0) {
int errcode = rv == -2 ? SSL_R_UNKNOWN_COMMAND : SSL_R_BAD_VALUE;

ERR_raise_data(ERR_LIB_SSL, errcode,
"section=%s, cmd=%s, arg=%s", name, cmdstr, arg);
if (rv <= 0)
++err;
}
}
if (!SSL_CONF_CTX_finish(cctx))
++err;
Expand Down

0 comments on commit f21f02e

Please sign in to comment.