Skip to content

Assertions not triggering with -O and test suite failure #44

@nh2

Description

@nh2

Hi,

version 0.11.4.16.

When you test with ./Setup build test:test-evp-base64 --ghc-option=-O0 or in ghci, then a test failure occurs (I've inserted some more stack traces and prints for your convenience):

in assertFunction: print (n, x, y, r)
("decodeBase64BS","YWJjZGVmZ2hpams=\n","abcdefghijk","decodeBlock "YWJjZGVmZ2hpams=\n"
*** Exception: Assertion failed
CallStack (from HasCallStack):
  assert, called at ./OpenSSL/EVP/Base64.hs:111:45 in main:OpenSSL.EVP.Base64
  decodeBlock, called at ./OpenSSL/EVP/Base64.hs:130:18 in main:OpenSSL.EVP.Base64
  decodeBase64BS, called at Test/OpenSSL/EVP/Base64.hs:51:37 in main:Main

This assertion triggers: https://github.com/vshabanov/HsOpenSSL/blob/a9efae0b598b9499443721a1989055ca017fd01f/OpenSSL/EVP/Base64.hs#L109-L111

This is because in the test https://github.com/vshabanov/HsOpenSSL/blob/master/Test/OpenSSL/EVP/Base64.hs#L49-L58

the last test case, "YWJjZGVmZ2hpams=\n" has 17 chars, and 17 mod 4 is not 0.

This assertion failure usually goes completely unnoticed, because assertions are compiled away when -O is used (which is the default).

Are these assertions relevant for security or correctness?

If yes, then they should not be assertions, because assertions should not be used for control flow and input validation. Alternatively, -fno-ignore-asserts can be used.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions