Skip to content

Commit 1c3a107

Browse files
committed
Handle null names in JVM extractor
Updated JvmExtractor.cs to safely handle cases where class, method, or field names may be null by providing default values. Added new dbscheme files and scripts for JVM binary extraction, and updated the binary dbscheme to support new extraction features.
1 parent d743fbf commit 1c3a107

7 files changed

Lines changed: 3175 additions & 220 deletions

File tree

binary/extractor/jvm/Semmle.Extraction.Java.ByteCode/JvmExtractor.cs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ private void ExtractClass(ClassFile classFile, string sourcePath)
8888

8989
// Get class name from constant pool - ClassConstant now has Name directly resolved
9090
var thisClassConstant = classFile.Constants.Get(classFile.This);
91-
var className = thisClassConstant.Name;
91+
var className = thisClassConstant.Name ?? "UnknownClass";
9292

9393
// Extract type (class/interface/enum)
9494
var typeId = trap.GetId();
@@ -307,7 +307,7 @@ private void ExtractCode(IKVM.ByteCode.Decoding.Attribute attr, int methodId, Cl
307307
if (!handler.CatchType.IsNil)
308308
{
309309
var catchClassConst = classFile.Constants.Get(handler.CatchType);
310-
catchType = catchClassConst.Name.Replace('/', '.');
310+
catchType = catchClassConst.Name?.Replace('/', '.') ?? "";
311311
}
312312

313313
trap.WriteTuple("jvm_exception_handler", handlerId, methodId,
@@ -584,9 +584,9 @@ private void ExtractFieldRef(Instruction instr, int instrId, ClassFile classFile
584584
var fieldRef = classFile.Constants.Get(new FieldrefConstantHandle(handle.Slot));
585585

586586
trap.WriteTuple("jvm_field_operand", instrId,
587-
fieldRef.ClassName.Replace('/', '.'),
588-
fieldRef.Name,
589-
fieldRef.Descriptor);
587+
fieldRef.ClassName?.Replace('/', '.') ?? "",
588+
fieldRef.Name ?? "",
589+
fieldRef.Descriptor ?? "");
590590
}
591591
catch
592592
{
@@ -607,33 +607,33 @@ private void ExtractMethodRef(Instruction instr, int instrId, ClassFile classFil
607607
case OpCode.InvokeVirtual:
608608
var virtHandle = instr.AsInvokeVirtual().Method;
609609
var virtRef = classFile.Constants.Get(new MethodrefConstantHandle(virtHandle.Slot));
610-
className = virtRef.ClassName.Replace('/', '.');
611-
methodName = virtRef.Name;
612-
descriptor = virtRef.Descriptor;
610+
className = virtRef.ClassName?.Replace('/', '.') ?? "";
611+
methodName = virtRef.Name ?? "";
612+
descriptor = virtRef.Descriptor ?? "";
613613
break;
614614

615615
case OpCode.InvokeSpecial:
616616
var specHandle = instr.AsInvokeSpecial().Method;
617617
var specRef = classFile.Constants.Get(new MethodrefConstantHandle(specHandle.Slot));
618-
className = specRef.ClassName.Replace('/', '.');
619-
methodName = specRef.Name;
620-
descriptor = specRef.Descriptor;
618+
className = specRef.ClassName?.Replace('/', '.') ?? "";
619+
methodName = specRef.Name ?? "";
620+
descriptor = specRef.Descriptor ?? "";
621621
break;
622622

623623
case OpCode.InvokeStatic:
624624
var statHandle = instr.AsInvokeStatic().Method;
625625
var statRef = classFile.Constants.Get(new MethodrefConstantHandle(statHandle.Slot));
626-
className = statRef.ClassName.Replace('/', '.');
627-
methodName = statRef.Name;
628-
descriptor = statRef.Descriptor;
626+
className = statRef.ClassName?.Replace('/', '.') ?? "";
627+
methodName = statRef.Name ?? "";
628+
descriptor = statRef.Descriptor ?? "";
629629
break;
630630

631631
case OpCode.InvokeInterface:
632632
var intfHandle = instr.AsInvokeInterface().Method;
633633
var intfRef = classFile.Constants.Get(new InterfaceMethodrefConstantHandle(intfHandle.Slot));
634-
className = intfRef.ClassName.Replace('/', '.');
635-
methodName = intfRef.Name;
636-
descriptor = intfRef.Descriptor;
634+
className = intfRef.ClassName?.Replace('/', '.') ?? "";
635+
methodName = intfRef.Name ?? "";
636+
descriptor = intfRef.Descriptor ?? "";
637637
break;
638638
}
639639

@@ -662,7 +662,7 @@ private void ExtractTypeRef(ConstantHandle constHandle, int instrId, ClassFile c
662662
return;
663663

664664
var classConst = classFile.Constants.Get(new ClassConstantHandle(constHandle.Slot));
665-
trap.WriteTuple("jvm_type_operand", instrId, classConst.Name.Replace('/', '.'));
665+
trap.WriteTuple("jvm_type_operand", instrId, classConst.Name?.Replace('/', '.') ?? "");
666666
}
667667
catch
668668
{

0 commit comments

Comments
 (0)