On Thu, 17 May 2007, Joerg Schilling wrote:

[EMAIL PROTECTED] wrote:

        - you cannot mix 64 bit & 32 bit
        - you cannot use code from libc in the kernel because there's
          no guarantee that that code will work in kernel context(!)


The kernel has a strstr() of its own, so you'll need to just call
that.

Many of the libc functions have to repect the same rules as the kernel
and the kernel implementations may also fail, see bug 6489267 where
strncat() from the kernel caused a panic because of accessing a byte
bejond the permitted range.

The str* functions just sometimes don't quite do what one might naively think they'd do. Try finding/fixing the bugs in this one:

        char str[100];

        memset(str, '\0', 100);         /* clear string memory */

        pgsz = sysconf(_SC_PAGESIZE);
        buf = mmap(NULL, pgsz, PROT_READ | PROT_WRITE,
                MAP_ANON | MAP_PRIVATE, 0, 0);
        memset(buf, 'a', pgsz);         /* page now filled with 'a' */

        strlcat(str, buf, 1);           /* append single byte from buf */
        strncat(str, buf + pgsz, 0);    /* doesn't really do anything */

Both str*cat calls will crash. Go figure.


The difference is that we _exspect_ that the kernel implementation have been
coded carefully enough to avoid a e.g. kernel panic but the same bug in libc
would cause a core dump under similar conditions.

We "expect" many things, any very often what we expect isn't what we get. That's particularly true for the str*() family of functions :(

FrankH.
_______________________________________________
opensolaris-discuss mailing list
[email protected]

Reply via email to