Odd behaviour of "stack smashing detected"

This is my code.

struct ar { char array[10]; }b; void func() { char array[10]; scanf("%s",b.array); printf("%s\n", b.array); scanf("%s",array); printf("%s\n", array); } int main(int argc, char **argv) { func(); }

When i give string longer than size of array from command line for both array, I am facing stack smashing detected error for char array defined in main but array inside structure is not giving the error and printing the correct string.

What can be the reason?

-------------Problems Reply------------

  1. Basically what you have is undefined behavior when you do array out of bound access.
  2. The global here is put into the .bss segment in the data segment and not on stack.
  3. There is a possibility that everything might work as expected but that is a side-effect of UB , in another case you might see a crash.
Category:c# Views:2 Time:2018-08-08
Tags: arrays stack gcc

Related post

  • Stack smashing detected 2009-08-28

    I am executing my a.out file. After execution the program runs for some time then exits with the message: **** stack smashing detected ***: ./a.out terminated* *======= Backtrace: =========* */lib/tls/i686/cmov/libc.so.6(__fortify_fail+0x48)Aborted*

  • gcc C ***stack smashing detected*** array 2012-01-08

    The line of code causing the problem is char command_tb_temp[][1000]={"gcc -Wall ","-o3 -ftree-ccp -fno-align-jumps "," Scripts/*.c -o output -lm && time -f \"%e\" -o TB.log ./output 1.dat"}; When the same code is written by giving only 1 opt

  • "stack smashing detected" by getline & printf - and i really cant figure out why 2012-01-28

    when it comes to C i am not a noob - i'm more like a total & complete stupid ignorant noob! i am trying to write a program to parse simple text files, and i would like to make it as general as possible(why i use getline). well here is my code: //

  • c stack smashing detected 2012-03-15

    I've created a file which prints Hello, world as many times at the user wants to give input. #include <stdio.h> #include <string.h> int main() { char message[10]; int count, i; strcpy(message, "Hello, world!"); printf("Repeat how many tim

  • stack smashing detected in bandwidthTest.cu in CUDA SDK 2012-03-26

    I want to run the bandwidthTest inside the CUDA SDK. It is terminated by stack smashing detected error. How can I solve this problem????? I use the make command to run this program and make the file. I cannot change anything inside the code. --------

  • Stack Smashing Detected. C programming 2012-04-27

    i'm trying to run a C program. It seems to work fine, but at the end it shows: STACK SMASHING DETECTED This is the code: #include <stdio.h> #include <string.h> #include <stdlib.h> #include <unistd.h> #include <errno.h> e

  • Can someone assist in explaining the backtrace output having the term 'stack smash'? 2009-04-25

    plz explain the follwing result of the stack smash after running a programming in which input i gave is much more than the capacity of the charachter array. *** stack smashing detected ***: ./a.out terminated ======= Backtrace: ========= /lib/tls/i68

  • What to do with error information after stack smashing 2010-02-21

    I'm experiencing some problems with my C program on Linux. It compiles and runs just fine on Windows. The Linux terminal returns this information: *** stack smashing detected ***: ./student terminated ======= Backtrace: ========= /lib/libc.so.6(__for

  • how to find the cause of stack smash 2011-01-04

    I am trying to figure out why im getting stack smashed when using FFMPEG libraries. I've recompiled FFMPEG with debugging info and from the backtrace, the offending line is libavformat/mpegtsenc.c:800. However that line is just the closing } brace of

  • Question with stack smashing protection and buffer overflows 2011-07-19

    Im doing some research on buffer overflows and I was wondering how does stack smashing protection works i have this code: int main( ) { char Buf[16]; printf(“Digite o seu nome: ”); gets(Buf); printf(“%s”,Buf); return 0; } I compile it with gcc and th

  • Stack smashing code not working on Linux kernel 2.6.38.7- Please help 2011-08-20

    I have been reading "The Shellcoders Handbook" and been referring to this link for practice of stack overflow. But it seems the Linux kernel developers have made the kernel very secure. Here are my problems. 1) This code void function(int a, int b, i

  • Stack smash and sscanf 2011-09-15

    reply is S|[2 3 4 5 6 7 8 9]|[2 3 4 5 6 7 8 9] char com[10], f[100], s[100]; sscanf(reply, "%[^!]|%[^!]|%[^!]", com, f, s); It causes stack smash. I know that sscanf is usually unsafe, but I'm wondering why it fail here - when input string in fine. H

  • Stack Smashing Using Message Queues 2012-01-04

    i have the following main code: #include "ComHandler.h" #include "socketMessage.h" #define THIS_IP "localhost" #define C_PORT 32456 #define S_PORT 25465 #define S_PORT_UDP 22548 int main(int argc, char* argv[]) { conOptions opts; strncpy(opts.passwor

  • Reason for difference stack smashing behaviour between machines 2011-05-26

    We're trying to track down some stack smashing errors in some generated code. The problem is that the stack smashing errors are not 100% deterministic and only happens on one machine and not others. What possible reasons could there be for the differ

  • Stack Smashing attempt giving segfault 2009-01-29

    I am trying to do an example from the Smashing the Stack for Fun and Profit in C, but am kind of stuck at a point, following is the code (I have a 64-bit machine with Ubuntu 64-bit): int main() { int x; x = 0; func(1,2,3); x = 1; printf("x is : %d\n"

  • Why does this program give "stack smashing error"? 2010-08-11

    input .txt contents start_point(0) end_point(100) turtle_speed(3) hare_speed(6) hare_sleep_time(5) hare_turtle_dist(20) process_delay(1) stack smashing error occurs if i put hare-TURTLE_DIST GREATER THAN 10 code #include<stdio.h> #include<st

  • Stack Smashing problem in real time data writing to database 2010-08-19

    Have a program that receives burst traffic .Adds to linked list and then processes to writing to database.Seen stack smashing.Then no response of asynchronous message...... --------------Solutions------------- Stack smashing definition: http://search

  • Crash due to "stack corruption detected: aborted" 2010-12-17

    I recently received complaint from a user that my app was crashing. I've extracted the following from the user's error logs and was able to see why issues where happening: 12-17 10:31:12.446 I/PLAYLIST( 3158): PreparePlaylist 12-17 10:31:12.446 I/PLA

  • Inflating Views and adding them to a LinearLayout within a HorizontalScrollView - Odd Behaviour 2011-01-12

    I'm trying to create a class that can be added to a Layout file, have an adapter set and then update from a DataSetObserver. On the Nexus One this generally seems to work fine, however on the G1 I get some odd behaviour. So the Layout File for the Ac

  • istream's tellg/seekg cannot be protected from stack smashing (g++)? 2011-02-01

    For a program that I'm writing, it is useful for me to calculate file sizes, which I calculate by using iostream's tellg and seekg functions, but this leads to a warning by -Wstack-protector. The following code reproduces the "problem": #include <

  • Odd behaviour with links in PHP Mail function 2011-02-11

    I'm currently trying to get links working in emails sent via the PHP mail function. Here is my code - I've also included some things I've tried (commented out along with notes): $to = "[email protected]"; $subject = "Testing email"; //$body = '<str

  • Odd behaviour of Image control in WPF 2011-04-27

    I'm trying to get started with WPF in c#. I set a Canvas as the content of a window, then I create another Canvas and put it as a child of the first Canvas (together with other elements, such as buttons and labels). Everything runs fine until I creat

  • Odd behaviour when replacing DataGridCheckBoxColumn with a DataGridTemplateColumn 2011-06-24

    I have discovered an odd behaviour when replacing a DataGridCheckBoxColumn against a DataGridTemplateColumn that contains a Checkbox. <sdk:DataGrid Grid.Column="0" IsReadOnly="{Binding IsInReadOnlyMode}"> <sdk:DataGrid.Columns> <sdk:Da

  • Makefile odd behaviour 2011-11-22

    I've got this Makefile that is presenting some odd behaviour: $ javac -d Classes -sourcepath .. -classpath `for x in \`ls Classes/jars/*\`; do echo -n $x:; done` PCA/PCAClassifier.java compiles the java just fine. But for somereason when I call make

  • Very odd behaviour with launcher's task stack handling 2010-08-06

    I have an application with two activities, A and B. A is the root activity, which then starts B. When the stack looks like this: HOME > A > B ...and I select A from the launcher, I want it to resume the task without clearing the stack, so B is

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.166 (s). 11 q(s)