<p>George Joseph <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/19421">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span></span><br></pre><div style="white-space:pre-wrap">Approvals:
Joshua Colp: Looks good to me, but someone else must approve
George Joseph: Looks good to me, approved
Friendly Automation: Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_crypto: don't modify fname in try_load_key()<br><br>"fname" is passed in as a const char *, but strstr() mangles that<br>into a char *, and we were attempting to modify the string in place.<br>This is an unwanted (and undocumented) side-effect.<br><br>ASTERISK-30213<br><br>Change-Id: Ifa36d352aafeb7f9beec3f746332865c7d21e629<br>---<br>M res/res_crypto.c<br>1 file changed, 22 insertions(+), 7 deletions(-)<br><br></pre>
<pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/res/res_crypto.c b/res/res_crypto.c</span><br><span>index 82014b6..8d6c536 100644</span><br><span>--- a/res/res_crypto.c</span><br><span>+++ b/res/res_crypto.c</span><br><span>@@ -174,18 +174,20 @@</span><br><span> static struct ast_key *try_load_key(const char *dir, const char *fname, int ifd, int ofd, int *not2)</span><br><span> {</span><br><span> int ktype = 0, found = 0;</span><br><span style="color: hsl(0, 100%, 40%);">- char *c = NULL, ffname[256];</span><br><span style="color: hsl(120, 100%, 40%);">+ const char *c = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ char ffname[256];</span><br><span> unsigned char digest[MD5_DIGEST_LENGTH];</span><br><span> unsigned digestlen;</span><br><span> FILE *f;</span><br><span> EVP_MD_CTX *ctx = NULL;</span><br><span> struct ast_key *key;</span><br><span> static int notice = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ size_t fnamelen = strlen(fname);</span><br><span> </span><br><span> /* Make sure its name is a public or private key */</span><br><span style="color: hsl(0, 100%, 40%);">- if ((c = strstr(fname, ".pub")) && !strcmp(c, ".pub")) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (fnamelen > 4 && !strcmp((c = &fname[fnamelen - 4]), ".pub")) {</span><br><span> ktype = AST_KEY_PUBLIC;</span><br><span style="color: hsl(0, 100%, 40%);">- } else if ((c = strstr(fname, ".key")) && !strcmp(c, ".key")) {</span><br><span style="color: hsl(120, 100%, 40%);">+ } else if (fnamelen > 4 && !strcmp((c = &fname[fnamelen - 4]), ".key")) {</span><br><span> ktype = AST_KEY_PRIVATE;</span><br><span> } else {</span><br><span> return NULL;</span><br><span>@@ -244,8 +246,6 @@</span><br><span> }</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- /* Make fname just be the normal name now */</span><br><span style="color: hsl(0, 100%, 40%);">- *c = '\0';</span><br><span> if (!key) {</span><br><span> if (!(key = ast_calloc(1, sizeof(*key)))) {</span><br><span> fclose(f);</span><br><span>@@ -254,8 +254,8 @@</span><br><span> }</span><br><span> /* First the filename */</span><br><span> ast_copy_string(key->fn, ffname, sizeof(key->fn));</span><br><span style="color: hsl(0, 100%, 40%);">- /* Then the name */</span><br><span style="color: hsl(0, 100%, 40%);">- ast_copy_string(key->name, fname, sizeof(key->name));</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Then the name minus the suffix */</span><br><span style="color: hsl(120, 100%, 40%);">+ snprintf(key->name, sizeof(key->name), "%.*s", (int)(c - fname), fname);</span><br><span> key->ktype = ktype;</span><br><span> /* Yes, assume we're going to be deleted */</span><br><span> key->delme = 1;</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/19421">change 19421</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/19421"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 20 </div>
<div style="display:none"> Gerrit-Change-Id: Ifa36d352aafeb7f9beec3f746332865c7d21e629 </div>
<div style="display:none"> Gerrit-Change-Number: 19421 </div>
<div style="display:none"> Gerrit-PatchSet: 3 </div>
<div style="display:none"> Gerrit-Owner: Philip Prindeville <philipp@redfish-solutions.com> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@sangoma.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>