9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: rod@hemiola.co.uk
To: 9fans@9fans.net
Subject: [9fans] replica bug
Date: Thu,  3 Mar 2011 12:22:48 +0000	[thread overview]
Message-ID: <20110303122454.2E85865D3E@server.hemiola.co.uk> (raw)

The replica utilities use an avl tree to store sets of filenames and
attributes. When new trees are created, the function "mkavltree" is
called. It's argument is the comparison routine "entrycmp" in db.c.
"entrycmp" in turn uses "strcmp" to do it's donkey work, and returns
that value directly.  The avl code requires that it's comparison
function returns -1, 0 or 1.  Strcmp is guaranteed only to return an
integer whose sign reflects the comparison result. Whilst on the 386
strcmp does indeed return -1, 0 or 1, on the arm platform this isn't
necessarily the case, leading to bad things.

in db.c:

60a61
> 	int r;
64c65,66
< 	return strcmp(ea->name, eb->name);
---
> 	r = strcmp(ea->name, eb->name);
> 	return r > 0 ? 1 : r < 0 ? -1 : 0;

Rod

;-----------------

PS. Subsequently I wondered if this problem occured elsewhere in the
system. The only other place I can find avl trees being used is in
venti/copy. The actual avl library is used here, rather than the
nearly-the-same-as-the-library file that the replica utilities use.
The function "scoretreecmp" does seem to me to have the potential to
return non (-1,0,1) values. The return value can derive not only from
memcmp, but also from the difference between the two score types.  As
it happens "memcmp" is "safe" for both 386 and arm, and I am guessing
that the latter comparison rarely happens. I also note anyway that the
avl tree is only created and used if the undocumented -m option is
specified on the command line.  It seems that the chance of provoking
the problem here is small...



             reply	other threads:[~2011-03-03 12:22 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-03 12:22 rod [this message]
2011-03-03 13:03 ` erik quanstrom
2011-03-03 13:54   ` Russ Cox

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110303122454.2E85865D3E@server.hemiola.co.uk \
    --to=rod@hemiola.co.uk \
    --cc=9fans@9fans.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).