Does anyone have any idea of why this could happen?
I have a C program in AIX 5.3, I've been asked to run it on a SPARC Solaris 10 machine, but when I did it, I noticed there was a buffer overflow with one of the many reckless strcat uses. My goal is not to sanitize the code but to provide a concrete and well founded answer of why does this overflow happens on Solaris and not on AIX being the exact same bad coded program.
I've been reading a bit about if this could be caused by:
endianess diffs between AIX and Solaris.Execution of the strcat function (AIX copies right to left and Solaris left to right) but I haven't been able to find any documentation on this.
- Plain and simple luck that this issue doesn't occur on AIX.
Any light you could shed on this is highly appreciated.
EDIT: could this be avoided with the noexec_user_stack flag on solaris?
EDIT 2: Does anyone have any info on the way both OSes do the actual byte copying? in a situation like the option 2 above?
EDIT 3: Here's the chunk of code:
/*global*/
char bufferA[101];
/*inside function*/
bufferA[0]='\0';
strcpy(bufferA,"1");
if (atoi(something)==0) {
strcat(bufferA,pieces_of_data);
count ++ ;
}
obviously theres more of it but this is the only part where bufferA is being used, and there 2 variables declared global after bufferA that become corrupted with the last part of the last string appended to bufferA.
As i said before, if i change the declaration from 101 to 201 the corruption does not occur.
EDIT 4: does anyone know anything about the -misalign and -misalign2 compiler options on solaris? could there be any light with these options? Actually a better question would be: is there any difference between AIX powerPC and Solaris SPARC regarding alignment? altough this is probably a question for serverfault but please share if you know something.