Skip to content

Commit

Permalink
Fix stack corruption in ui_read
Browse files Browse the repository at this point in the history
This is an alternative to #20893

Additionally this fixes also a possible issue in UI_UTIL_read_pw:

When UI_new returns NULL, the result code would still be zero
as if UI_UTIL_read_pw succeeded, but the password buffer is left
uninitialized, with subsequent possible stack corruption or worse.

Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from #20957)

(cherry picked from commit a64c48c)
  • Loading branch information
bernd-edlinger authored and t8m committed May 17, 2023
1 parent 8ddacec commit 0f90c4d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 4 additions & 0 deletions crypto/ui/ui_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,10 @@ int UI_process(UI *ui)
ok = 0;
break;
}
} else {
ui->flags &= ~UI_FLAG_REDOABLE;
ok = -2;
goto err;
}
}

Expand Down
4 changes: 1 addition & 3 deletions crypto/ui/ui_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ int UI_UTIL_read_pw_string(char *buf, int length, const char *prompt,
int UI_UTIL_read_pw(char *buf, char *buff, int size, const char *prompt,
int verify)
{
int ok = 0;
int ok = -2;
UI *ui;

if (size < 1)
Expand All @@ -47,8 +47,6 @@ int UI_UTIL_read_pw(char *buf, char *buff, int size, const char *prompt,
ok = UI_process(ui);
UI_free(ui);
}
if (ok > 0)
ok = 0;
return ok;
}

Expand Down

0 comments on commit 0f90c4d

Please sign in to comment.