caput of escaped strings to CHAR array send too large array count

Bug #1441069 reported by Dirk Zimoch
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
EPICS Base
Fix Released
Medium
Ralph Lange
3.14
Fix Released
Medium
Ralph Lange
3.15
Fix Released
Medium
Ralph Lange
3.16
Fix Released
Medium
Ralph Lange

Bug Description

When a string is written to a CHAR array, the array count is set to string length+1 (includes terminating 0 byte).

But when escape sequences are used, the byte count does not get adjusted. Thus a sequence like "\a" sends 3 bytes (7 0 0), not 2.

This is the piece of code in question (caput.c). See how the result of epicsStrnRawFromEscaped is not used to update count.

        if (charArrAsStr) {
            count = len;
            dbrType = DBR_CHAR;
            ebuf = calloc(strlen(cbuf)+1, sizeof(char));
            if(!ebuf) {
                fprintf(stderr, "Memory allocation failed\n");
                return 1;
            }
            epicsStrnRawFromEscaped(ebuf, strlen(cbuf)+1, cbuf, strlen(cbuf));
        } else {

The bug appeared together with the -S option (3.14.12 ?) and can still be found in 3.15.1.

The bug is relatively harmless because it simply sends too many trailing 0 bytes.

description: updated
Revision history for this message
Andrew Johnson (anj) wrote :

How many times can one short piece of code call strlen() on the same string?

Revision history for this message
Dirk Zimoch (dirk.zimoch) wrote : Re: [Bug 1441069] Re: caput of escaped strings to CHAR array send too large array count

On 07.04.2015 17:00, Andrew Johnson wrote:
> How many times can one short piece of code call strlen() on the same
> string?

Crazy, isn't it? Especially since len already contains the length. Maybe
someone's mind was too much adjusted to PASCAL where the length
operation needs constant time?

Changed in epics-base:
importance: Undecided → Medium
assignee: nobody → Ralph Lange (ralph-lange)
status: New → Confirmed
Changed in epics-base:
milestone: none → 3.15.4
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.