Bug 202999

Summary: bug in tapset/string.stp:substr prevents it from returning desired substring
Product: Red Hat Enterprise Linux 4 Reporter: Jonathan Earl Brassow <jbrassow>
Component: systemtapAssignee: Frank Ch. Eigler <fche>
Status: CLOSED UPSTREAM QA Contact: Len DiMaggio <ldimaggi>
Severity: medium Docs Contact:
Priority: medium    
Version: 4.0CC: jbrassow
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2006-09-20 15:20:31 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Jonathan Earl Brassow 2006-08-17 18:54:44 UTC
Firstly, I pulled the sources from upstream and compiled them against a kernel I
have.  So, sorry if this is fixed in the rpm.

Description of problem:
The substr function, as described in the man page and comments, indicates the
last argument is the "stop", however, the strncpy function acts as though it
expects it to be a "length" argument.

If I want "there" from "hello there world", it currently does the following:
str = "hello there world"
substr(str, 6, 11) # 11 is the stop, not the len
-> strncpy(ret, s+6, 11)
-> ret[11] = '\0'
result:  "there world"

should be:
str = "hello there world"
substr(str, 6, 11) # 11 is the stop, not the len
-> strncpy(ret, s+6, 11-6)
-> ret[11-6] = '\0'
result:  "there"

Version-Release number of selected component (if applicable):
?

How reproducible:
always

Steps to Reproduce:
See above

I am using the following (please review for correctness):
strncpy(THIS->__retvalue,s+THIS->start, THIS->stop - THIS->start);
THIS->__retvalue[THIS->stop - THIS->start]='\0';

Comment 1 Frank Ch. Eigler 2006-08-23 12:02:59 UTC
Martin will fix this upstream.

http://sourceware.org/ml/systemtap/2006-q3/msg00362.html

Comment 2 Jonathan Earl Brassow 2006-09-08 16:19:42 UTC
3 argument changed upstream to be 'length' not 'stop' - works upstream now.


Comment 3 Frank Ch. Eigler 2006-09-20 15:20:31 UTC
The fix will be included in any subsequent package refresh.