Skip to content

[MISRA-CERT-14] FFI extern blocks bypass all safety checks (MISRA Rule 8.1) #276

Closed

Description

@godofecht

Description

extern blocks declare C functions with no safety analysis. Any unsafe C function can be called from Flow with no warning.

extern {
    function system(cmd: string) -> i32
    function gets(buf: ptr<i8>) -> ptr<i8>
}

The type checker (src/flow/parser.py line 2049 parse_extern) accepts any extern declaration. No allowlist. No annotation required.

Standards

  • MISRA C:2024 Rule 8.1 (Required): Functions shall have prototypes.
  • MISRA C:2024 Rule 8.7 (Required): Functions and objects should not be defined with external linkage if they are not referenced by another translation unit.
  • CERT C multiple rules on unsafe C library functions.

Fix

  1. Add @unsafe attribute required on extern blocks: @unsafe extern { ... }.
  2. In --profile safety, ban all extern blocks unless individually allowlisted in flow.toml.
  3. Maintain a known-unsafe C function list (system, gets, strcpy, sprintf, atoi, etc.) and warn even in default profile.
  4. Document the FFI safety model in docs/language/ffi-safety.md.

Audit ID: MISRA-CERT-14

Severity: High | Category: Language - FFI safety

Activity

  1. added
    MISRA
    CERT
    on Aug 9, 2026
  2. added 2 commits that reference this issue on Aug 10, 2026
  3. godofecht commented on Aug 10, 2026

    @godofecht
    ContributorAuthor

    Implemented: Under --profile safety/flight, extern declarations now require @unsafe. The type checker has a DANGEROUS_EXTERN_NAMES set (system, gets, strcpy, strcat, sprintf, vsprintf, scanf, sscanf, realpath, getwd) that always requires @unsafe, regardless of profile. @safe functions cannot call @unsafe or bare extern functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    CERTMISRAcompilersecurity

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions