CLI may only copy data for null terminated values

Bug #1371176 reported by Cliff Gray
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Trafodion
Fix Released
High
Cliff Gray

Bug Description

The CLI interface, ExeCliInterface::executeImmediate and executeImmmediateExec take a Boolean, nullTerminate, that is intended to control whether a trailing null is added after returned data. However, for some queries, if the Boolean is not set to true, the data is not copied.

The suspicious code is in ExeCliInterface::executeImmediate.

  if ((outputBuf) &&
      (outputBufLen))
    {
      *outputBufLen = 0;
      if (retcode != 100)
 {
   if (nullTerminate)
     {
       char * ptr;
       Lng32 len;
       getPtrAndLen(1, ptr, len);

       str_cpy_all(outputBuf, ptr, len);

       outputBuf[len] = 0;
       *outputBufLen = len;
     }
   else
     *outputBufLen = outputDatalen_;
 }
    }

Perhaps the get and copy code should be outside the if (nullTerminate) block.

Queries that result in data not being copied unless nullTerminate is set to true include:

SELECT MAX(columnName) FROM table [WHERE condition];

For called to executeImmediate where the value is not a null-terminated string, passing true for the parameter nullTerminate results in a null/zero being placed in the byte of a variable on the stack near the passed outputBuf. A workaround is to declare dummy variables around the passed outputBuf.

Tags: sql-exe
Cliff Gray (cliff-gray)
tags: added: sql-exe
Changed in trafodion:
assignee: nobody → Sandhya Sundaresan (sandhya-sundaresan)
importance: Undecided → High
Cliff Gray (cliff-gray)
Changed in trafodion:
assignee: Sandhya Sundaresan (sandhya-sundaresan) → Cliff Gray (cliff-gray)
status: New → In Progress
milestone: none → r0.9
milestone: r0.9 → r1.0
Revision history for this message
Sandhya Sundaresan (sandhya-sundaresan) wrote :

The CLI code that was doing the memory overwrite was fixed.
Corresponding kludges were removed in the security code that worked around the original problem and were fixed in Change-Id: If7538eee38178c2345fe418172c6196b25a20b33

Changed in trafodion:
status: In Progress → Fix Committed
Cliff Gray (cliff-gray)
Changed in trafodion:
status: Fix Committed → Fix Released
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.