This is the mail archive of the ecos-patches@sources.redhat.com 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: [ECOS] redboot gets null termination


Andrew Lunn wrote:
Hi Gary

Does the _rb_gets() function always null terminate the buffer? Im
thinking more about the buffer full condition rather than the normal
CRLF exit from the function. It just seems to exit when the buffer is
full without putting on a trailing \0.
FWIW I agree. To allow for this it should stop at buflen -1 of course, i.e.

        if (ip == buf + buflen - 1) { // Buffer full
	    *ip = '\0';
            return buflen;
        }

I'll check this in.

Jifl

Index: ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos/packages/redboot/current/ChangeLog,v
retrieving revision 1.82
diff -u -5 -p -r1.82 ChangeLog
--- ChangeLog	24 Oct 2002 18:32:24 -0000	1.82
+++ ChangeLog	5 Nov 2002 04:25:33 -0000
@@ -1,5 +1,9 @@
+2002-11-05  Jonathan Larmour  <jifl@eCosCentric.com>
+
+	* src/io.c (_rb_gets_preloaded): Null terminate when buffer full.
+
 2002-10-24  Gary Thomas  <gthomas@ecoscentric.com> (inspired by)
 2002-10-24  Jay Foster <jay@systech.com>	

 	* include/net/bootp.h (BP_MIN_VEND_SIZE):
 	* src/net/bootp.c (__bootp_find_local_ip): Require a minimum vendor
Index: src/io.c
===================================================================
RCS file: /cvs/ecos/ecos/packages/redboot/current/src/io.c,v
retrieving revision 1.28
diff -u -5 -p -r1.28 io.c
--- src/io.c	16 Aug 2002 23:59:47 -0000	1.28
+++ src/io.c	5 Nov 2002 04:25:33 -0000
@@ -593,12 +593,14 @@ _rb_gets_preloaded(char *buf, int buflen
                 }
 #endif
             }
         }
         last_ch = c;
-        if (ip == buf + buflen) // Buffer full
+        if (ip == buf + buflen - 1) { // Buffer full
+            *ip = '\0';
             return buflen;
+        }
     }
 }

 int
 _rb_gets(char *buf, int buflen, int timeout)

--
eCosCentric       http://www.eCosCentric.com/       <info@eCosCentric.com>
--[ "You can complain because roses have thorns, or you ]--
--[  can rejoice because thorns have roses." -Lincoln   ]-- Opinions==mine


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