The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Special Forums > Hardware > Filesystems, Disks and Memory
.
google unix.com



Filesystems, Disks and Memory Discuss NAS, SAN, RAID, Robotic Libraries, backup devices, RAM, DRAM, SCSI, IDE, EIDE topics here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
explanation for this line namishtiwari Shell Programming and Scripting 3 02-01-2008 12:51 AM
need explanation Mari.kb UNIX and Linux Applications 1 11-23-2007 10:41 AM
tr explanation please convenientstore Shell Programming and Scripting 1 05-30-2007 11:42 PM
tr explanation please convenientstore Shell Programming and Scripting 0 05-30-2007 11:12 PM
AWK explanation penfold Shell Programming and Scripting 2 04-05-2005 09:46 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-14-2006
bobbyjohnz bobbyjohnz is offline
Registered User
  
 

Join Date: May 2005
Posts: 19
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 03:15 AM..
  #2 (permalink)  
Old 06-14-2006
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
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. 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.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:45 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0