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  2012  2013  2014  <20152016  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  2012  2013  2014  <20152016  2017  2018  2019  2020  2021  2022  2023  2024 
<== Date ==> <== Thread ==>

Subject: Re: Stream device problem with redirection in @mismatch
From: Michael Johnson <[email protected]>
To: Dirk Zimoch <[email protected]>
Cc: Tech Talk <[email protected]>
Date: Fri, 10 Apr 2015 12:50:46 -0400
Hi there,

We are seeing a very similar problem at Jefferson Lab. Buffer overflows as soon as I process a device record.

I am using Stream over Asyn with CR-only terminators, configured ala:

# String terminator settings at ASYN level (? - MJ)
asynOctetSetInputEos("PGUNFDIV",0,"\r")
asynOctetSetOutputEos("PGUNFDIV",0,"\r")

#DEBUGGING
asynSetTraceMask("PGUNFDIV",-1,0x9)
asynSetTraceIOMask("PGUNFDIV",-1,0x2)

In Stream, I do not set any terminators (redundant?). 

I am getting these errors after applying the patch. Any thoughts?

Cexp>2015/04/10 12:25:29.570 104-Com-8sm write -1 , bufflen = 1, buffaddr = 8c4edc
\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\004\000\000\000@\000\000\000\004\000\000\000\004\314\225\000\000\000\000\000\000\000\000\000\000
2015/04/10 12:25:29.910 104-Com-8sm write 0
Program heap: free of bad pointer 8C4EDC -- range 832928 - 1F6C0000
2015/04/10 12:25:30.210 104-Com-8sm write -1 , bufflen = 1, buffaddr = 9894c4
\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\004\000\000\000@\000\000\000\004\000\000\000\004\314\225\000\000\000\000\000\000\000\000\000\000
2015/04/10 12:25:30.570 104-Com-8sm write 0
Program heap: free of bad pointer 98assertion "(uread(BSP_UART_COM1, LSR) & THRE) != 0" failed: file "../../../../../../../../rtems-4.9.2/c/src/lib/libbsp/i386/pc386/../../i386/shared/comm/uart.c", line 585, function: BSP_uart_termios_write_com1

Here is the path I applied (after changing "print" to "printf" to get it to compile):

StreamEpics.cc
916,918c916,918
<         StreamBuffer fullname;
<         fullname.printf("%s.%s", name(), fieldname);
<         if (dbNameToAddr(fullname(), &dbaddr) != OK)
---
>         char fullname[PVNAME_SZ + 1];
>         sprintf(fullname, "%s.%s", name(), fieldname);
>         if (dbNameToAddr(fullname, &dbaddr) != OK)
921,923c921,923
<             fullname.clear().printf("%s.VAL", fieldname);
<             if (dbNameToAddr(fullname(), &dbaddr) != OK) return false;
<         }
---
>             sprintf(fullname, "%s.VAL", fieldname);
>             if (dbNameToAddr(fullname, &dbaddr) != OK) return false;
>         }

With Context:

[205] michaelj@devl01 > diff -c StreamEpics.cc StreamEpics.cc.orig

*** StreamEpics.cc    2015-04-09 14:57:09.264306145 -0400
--- StreamEpics.cc.orig    2015-04-09 14:13:40.706615881 -0400
***************
*** 913,926 ****
      else
      {
          // FIELD in this record or VAL in other record
!         StreamBuffer fullname;
!         fullname.printf("%s.%s", name(), fieldname);
!         if (dbNameToAddr(fullname(), &dbaddr) != OK)
          {
              // VAL in other record
!             fullname.clear().printf("%s.VAL", fieldname);
!             if (dbNameToAddr(fullname(), &dbaddr) != OK) return false;
!         }
      }
      address.append(&dbaddr, sizeof(dbaddr));
      return true;
--- 913,926 ----
      else
      {
          // FIELD in this record or VAL in other record
!         char fullname[PVNAME_SZ + 1];
!         sprintf(fullname, "%s.%s", name(), fieldname);
!         if (dbNameToAddr(fullname, &dbaddr) != OK)
          {
              // VAL in other record
!             sprintf(fullname, "%s.VAL", fieldname);
!             if (dbNameToAddr(fullname, &dbaddr) != OK) return false;
!         }
      }
      address.append(&dbaddr, sizeof(dbaddr));
      return true;

THANKS for reading! - Mike J

On Wed, Apr 8, 2015 at 5:37 AM, Dirk Zimoch <[email protected]> wrote:
On 08.04.2015 11:20, Dirk Zimoch wrote:
 >
/usr/local/epics/support/stream/StreamDevice-2-6/lib/linux-x86_64/libstream.so(_ZN6Stream15getFieldAddressEPKcR12StreamBuffer+0xcd)[0x7f9c3d4bd34d]


I found the bug in getFieldAddress:

         // FIELD in this record or VAL in other record
         char fullname[PVNAME_SZ + 1];
         sprintf(fullname, "%s.%s", name(), fieldname);
         if (dbNameToAddr(fullname, &dbaddr) != OK)
         {
             // VAL in other record
             sprintf(fullname, "%s.VAL", fieldname);
             if (dbNameToAddr(fullname, &dbaddr) != OK) return false;
         }

The first sprintf prints
$(device):StatEnable.$(device):StatEnableInterlock which is way too
long. My fault. I will send a patch soon....

Dirk


Try this:
        // FIELD in this record or VAL in other record
        StreamBuffer fullname;
        fullname.print("%s.%s", name(), fieldname);
        if (dbNameToAddr(fullname(), &dbaddr) != OK)
        {
            // VAL in other record
            fullname.clear().print("%s.VAL", fieldname);
            if (dbNameToAddr(fullname(), &dbaddr) != OK) return false;
        }

(in src/StreamEpics.cc function getFieldAddress)

Dirk




Replies:
Re: Stream device problem with redirection in @mismatch Dirk Zimoch
References:
Stream device problem with redirection in @mismatch ruzickaj
Re: Stream device problem with redirection in @mismatch Dirk Zimoch
Re: Stream device problem with redirection in @mismatch ruzickaj
Re: Stream device problem with redirection in @mismatch Dirk Zimoch
Re: Stream device problem with redirection in @mismatch Dirk Zimoch

Navigate by Date:
Prev: Re: Micro-Epsilon capacitive sensor Steve Shoaf
Next: Re: Device support for agilent 34410A multimeter? Mazanec Tomáš
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  <20152016  2017  2018  2019  2020  2021  2022  2023  2024 
Navigate by Thread:
Prev: Re: Stream device problem with redirection in @mismatch ruzickaj
Next: Re: Stream device problem with redirection in @mismatch Dirk Zimoch
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  <20152016  2017  2018  2019  2020  2021  2022  2023  2024 
ANJ, 16 Dec 2015 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·