Class SanitizeInstrAsmGenerator

java.lang.Object
org.ek9lang.compiler.backend.jvm.AbstractAsmGenerator
org.ek9lang.compiler.backend.jvm.SanitizeInstrAsmGenerator
All Implemented Interfaces:
Consumer<SanitizeInstr>

final class SanitizeInstrAsmGenerator extends AbstractAsmGenerator implements Consumer<SanitizeInstr>
Specialized ASM generator for SanitizeInstr processing.

Generates JVM bytecode to sanitize a String value and store the result. The sanitization uses InputSanitizer.sanitize() which:

  • Returns an unset String if dangerous patterns are detected
  • Returns the original String if safe (no threats detected)

Includes null-safety check: if source is null, creates an unset String directly without calling sanitize. This provides defense-in-depth even though EK9 variables should never be null (they may be unset but are always allocated).

Pattern: SANITIZE destination = source

JVM Bytecode generated (with null check):

ALOAD source_slot
IFNONNULL notNull
  NEW org/ek9/lang/String
  DUP
  INVOKESPECIAL org/ek9/lang/String.<init>()V
  ASTORE dest_slot
  GOTO end
notNull:
  NEW org/ek9/lang/InputSanitizer
  DUP
  INVOKESPECIAL org/ek9/lang/InputSanitizer.<init>()V
  ALOAD source_slot
  INVOKEVIRTUAL org/ek9/lang/InputSanitizer.sanitize(Lorg/ek9/lang/String;)Lorg/ek9/lang/String;
  ASTORE dest_slot
end:
  • Constructor Details

    • SanitizeInstrAsmGenerator

      SanitizeInstrAsmGenerator(ConstructTargetTuple constructTargetTuple, OutputVisitor outputVisitor, org.objectweb.asm.ClassWriter classWriter)
  • Method Details

    • accept

      public void accept(SanitizeInstr sanitizeInstr)
      Generate JVM bytecode for a SANITIZE instruction.

      Includes null-safety check: if source is null, creates an unset String directly. Otherwise, creates InputSanitizer and calls sanitize on the source.

      Specified by:
      accept in interface Consumer<SanitizeInstr>