Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 22 Feb 1997 17:04:48 -0800 (PST)
From:      "Jonathan M. Bresler" <jmb>
To:        abelits@phobos.illtel.denver.co.us (Alex Belits)
Cc:        guido@gvr.win.tue.nl, dillon@best.net, gurney_j@resnet.uoregon.edu, top@sonic.cris.net, audit-bin@FreeBSD.ORG, FreeBSD-hackers@FreeBSD.ORG
Subject:   *p!='\0' (still)
Message-ID:  <199702230104.RAA05821@freefall.freebsd.org>
In-Reply-To: <Pine.LNX.3.95.970222015956.28017B-100000@phobos.illtel.denver.co.us> from "Alex Belits" at Feb 22, 97 02:03:10 am

next in thread | previous in thread | raw e-mail | index | archive | help
Alex Belits wrote:
> 
> with p=""  
> *p != '\0' && p[strlen(p) - 1] == '[' _still_ will read a byte p[-1].
> In most of situations not dangerous, but still potentially unaccessible
> memory (sorry, I have no idea where is this ugly thing from and how p is
> allocated).

	not true.  the test *p != '\0'  fails.
	the second half of the && statement is not executed

Aspen:[14] cat /tmp/a.c
#include <stdio.h>
int
main(int argc, char *argv[]) {
        char *p = "";
        if (*p != '\0') {
                printf("passed\n");
        } else {
                printf("failed\n");
        }
}
Aspen:[15] gcc -o /tmp/a.out /tmp/a.c
Aspen:[16] /tmp/a.out
failed
Aspen:[17] uname -a 
FreeBSD Aspen.Woc.Atinc.COM 3.0-CURRENT FreeBSD 3.0-CURRENT #0: Sat Feb 22 19:35:37 EST 1997     jmb@Aspen.Woc.Atinc.COM:/usr/src/sys/compile/ASPEN  i386


jmb



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199702230104.RAA05821>