LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-11-2007, 10:43 AM   #1
ashlesha
Member
 
Registered: May 2005
Location: PA
Distribution: Ubuntu
Posts: 204

Rep: Reputation: 30
strcat giving a stack smashing detected error


Hi,

This is my program:
Quote:
#include<stdio.h>

#include<stdlib.h>

#include<strings.h>

#include<string.h>

void itoa (int n, char s[]);
void reverse (char s[]);

int main()
{
char ash[20],chi[20],temp[40];
int a,b,taxi_state,count,error[11]={1,2,3,4,5,6,7,8,9,0,11};

count=-1;
while(count<10)
{
itoa(error[count++],temp);
strcat(ash,temp);
}

printf("%s\n",ash);
return 0;
}
Anytime I have the strcat function, I get the following error by gcc:

Quote:
*** stack smashing detected ***: ./test2 terminated
Aborted (core dumped)
What does this error mean exactly?

Thanks,
Ashlesha.

Using UBUNTU 6.1

Last edited by ashlesha; 03-11-2007 at 10:45 AM.
 
Old 03-11-2007, 11:02 AM   #2
random0
LQ Newbie
 
Registered: Jun 2006
Location: Gainesville, Fl, USA
Distribution: Debian GNU/Linux
Posts: 18

Rep: Reputation: 0
You are getting that error because your system detects an attempt at a buffer overflow attack in your program. In your particular case, the temp buffer is larger than the ash buffer and trying to strcat temp onto ash writes out of the bounds of ash; that is what your system is detecting. You could modify temp to be smaller or you could read the man page on strcat for further advice.
 
Old 03-11-2007, 11:15 AM   #3
ashlesha
Member
 
Registered: May 2005
Location: PA
Distribution: Ubuntu
Posts: 204

Original Poster
Rep: Reputation: 30
Thank you --

yeah it works now -- the problem was that the source buffer must be a const
so i just said temp[0]=0; and it works

-Ashlesha
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
giving separate stack space for each task manas_sem Programming 2 03-01-2007 04:34 PM
Smashing the stack protection Seniltai Programming 1 04-21-2006 12:12 PM
TeX, pdflatex, beamer stack error. djib Linux - Software 1 04-04-2005 07:46 AM
kernel stack error installing... artofluke Linux - General 1 03-04-2005 09:21 PM
strcat() error with gcc sureshkellemane Programming 17 02-21-2005 12:42 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:32 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration