Skip to content

{.push ... .} pragma stack usage leak with isErrOr and isOkOr #55

@tersec

Description

@tersec

Maybe other callables too.

import results

{.push raises: [].}

proc r() =
  default(Result[int, int]).isErrOr:
    discard

{.pop.}

import std/os
proc n() = createDir("")

For example.

This is happening with at least

Nim Compiler Version 2.0.14 [Linux: amd64]
Compiled at 2025-03-10
Copyright (c) 2006-2023 by Andreas Rumpf

git hash: bf4de6a394e040d9810cba8c69fb2829ff04dcc6
active boot switches: -d:release

The issue is that these templates under certain conditions:

nim-results/results.nim

Lines 1353 to 1354 in df8113d

when pushGenericsOpenSym:
{.push experimental: "genericsOpenSym".}

which means that the {.pop.} in the example above does not pop {.push raises: [].} but rather this {.push experimental: "genericsOpenSym".}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions