EPICS Controls Argonne National Laboratory

Experimental Physics and
Industrial Control System

1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  <20122013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024  Index 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  <20122013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
<== Date ==> <== Thread ==>

Subject: devlib2 bugfix (rare string corruption)
From: Till Straumann <[email protected]>
To: "Davidsaver, Michael" <[email protected]>
Cc: EPICS Techtalk <[email protected]>
Date: Wed, 19 Dec 2012 11:59:53 -0600
vallocPrintf()

first calls vsnprintf() with a length argument of zero to determine
the necessary buffer size, allocates a buffer and then calls

size2 = vsprintf(buf,format,args)

It then goes on and complains if size2 is different from what the
initial vsnprintf() returned.

If, however, this really happens (and I have observed this under 64-bit ubuntu-12.10) then it is well possible that vsprintf() writes beyond the length of the buffer.

Hence, I suggest to replace vsprintf() by

size2 = vsnprintf(buf, size+1, format, args)

just to make sure. (Note that the 'size' argument to snprintf() includes space for
the terminating NUL whereas the return value does not.)

- Till

A patch is attached for sake of convenience.
diff -r ed471db5e741 pciApp/os/Linux/devLibPCIOSD.c
--- a/pciApp/os/Linux/devLibPCIOSD.c	Wed Dec 19 11:52:40 2012 -0600
+++ b/pciApp/os/Linux/devLibPCIOSD.c	Wed Dec 19 11:53:34 2012 -0600
@@ -187,7 +187,7 @@
         errlogPrintf("vaprintf: Failed to allocate memory for format '%s'\n",format);
         goto fail;
     }
-    size2=vsprintf(ret,format,args);
+    size2=vsnprintf(ret,size+1,format,args);
     if (size!=size2) {
         errlogPrintf("vaprintf: Format yielded different size %d %d : %s\n",size,size2,format);
         goto fail;

Replies:
Re: devlib2 bugfix (rare string corruption) Michael Davidsaver

Navigate by Date:
Prev: [makefile] adding a library to an EPICS application Pavel Maslov
Next: Re: [makefile] adding a library to an EPICS application Martin Konrad
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  <20122013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
Navigate by Thread:
Prev: Re: [makefile] adding a library to an EPICS application Ralph Lange
Next: Re: devlib2 bugfix (rare string corruption) Michael Davidsaver
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  <20122013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
ANJ, 18 Nov 2013 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·