Article View: comp.os.xinu
Article #307Old Bug uncovered
From: Shawn Ostermann
Date: Wed, 08 Feb 1989 04:40
Date: Wed, 08 Feb 1989 04:40
68 lines
2531 bytes
2531 bytes
(A little trivia for pointer buffs)
I was helping the VM Xinu guys track down a bug, and found a coding
mistake that has been living in a library file for years. The bug is
in the library file src/lib/libxc/doscan.c, and the interesting
parts are as follows (watch the variable fileended):
MANY LINES DELETED
/* doscan.c - doscan */
...
_doscan( ... )
{
int **ptr, fileended, size;
...
fileended = 0;
...
if (_innum(ptr, ch, len, size, getch, ungetch,
arg1, arg2, fileended) && ptr)
...
}
...
_innum(ptr, type, len, size, getch, ungetch, arg1, arg2, eofptr)
...
int *eofptr;
{
...
if (c != EOF) {
(*ungetch)(arg1, arg2);
*eofptr = 0;
} else
*eofptr = 1;
...
}
_innum is trying to use eofptr as a flag for doscan. The mistake (as
you've ALL already seen (-: ) is that the call to innum SHOULD be
if (_innum(ptr, ch, len, size, getch, ungetch,
arg1, arg2, &fileended) && ptr)
^
to pass the ADDRESS of fileended, rather than a null pointer. The bug
was never noticed in the old Xinu stuff because address 0 was writable,
and not used. In VM Xinu, however, that is an illegal address for
some processes, and the dereferencing causes a page fault (that's how
I found it). A little poking around found that this routine has been
included faithfully in all of the architecture distributions that I
looked at. This will probably never affect anyone using the old Xinu
stuff, but if you're a stickler for good pointer grammar, you might
want to fix it.
The moral of the story:
Boy I'm glad that this module was written before I started working on the
Xinu project, that way (for once) it's not my fault!!!
(no pun intended)
Anybody out there in Xinu land wanna own up to it????!!!
Shawn
-----------------------------------------------------------------------------
Shawn Ostermann ARPA: sdo@cs.purdue.edu UUCP: ...!purdue!sdo
-----------------------------------------------------------------------------
Technical Details
Message-ID:
<8902080440.AA16718@medusa.cs.purdue.edu>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!pasteur!agate!ucbvax!PURDUE.EDU!sdoShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!pasteur!agate!ucbvax!PURDUE.EDU!sdo From: sdo@PURDUE.EDU (Shawn Ostermann) Newsgroups: comp.os.xinu Subject: Old Bug uncovered Message-ID: <8902080440.AA16718@medusa.cs.purdue.edu> Date: 8 Feb 89 04:40:32 GMT Sender: daemon@ucbvax.BERKELEY.EDU Organization: The Internet Lines: 68