<html>
    <head>
      <base href="https://bugzilla.netfilter.org/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - incorrect sort function at segtree.c"
   href="https://bugzilla.netfilter.org/show_bug.cgi?id=1181">1181</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>incorrect  sort function at segtree.c
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>nftables
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>x86_64
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>minor
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P5
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>iptables over nftable
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>pablo@netfilter.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>cidjey1991@mail.ru
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=506" name="attach_506" title="Suggested solution">attachment 506</a> <a href="attachment.cgi?id=506&action=edit" title="Suggested solution">[details]</a></span>
Suggested solution

Function static int expr_value_cmp(const void *p1, const void *p2) at segtree.c
in nftables sources is incorrect.

static int expr_value_cmp(const void *p1, const void *p2)
{
    struct expr *e1 = *(void * const *)p1;
    struct expr *e2 = *(void * const *)p2;
    int ret;

    ret = mpz_cmp(expr_value(e1)->value, expr_value(e2)->value);
    if (ret == 0 && (e1->flags & EXPR_F_INTERVAL_END))
        return -1;
    else
        return 1;

    return ret;
}


as you can see, running never reaches "return ret" and basically it doesn't
matter if mpz_cmp returned 1 or -1.

Suggested solution:

static int expr_value_cmp(const void *p1, const void *p2)
{
    struct expr *e1 = *(void * const *)p1;
    struct expr *e2 = *(void * const *)p2;
    int ret;

    ret = mpz_cmp(expr_value(e1)->value, expr_value(e2)->value);
    if (ret == 0) {
        if (e1->flags & EXPR_F_INTERVAL_END)
            return -1;
        else 
            return 1;
    } 

    return ret;
}

The patch is attached.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are watching all bug changes.</li>
      </ul>
    </body>
</html>