_FORTIFY_SOURCE and strncat(), buggy?
_FORTIFY_SOURCE and strncat(), buggy?
- Subject: _FORTIFY_SOURCE and strncat(), buggy?
- From: "Sean McBride" <email@hidden>
- Date: Thu, 24 Jul 2008 14:19:58 -0400
- Organization: Rogue Research
Hi all,
Anyone else out there using _FORTIFY_SOURCE? Do you find it reliable?
The following code seems correct to me, but dies with _FORTIFY_SOURCE enabled.
--------------
#include <stdlib.h>
#include <string.h>
int main (int argc, const char * argv[])
{
(void)argc; (void)argv;
size_t size = 50;
char* buffer = (char*)calloc(size, 1);
// buffer[0] = 'q'; // uncomment this to 'fix'.
strncat(buffer, "test", (size-1));
return 0;
}
--------------
$ gcc-4.2 -Wall -D_FORTIFY_SOURCE=2 ~/Desktop/strncat_test.c
$ ./a.out
Abort trap
(PS: yes, I know C strings suck; yes, I know about strlcat).
Cheers,
--
____________________________________________________________
Sean McBride, B. Eng email@hidden
Rogue Research www.rogue-research.com
Mac Software Developer Montréal, Québec, Canada
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden