Explanation for how it was working so far!!!


 
Thread Tools Search this Thread
Special Forums Hardware Filesystems, Disks and Memory Explanation for how it was working so far!!!
# 1  
Old 06-14-2006
Explanation for how it was working so far!!!

Hi all

Recently we got an error unearthed which was existing long since in our production code. Let me explain the problem..It was something like this...
char source[20] = "1234567890123456789";
char destination[10];

sprintf(destination,"%9s",source);

The person who coded perhaps had a perception that if he uses the %9s convertion specification, only the 9 characters will be taken from the source string. We know very well that it causes the sprintf to write beyond the allocated memory of destination string. But the problem is like this code is running in production for so long with out giving any issues. Recently when we did some changes in the code, all of a sudden it started behaving abnormal and found this is the cause of error and raised the alarm. Now the question we have to answer is "If it is an error, then how come the same code was running in production for years with out any ERROR?" Please, experts over there.. help us to explain so that a lay man can also understand.

I mean, though I and many around me are sure it is an error, we don't have a convinsing reason/answer for the question "Why the code with the ERROR was working well for such a long time!!" More over we cannot just escape by answeing like - it is a case of memory overwrite which may result in inconsistent behaviour and all - So please help with a STRONG and convincing answer which we can present to any one.

Last edited by bobbyjohnz; 06-14-2006 at 04:15 AM..
# 2  
Old 06-14-2006
Quote:
Originally Posted by bobbyjohnz
More over we cannot just escape by answeing like - it is a case of memory overwrite which may result in inconsistent behaviour
Well, that is the correct answer. Smilie To elaborate a bit, the code you show is going to overwrite 10 bytes of something else nearby to "destination". Previously you must have had something expendable in those 10 bytes. But you made some changes and now something critical is being placed nearby. Most compilers have options to display the assembler code being generated. Obtain the assembler code for both versions and figure out what was being overlaid in both versions if you really feel the need to know.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need explanation

Hi, I need more explination on it, how it works abcd="$(echo "$abcd" | sed 's/ //g')" >> ${LOGFILE} 2>&1 can any one suggest me on this? Rgds, LKR (1 Reply)
Discussion started by: lakshmanraok
1 Replies

2. UNIX for Dummies Questions & Answers

Explanation on egrep

Hi all I am new to egrep can someone please explain me what does the below Statement do egrep -v "^missing sales|^\ Thanks in advance Sri Please use next time code tags for your code and data (4 Replies)
Discussion started by: Sri3001
4 Replies

3. UNIX for Dummies Questions & Answers

Filesystem explanation

Hey everyone, I just need some clarification on a filesystem question that's been bothering me. When checking df- k (output below) you can see the root filesystem, usr, var, and the disks they are mounted to at the top of the list. However below there appears to be another root filesystem... (2 Replies)
Discussion started by: blinkme323
2 Replies

4. UNIX for Dummies Questions & Answers

In need of explanation

Its great someone provided this script that strips out a filename and extension but can someone explain how each line works? file1='Jane Mid Doe.txt' newfile='Jane.txt' 1) ext=${file1##*.} 2) filename=${file%%.???} 3) set -- $filename 4) newfile="1.$extension" (1 Reply)
Discussion started by: Lillyt
1 Replies

5. UNIX for Dummies Questions & Answers

Features explanation???

HI Can anybody explain following UNIX features? Removable file system Dynamic file space allocation Thanks (1 Reply)
Discussion started by: skyineyes
1 Replies

6. Shell Programming and Scripting

Need explanation of script

Hi All, Can anybody explain what this script is doing? #!/bin/sh who | cut -d " " -f1 | sort -u > userlist1 while true ; do sleep 60 who | cut -d" " -f1 | sort -u >userlist2 for username in `cat userlist1` ; do if ! grep "^$username$" userlist2 > /dev/null ; then echo... (0 Replies)
Discussion started by: vishalpatel03
0 Replies

7. UNIX and Linux Applications

need explanation

Hi am having a c pgm. It has the include files (unistd.h,sys/types.h,win.h,scr.h,curses.h,stdarg.h and color.h). I don't know the purpose of these include files. will u plz explain me. (1 Reply)
Discussion started by: Mari.kb
1 Replies

8. Shell Programming and Scripting

tr explanation please

how does below tr command replace nonletters with newlines? I think I understand tr -cs '\n' part.. but what is A-Za-z\' <--- what is this?? tr -cs A-Za-z\' '\n' | -c --complement -s, --squeeze-repeats replace each input sequence of a repeated character that is... (1 Reply)
Discussion started by: convenientstore
1 Replies

9. Shell Programming and Scripting

tr explanation please

how does below tr command replace nonletters with newlines? I think I understand tr -cs '\n' part.. but what is A-Za-z\' <--- what is this?? tr -cs A-Za-z\' '\n' | -c --complement -s, --squeeze-repeats replace each input sequence of a repeated character that is... (0 Replies)
Discussion started by: convenientstore
0 Replies

10. Shell Programming and Scripting

AWK explanation

Hi, Could anyone please explain why we have arr=1 - what does this statement do? awk -F\; 'FNR==NR{arr=1;next};$3 in arr' core.txt gmrd.txt Any help appreciated (2 Replies)
Discussion started by: penfold
2 Replies
Login or Register to Ask a Question