Need Help

P

pycraze

Hi ,

I am working on Fedora core 5 and my OS version is
2.6.15-1.2054_FC5 . My GCC version is 4.1.1 20070105 (Red Hat
4.1.1-51) .

I am currently using the openssl libraries to write a simple
base64 encode routine and base64 decoding routine . My openssl version
is 0.9.8a 11 Oct 2005 .

I had did numerous unit testing of my base64 encoding and
decoding schemes and i did not get face any SigSEGV from any of the
libraries from openssl . After completing my extensive unit testing ,
i merged with my application and the below error occurs -

"Program received signal SIGSEGV, Segmentation fault.
0x003577da in SSLeay_version () from /lib/libcrypto.so.6"


Below i have attached by code for base64 decoding technique where
the above error is actually occurring . This code has been picked
from the www.openssl.org , after some very minute modifications .

-------------------------------------------------------------------------------------------------------------------------------------------------

int base64_decodestring(char* pcto_decode,char** ppcdecoded_string)
{
BIO* bio = NULL ;
BIO* bmem = NULL ;
BIO* b64 = NULL ;
BUF_MEM* bptr = NULL ;

*ppcdecoded_string = (char *)malloc(sizeof(char)*2048);
if (!*ppcdecoded_string)
{
printf("malloc failed");
return 1;
}
memset(*ppcdecoded_string, 0,sizeof(char)*2048);

b64 = BIO_new(BIO_f_base64());
bmem = BIO_new_mem_buf(pcto_decode, strlen(pcto_decode));
bmem = BIO_push(b64, bmem);
BIO_read(bmem,*ppcdecoded_string,strlen(pcto_decode));
BIO_flush(bmem);
BIO_free_all(bmem);
BIO_free_all(b64);
return 0;
}

--------------------------------------------------------------------------------------------------------------------------------------------

i will also show the core dump below :-

#1 0x003aa1be in lh_retrieve () from /lib/libcrypto.so.6
(gdb) bt
#0 0x003577da in SSLeay_version () from /lib/libcrypto.so.6
#1 0x003aa1be in lh_retrieve () from /lib/libcrypto.so.6
#2 0x00357e1c in CRYPTO_get_ex_data_implementation () from /lib/
libcrypto.so.6
#3 0x003582fc in CRYPTO_get_ex_data_implementation () from /lib/
libcrypto.so.6
#4 0x00357b79 in CRYPTO_new_ex_data () from /lib/libcrypto.so.6
#5 0x003a1654 in BIO_set () from /lib/libcrypto.so.6
#6 0x003a16ea in BIO_new () from /lib/libcrypto.so.6
#7 0x08055df4 in base64_decodestring (
pcto_decode=0x9030250
"TlRMTVNTUAACAAAACQAJADgAAAAGgoICpprSq2j8BOYAAAAAAAAAAFwAXABBAAAABQLODgAAAA9S
\nSUNPSC1JSVMCABIAUgBJAEMATwBIAC0ASQBJAFMAAQASAFIASQBDAE8ASAAtAEkASQBTAAQAEgBS
\nAEkAQwBPAEgALQBJAEkAUwADABIAUgBJAEMATwBIAC0ASQ"...,
ppcdecoded_string=0xbf83610c) at base64_openssl.c:39

-----------------------------------------------------------------------------------------------------------------------------------


I cannot figure out why there could be an error from the shared
libraries . This is a big work - stopper .

Please Help !
 
J

Jens Thoms Toerring

pycraze said:
I am currently using the openssl libraries to write a simple
base64 encode routine and base64 decoding routine . My openssl version
is 0.9.8a 11 Oct 2005 .
I had did numerous unit testing of my base64 encoding and
decoding schemes and i did not get face any SigSEGV from any of the
libraries from openssl . After completing my extensive unit testing ,
i merged with my application and the below error occurs -
"Program received signal SIGSEGV, Segmentation fault.
0x003577da in SSLeay_version () from /lib/libcrypto.so.6"
Below i have attached by code for base64 decoding technique where
the above error is actually occurring . This code has been picked
from the www.openssl.org , after some very minute modifications .
int base64_decodestring(char* pcto_decode,char** ppcdecoded_string)
{
BIO* bio = NULL ;
BIO* bmem = NULL ;
BIO* b64 = NULL ;
BUF_MEM* bptr = NULL ;
*ppcdecoded_string = (char *)malloc(sizeof(char)*2048);

There's no good reason (for most people;-) to cast the return
value of malloc() - it only keeps the compiler from telling
if (!*ppcdecoded_string)
{
printf("malloc failed");
return 1;
}
memset(*ppcdecoded_string, 0,sizeof(char)*2048);
b64 = BIO_new(BIO_f_base64());
bmem = BIO_new_mem_buf(pcto_decode, strlen(pcto_decode));
bmem = BIO_push(b64, bmem);
BIO_read(bmem,*ppcdecoded_string,strlen(pcto_decode));
BIO_flush(bmem);
BIO_free_all(bmem);
BIO_free_all(b64);
return 0;
}
I cannot figure out why there could be an error from the shared
libraries . This is a big work - stopper .

The error is rather likely not in the original ssl library,
it's only the place where an error you made somewhere else
in your program before shows its effects. You have some kind
of memory corruption going on in your program. Probably you
have somewhere a pointer that you use despite it not pointing
to memory you have the permission to write to and thus write
accidentally over some memory used internally by the C or the
ssh library. It is for example not uncommon that a program
crashes in some completely innocent function like printf() in
these situation. It's unfortunatelly impossible to say where
there real problem is - it could be thousands of lines of code
executed before.

If you hadn't modified the ssl library I would say not to waist
any time on the ssl library. But since you did the problem could
be there - that it worked before under different circumstances
does not prove anything, unfortunately you often get away with
broken code (there are even cases where such a problem only
shows up when you run a program normally but not anymore when
you run it under a debugger or vice versa). But just because
the effect of the error crashes your program in the ssl library
doesn't mean that the error is there. Check your code and the
modifications to the ssl library for mistakes. Look carefully
at all places where you allocate and free memory and check that
you never use pointers that not point to memory you "own". If
you can't find the reason get yourself a memory debugger.

<OT> On Linux the C library comes with some support for memory
debugging, see the libc documentation. And then there are se-
veral free memory debuggers like valgrind, mpatrol, Electric
Fence, dmalloc etc. as well as some you have to pay for. </OT>

Regards, Jens
 
A

Army1987

Hi ,

I am working on Fedora core 5 and my OS version is
2.6.15-1.2054_FC5 . My GCC version is 4.1.1 20070105 (Red Hat
4.1.1-51) .

I am currently using the openssl libraries to write a simple
base64 encode routine and base64 decoding routine . My openssl version
is 0.9.8a 11 Oct 2005 .

I had did numerous unit testing of my base64 encoding and
decoding schemes and i did not get face any SigSEGV from any of the
libraries from openssl . After completing my extensive unit testing ,
i merged with my application and the below error occurs -

"Program received signal SIGSEGV, Segmentation fault.
0x003577da in SSLeay_version () from /lib/libcrypto.so.6"


Below i have attached by code for base64 decoding technique where
the above error is actually occurring . This code has been picked
from the www.openssl.org , after some very minute modifications .

-------------------------------------------------------------------------------------------------------------------------------------------------

int base64_decodestring(char* pcto_decode,char** ppcdecoded_string)
{
BIO* bio = NULL ;
BIO* bmem = NULL ;
BIO* b64 = NULL ;
BUF_MEM* bptr = NULL ;

*ppcdecoded_string = (char *)malloc(sizeof(char)*2048);
sizeof(char) is always 1. And that cast is useless.
*ppcdecoded_string = malloc(2048);
if (!*ppcdecoded_string)
{
printf("malloc failed");
Write that to stderr, rather than to stdout, and I'd end the
warning with a newline. Also, since you return a value, you can
have the caller print the warning if base64_decodestring() returns
1.
return 1;
}
memset(*ppcdecoded_string, 0,sizeof(char)*2048);

b64 = BIO_new(BIO_f_base64());
bmem = BIO_new_mem_buf(pcto_decode, strlen(pcto_decode));
What does that function do? If, as I guess, it duplicates the
first arg2 bytes of arg1 into a new object, you need to use
strlen(pcto_decode) + 1 to make room for the terminating '\0'.
But this is a guess.
 
P

pycraze

sizeof(char) is always 1. And that cast is useless.
*ppcdecoded_string = malloc(2048);


Write that to stderr, rather than to stdout, and I'd end the
warning with a newline. Also, since you return a value, you can
have the caller print the warning if base64_decodestring() returns
1.> return 1;


What does that function do? If, as I guess, it duplicates the
first arg2 bytes of arg1 into a new object, you need to use
strlen(pcto_decode) + 1 to make room for the terminating '\0'.
But this is a guess.

Thanks for your inputs, will try and will get back .
 
A

Army1987

sizeof(char) is always 1. And that cast is useless.
*ppcdecoded_string = malloc(2048);


Write that to stderr, rather than to stdout, and I'd end the
warning with a newline. Also, since you return a value, you can
have the caller print the warning if base64_decodestring() returns
1.> return 1;


What does that function do? If, as I guess, it duplicates the
first arg2 bytes of arg1 into a new object, you need to use
strlen(pcto_decode) + 1 to make room for the terminating '\0'.
But this is a guess.
[snip signature]
Thanks for your inputs, will try and will get back .
But since these functions are not standard C, you'd better ask in
a group about that which defines them (or to post its source here,
if you wrote them yourself).
 
M

msaugat

If you want to decode then should you not be using

BIO_read(b64,*ppcdecoded_string,strlen(pcto_decode));


If you read from bmem, then you should only get the content of
pcto_decode.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,123
Latest member
Layne6498
Top