This is the mail archive of the ecos-patches@sourceware.org mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Please advice w.r.t. language/tcl


On Tue, Jun 17, 2008 at 9:34 PM, Andrew Lunn <andrew@lunn.ch> wrote:
> On Tue, Jun 17, 2008 at 06:14:47PM +0200, ?yvind Harboe wrote:
>> Jim Tcl contains an eCos repository in CVS HEAD.
>>
>>
>> http://cvs.berlios.de/cgi-bin/viewcvs.cgi/jim/jim/ecos/
>
> Hi Oyvind
>
> I have gcc 4.3.1 installed as the host compiler. I just tried
> compiling the jim tcl interpreter with synth, ie the host tools and i
> get a warning:
>
> /home/lunn/eCos/anoncvs-clean/packages/net/athttpd/current/src/jim-aio.c:140: warning: array subscript is above array bounds
>
> The code fragment is:
>
>    /* GETS */
>        char buf[AIO_BUF_LEN];
>        Jim_Obj *objPtr;
>
>        if (argc != 2 && argc != 3) {
>            Jim_WrongNumArgs(interp, 2, argv, "?varName?");
>            return JIM_ERR;
>        }
>        objPtr = Jim_NewStringObj(interp, NULL, 0);
>        while (1) {
>            int more = 0;
>            buf[AIO_BUF_LEN-1] = '_';
>            if (fgets(buf, AIO_BUF_LEN, af->fp) == NULL)
>                break;
>            if (buf[AIO_BUF_LEN-1] == '\0' && buf[AIO_BUF_LEN] == '\n')
>
> buf[AIO_BUF_LEN] is a buffer overrun by one.
>
>     Andrew
>

I'm having trouble parsing the docs for fgets(), but
http://linux.die.net/man/3/fgets
indicates that the attached patch should be correct.

What do  you think?


### Eclipse Workspace Patch 1.0
#P jim
Index: ChangeLog
===================================================================
RCS file: /cvsroot/jim/jim/ChangeLog,v
retrieving revision 1.131
diff -u -r1.131 ChangeLog
--- ChangeLog	16 Jun 2008 14:03:10 -0000	1.131
+++ ChangeLog	17 Jun 2008 19:51:38 -0000
@@ -1,3 +1,9 @@
+2008-06-17 Andrew Lunn <andrew@lunn.ch> / oharboe
+
+	* ChangeLog, jim-aio.c: Andrew spotted a bug in the
+	aio.gets implementation for lines that are more than
+	AIO_BUF_LEN long. GCC 4.3.1 pointed out this problem.
+	
 2008-06-16 Uwe Klein wiederling at googlemail.com

 	* ChangeLog, jim.c: fixed parsing in "expr 0x1234".
Index: jim-aio.c
===================================================================
RCS file: /cvsroot/jim/jim/jim-aio.c,v
retrieving revision 1.12
diff -u -r1.12 jim-aio.c
--- jim-aio.c	15 Jun 2008 21:03:26 -0000	1.12
+++ jim-aio.c	17 Jun 2008 19:51:38 -0000
@@ -143,7 +143,7 @@
             buf[AIO_BUF_LEN-1] = '_';
             if (fgets(buf, AIO_BUF_LEN, af->fp) == NULL)
                 break;
-            if (buf[AIO_BUF_LEN-1] == '\0' && buf[AIO_BUF_LEN] == '\n')
+            if (buf[AIO_BUF_LEN-1] == '\0' && buf[AIO_BUF_LEN-2] != '\n')
                 more = 1;
             if (more) {
                 Jim_AppendString(interp, objPtr, buf, AIO_BUF_LEN-1);


-- 
Øyvind Harboe
http://www.zylin.com/zy1000.html
ARM7 ARM9 XScale Cortex
JTAG debugger and flash programmer


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]