[solved] Application behaving in 3 different ways on 3 different machines
Hello.
During the holidays I've been developing an application on my desktop computer at home.
I setup a repository on github, so when I got back to work I cloned the repo to my laptop.
It wouldn't work.
The app is comprised of a client and a server, strangely enough the server would segfault at a strcpy at the very beginning, while the client would bug me about not supplying a command line parameter (it's supposed to work anyway).
So I ssh-ed into an office machine we use to test things out, cloned the repo and the problems are inverted!
Now it's the client that would segfault while the server pretends a parameter!
My machines are
desktop - i7 2600k with Ubuntu 12.04 x64 eng
laptop - core2duo with Ubuntu 12.04 x64 eng
test pc - core2duo with Ubuntu 10.04 ita (dunno if x86 or x64)
Now I could bear that an app developed on a single pc would require some tinkering on other pcs, but the same app displaying exactly symmetrical behaviour on two different pcs I can't understand.
Anyway the specific code that seems to be the problems is the following
either I get a segfault at the strcpy or somehow the argp_parse exits the program.
I'm not an expert enough to understand why declaring the following is correct
while this is wrong
And even more so I can't understand why, if it's wrong, it would work on my desktop computer!
Any help is really appreciated.
Last edited by erupter; 01-07-2013 at 10:16 AM..
Reason: solved
The fact that your code ever worked is an accident. You have what is called undefined behavior
They are pointers to a character string. They have NO memory allocated to them.
Change them like this (pick a number I chose 256...) :
Or call
to allocate memory for each one in main().
You code did not work, it just happened not to crash. Because those pointers are never initialized they could be pointing to any bit of memory left over from a previous program. If you rebooted one of the PC's you may get different behavior. It is purely random, so it may not be something you can duplicate.
Last edited by jim mcnamara; 01-07-2013 at 08:16 AM..
There is a set of standards for C. They dictate what will or will not happen in the language.
Doing what you did created something that has undefined behavior. I'll make one pass at this.
When you run a C program:
I will disagree VERY slightly with Jim concerning #3 in the above list. On any UNIX system, data allocated to one process will never be given to another process for use as the stack of a new process. Doing so would create a security hole (covert channel).
Code may be shared between processes (using shared libraries); data may be shared using shared libraries, shared memory segments, mmap()ed files, etc. But address space that will be used as data (including the stack) that is not explicitly shared, will be cleared by the OS before handing it to any user-level process.
There is a lot of code run by a process when a C program starts executing before you get to the first line of code in main(). Shared libraries have to be linked in; the locale has to be initialized; the STDIO stdin, stdout, and stderr streams have to be initialized; etc. Any of these can leave random data in what will eventually become the stack frame allocated to main(), and some of them may leave different things on the stack depending on the time/date when the program was run, the version of the OS or shared libraries being used, etc.
So, the end result is the same. Uninitialized data on the stack of main() can vary from run to run. And if you have other uninitialized pointers being used by argp_parse() or s_catch_signals(), they may also be overwriting anything in your address space and may get segmentation faults on some future execution of your code.
Can anyone explain why wc is behaving weirdly? Their are only 2 occurrences but wc thinks their are 7 occurrences. I have even manually checked this.
$ grep -i base *
lit: base xx
lit.lst:003- 00103 BASE XX
$ grep -i base * | wc -w ... (2 Replies)
Hi,
Immediate help on below will be appreciated.
I have to read a file (max of 10MB) which will have no new line characters, i.e. data in single line. and have to inster '\n' at every 100 characters. and if record starts with 'BUCA' then need to pick value of length 10 at position 71 and... (7 Replies)
Hello. I need upgrade memcached. This software is installed throuth yum. In official repositories isn`t newest version of memcached, but this one is vulnerable. So looks like I need built it from source, but I dont really want to install c libraries un compilers on system.
1.) So can I compile... (0 Replies)
I have two servers on same domain. one can nslookup other cannot
Psu100 can lookup to psu000, psu010 & psu011
Psu110 can NOT lookup to psu000, psu010 & psu011
I verified resolv.conf entries on both psu000 and psu010 and it contains both name servers (10.200.10.21 & 10.200.11.22).I am... (1 Reply)
Hi Gurus,
I tried FTP one file to UNIX which got values like
wel^come
If I see the content in unix, it shows like
wel^Zcome
^ coverted into ^Z (Control + Z )
Can someone please share what is happening here?
Thanks,
Shahnaz (5 Replies)
Im trying to execute the below command on our server to list files and replace the newline in the file list with spaces, but the character 'n' is getting replaced with a space, is there any environment variable that needs to be set in UNIX?
sh -c 'ls -trx... (1 Reply)
I have a set up of 5 machines which are connected in same network.
Now i want to run a small application so that those machines are not ideal. (0 Replies)
I have a large file with the first 2 characters of each line determining the type of record. type 03 being a subheader and then it will have multiple 04 records.
eg: 03,xxx,xxxx,xxxx
04,xxxxxxxxxxxxxxxxxxxxxxxxxxxx
04,xxxxxxxxxxxxxxxxxxxxxxxxxxxx
03,xxx,xxx,xxx
... (2 Replies)
Hi,
I am working on a custom made FTP application. The application is behaving erratically for the "ls" command. Wild card character passed to the "ls" command (like "ls *temp") is giving inconsistent results. On debuggin I have found that the "ls" command is implemented as shown below in the... (7 Replies)