sendfile08 - initialize buf structure
PATCH 1/1 sendfile08 - initialize buf structure
The sendfile08 testcase uses the sendfile() syscall to write the strings "hello" and "world" to a file descriptor and then reads them back in through another file descriptor.
The length of the strings written are determined by strlen(), so that in total 10 bytes are written.
When reading the strings back in, again 10 bytes are read, but the problem is, that those are read back into a *local* string buffer array (buf[]) which hasn't been initialized.
Afterwards,
strcmp(buf, "helloworld")
is called to compare input and output.
This strcmp() is wrong, because basically "helloworld\0" (with the trailing string zero terminator) is compared to "helloworld" (likely without a trailing zero in the buf[] array).
So, if buf[] hasn't been initialized, it's not guaranteed that the 10th byte in buf[10] equals to '\0'.
This problem was found on hppa64-linux-gnu architecture, most likely, because it's a stack-grows-up architecture.
Fix this buglet, by zero-initializing the buf[] array. Alternatively, strncmp() could be used instead of memcmp().
testcases/kernel/syscalls/sendfile/sendfile08.c renamed from testcases/kernel/syscalls/sendfile/sendfile08.c.org +2 -0
@@ -74,6 +74,8 @@ int main(int argc, char *argv[])if (ret ==-1 )tst_brkm (TBROK |TERRNO , cleanup,"lseek %s failed" , out_file); + +memset (buf,0 ,BUFSIZ ); ret =read (out_fd, buf,BUFSIZ );if (ret ==-1 ) tst_brkm(TBROK | TERRNO, cleanup, "read %s failed",
------------------------------------------------------------------------------
November Webinars for C, C++, Fortran Developers
Accelerate application performance with scalable programming models. Explore techniques for threading, error checking, porting, and tuning. Get the most from the latest Intel processors and coprocessors. See abstracts and register
http://pubads.g.doubleclick.net/gampad/clk?id=60136231&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
----- Original Message -----
Quoted 26 lines
From: "Helge Deller" <[email protected]>
To: [email protected]
Sent: Wednesday, 6 November, 2013 8:41:11 PM
Subject: [LTP] [PATCH] sendfile08 - initialize buf structureThe sendfile08 testcase uses the
sendfile()syscall to write the strings "hello" and "world" to a file descriptor and then reads them back in through another file descriptor.The length of the strings written are determined by
strlen(), so that in total 10 bytes are written.When reading the strings back in, again 10 bytes are read, but the problem is, that those are read back into a *local* string buffer array (buf[]) which hasn't been initialized.
Afterwards,
strcmp(buf, "helloworld")
is called to compare input and output.
Thisstrcmp()is wrong, because basically "helloworld\0" (with the trailing string zero terminator) is compared to "helloworld" (likely without a trailing zero in the buf[] array).So, if buf[] hasn't been initialized, it's not guaranteed that the 10th byte in buf[10] equals to '\0'.
Quoted 7 lines
This problem was found on hppa64-linux-gnu architecture, most likely, because it's a stack-grows-up architecture.
Fix this buglet, by zero-initializing the buf[] array. Alternatively,
strncmp()could be used instead ofmemcmp().Signed-off-by Helge Deller <[email protected]>
Hi,
I pushed the strncmp() version.
Thanks,
Jan
Quoted 12 lines
------------------------------------------------------------------------------
November Webinars for C, C++, Fortran Developers
Accelerate application performance with scalable programming models. Explore techniques for threading, error checking, porting, and tuning. Get the most from the latest Intel processors and coprocessors. See abstracts and register
http://pubads.g.doubleclick.net/gampad/clk?id=60136231&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
------------------------------------------------------------------------------
November Webinars for C, C++, Fortran Developers
Accelerate application performance with scalable programming models. Explore techniques for threading, error checking, porting, and tuning. Get the most from the latest Intel processors and coprocessors. See abstracts and register
http://pubads.g.doubleclick.net/gampad/clk?id=60136231&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list