res_crypto.c: Gracefully handle potential key filename truncation.

Partially resolves #143.

(cherry picked from commit 97b901a29b)
releases/certified-20.7
Sean Bright 2 years ago committed by Asterisk Development Team
parent 5497b1abe3
commit 99622c35e0

@ -196,7 +196,14 @@ static struct ast_key *try_load_key(const char *dir, const char *fname, int ifd,
}
/* Get actual filename */
snprintf(ffname, sizeof(ffname), "%s/%s", dir, fname);
n = snprintf(ffname, sizeof(ffname), "%s/%s", dir, fname);
if (n >= sizeof(ffname)) {
ast_log(LOG_WARNING,
"Key filenames can be up to %zu bytes long, but the filename for the"
" key we are currently trying to load (%s/%s) is %d bytes long.",
sizeof(ffname) - 1, dir, fname, n);
return NULL;
}
/* Open file */
if (!(f = fopen(ffname, "r"))) {

Loading…
Cancel
Save