mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-05 20:20:07 +00:00
res_crypto: don't modify fname in try_load_key()
"fname" is passed in as a const char *, but strstr() mangles that into a char *, and we were attempting to modify the string in place. This is an unwanted (and undocumented) side-effect. ASTERISK-30213 Change-Id: Ifa36d352aafeb7f9beec3f746332865c7d21e629
This commit is contained in:
committed by
George Joseph
parent
bc9ee15b93
commit
5daf32bb14
@@ -174,18 +174,20 @@ struct ast_key * AST_OPTIONAL_API_NAME(ast_key_get)(const char *kname, int ktype
|
|||||||
static struct ast_key *try_load_key(const char *dir, const char *fname, int ifd, int ofd, int *not2)
|
static struct ast_key *try_load_key(const char *dir, const char *fname, int ifd, int ofd, int *not2)
|
||||||
{
|
{
|
||||||
int ktype = 0, found = 0;
|
int ktype = 0, found = 0;
|
||||||
char *c = NULL, ffname[256];
|
const char *c = NULL;
|
||||||
|
char ffname[256];
|
||||||
unsigned char digest[MD5_DIGEST_LENGTH];
|
unsigned char digest[MD5_DIGEST_LENGTH];
|
||||||
unsigned digestlen;
|
unsigned digestlen;
|
||||||
FILE *f;
|
FILE *f;
|
||||||
EVP_MD_CTX *ctx = NULL;
|
EVP_MD_CTX *ctx = NULL;
|
||||||
struct ast_key *key;
|
struct ast_key *key;
|
||||||
static int notice = 0;
|
static int notice = 0;
|
||||||
|
size_t fnamelen = strlen(fname);
|
||||||
|
|
||||||
/* Make sure its name is a public or private key */
|
/* Make sure its name is a public or private key */
|
||||||
if ((c = strstr(fname, ".pub")) && !strcmp(c, ".pub")) {
|
if (fnamelen > 4 && !strcmp((c = &fname[fnamelen - 4]), ".pub")) {
|
||||||
ktype = AST_KEY_PUBLIC;
|
ktype = AST_KEY_PUBLIC;
|
||||||
} else if ((c = strstr(fname, ".key")) && !strcmp(c, ".key")) {
|
} else if (fnamelen > 4 && !strcmp((c = &fname[fnamelen - 4]), ".key")) {
|
||||||
ktype = AST_KEY_PRIVATE;
|
ktype = AST_KEY_PRIVATE;
|
||||||
} else {
|
} else {
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -244,8 +246,6 @@ static struct ast_key *try_load_key(const char *dir, const char *fname, int ifd,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Make fname just be the normal name now */
|
|
||||||
*c = '\0';
|
|
||||||
if (!key) {
|
if (!key) {
|
||||||
if (!(key = ast_calloc(1, sizeof(*key)))) {
|
if (!(key = ast_calloc(1, sizeof(*key)))) {
|
||||||
fclose(f);
|
fclose(f);
|
||||||
@@ -254,8 +254,8 @@ static struct ast_key *try_load_key(const char *dir, const char *fname, int ifd,
|
|||||||
}
|
}
|
||||||
/* First the filename */
|
/* First the filename */
|
||||||
ast_copy_string(key->fn, ffname, sizeof(key->fn));
|
ast_copy_string(key->fn, ffname, sizeof(key->fn));
|
||||||
/* Then the name */
|
/* Then the name minus the suffix */
|
||||||
ast_copy_string(key->name, fname, sizeof(key->name));
|
snprintf(key->name, sizeof(key->name), "%.*s", (int)(c - fname), fname);
|
||||||
key->ktype = ktype;
|
key->ktype = ktype;
|
||||||
/* Yes, assume we're going to be deleted */
|
/* Yes, assume we're going to be deleted */
|
||||||
key->delme = 1;
|
key->delme = 1;
|
||||||
|
Reference in New Issue
Block a user