<p>Stefan Sperling has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.osmocom.org/11858">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">fix allocation of ippool's hash table<br><br>The calloc() call in ippool_new() had two problems.<br><br>The first problem is benign: The order of arguments were reversed.<br>Pass the number of elements in the array first, then the size of<br>each element, as calloc() expects.<br>This problem was found by me. There are more instances of this<br>problem in this file, which I'll address in follow-up patches.<br><br>The second problem is that the requested allocation was larger than<br>necessary: The hash table is an array of pointers to ippoolm_t, not<br>an array of struct ippoolm_t. Fix the required size passed to calloc().<br>This problem was found by Coverity.<br><br>Change-Id: I93fa5bc539771ca19714f6a665558c9140e2ce07<br>Related: CID#57920<br>---<br>M lib/ippool.c<br>1 file changed, 2 insertions(+), 3 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.osmocom.org:29418/osmo-ggsn refs/changes/58/11858/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/lib/ippool.c b/lib/ippool.c</span><br><span>index 6561f1f..6ce3cda 100644</span><br><span>--- a/lib/ippool.c</span><br><span>+++ b/lib/ippool.c</span><br><span>@@ -276,9 +276,8 @@</span><br><span>       (*this)->hashmask = (*this)->hashsize - 1;</span><br><span> </span><br><span>         /* Allocate hash table */</span><br><span style="color: hsl(0, 100%, 40%);">-       if (!</span><br><span style="color: hsl(0, 100%, 40%);">-       ((*this)->hash =</span><br><span style="color: hsl(0, 100%, 40%);">-      calloc(sizeof(struct ippoolm_t), (*this)->hashsize))) {</span><br><span style="color: hsl(120, 100%, 40%);">+       (*this)->hash = calloc((*this)->hashsize, sizeof(struct ippoolm_t *));</span><br><span style="color: hsl(120, 100%, 40%);">+  if (!(*this)->hash) {</span><br><span>             SYS_ERR(DIP, LOGL_ERROR, 0,</span><br><span>                  "Failed to allocate memory for hash members in ippool");</span><br><span>           return -1;</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/11858">change 11858</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.osmocom.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.osmocom.org/11858"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: osmo-ggsn </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: I93fa5bc539771ca19714f6a665558c9140e2ce07 </div>
<div style="display:none"> Gerrit-Change-Number: 11858 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Stefan Sperling <ssperling@sysmocom.de> </div>