Pointer corruption when passed from a different file Fedora 17

96 views Asked by At

Has anyone come across this issue of pointer getting corrupted in Fedora Core 17 64bit

Linux (none) 3.3.4-5.fc17.x86_64 #1

gcc gcc (GCC) 4.7.2 20120921 (Red Hat 4.7.2-2)

For instance I have files A.c containing function aaa() returning or accepting some pointer and B.c has a function bbb() returning or accepting some pointer. In my scenario I am passing a context pointer from bbb() to aaa() and here is what i pass

values e n d 0x2b440c0 0x2b4a190 0x2b57db0

and here is what I receive in function aaa()

values e n d 0x2b440c000000000 0x2b57db000000000 0x0

I am not running any compiler optimization flags on this. Although if I maintain both the functions in one file, things work properly as expected.

Have added some code here that might help

file: src/enc/encrypt.c
function PopulateEncryptionKeys

 dataEncrypt->stRsa = RSA_new();   ---> this is ok  0x21d0440
     if(dataEncrypt->stRsa == NULL)
     {

         return FALSE;
     }


     dataEncrypt->stRsa->e = BN_bin2bn("<hex data>", 1, dataEncrypt->stRsa->e);
     dataEncrypt->stRsa->n = BN_bin2bn(dataEncrypt->m_nPublicKey, val, dataEncrypt->stRsa->n);
     dataEncrypt->stRsa->d = BN_bin2bn(dataEncrypt->m_nPrivateExponent, val, dataEncrypt->stRsa->d);  ----> these are ok
     RSA_blinding_off(dataEncrypt->stRsa);


file: src/enc/encrypt.c
function: Decipher

keyRetVal = RSAPrivateDecrypt(nDecryptedMessage,nDataBuffer,m_dataEncryption->stRsa,val,var);

Uptill this the values of e n and d above are
values e n d 0x2364090 0x23640d0 0x23a2c10

This function calls another function part of crypto wraper, which inturn is supposed to to call BN_bn2bin

file: src/crypto/wrapper.c
function: RSAPrivateDecrypt

int RSAPrivateDecrypt(unsigned char *decryptedBuffer,unsigned char *data, RSA* rsa, int flen, int reverseKeyData)

RSAPrivateDecrypt: rsa is 0x20cc440 e n d 0x229ec1000000000 0x226009000000000 (nil)

Any thoughts on this?

Appreciate, Thanks

1

There are 1 answers

0
user1663533 On BEST ANSWER

I have figured out the answer, a basic forward decleration issue. While porting to 64bit from 32bit if you have any function that is not declared before it is called, then any pointers it returns will be stripped to 32 bit. Read it online and trace back my complex code to that. Hope this helps someone.

Regards