Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#313 Java STRING_ARRAY output typemap could dereference a NULL

closed
general (37)
5
2012-04-28
2012-04-27
Leo Davis
No

I was examining the JNI output from SWIG and noticed that I could get a NULL pointer dereference if I was wrapping char** foo(void) with
a STRING_ARRAY and foo() returned NULL:

result = (char **)foo();
{
int i;
int len=0;
jstring temp_string;
const jclass clazz = (*jenv)->FindClass(jenv, "java/lang/String");

while (result[len]) len++; // dereference NULL here
...

The patch I attached simply wraps all the %typemap(out) code in an if test.

Discussion

  • Leo Davis
    Leo Davis
    2012-04-27

    patch based on SWIG 2.0.5 which should fix the problem

     
  • Leo Davis
    Leo Davis
    2012-04-27

    Simple input file demonstrating the problem.

     
    Attachments
  • William Fulton
    William Fulton
    2012-04-28

    Thanks, applied for swig-2.0.6 along with a further fix for the 'in' typemap to handle null pointers.

     
  • William Fulton
    William Fulton
    2012-04-28

    • assigned_to: nobody --> wsfulton
    • status: open --> closed