FedericoCeratto / nim-libsodium

Nim wrapper for the libsodium library
Mozilla Public License 2.0
46 stars 13 forks source link

read from nil error when running `test_sodium.nim` #3

Open bobgus opened 7 years ago

bobgus commented 7 years ago

When I compile and run the test_sodium.nim program from the libsodium nimble pkg directory:

nim c -r ~/.nimble/pkgs/libsodium-0.1.0/test_sodium.nim

I get an error:

...
...
[Suite] hashing
  [OK] generic hashing
  [OK] generic multipart hashing
Traceback (most recent call last)
test_sodium.nim(167)     test_sodium
sodium.nim(621)          finalize
SIGSEGV: Illegal storage access. (Attempt to read from nil?)
Error: execution of an external program failed: '/Users/bobgus/.nimble/pkgs/libsodium-0.1.0/test_sodium '

I'm not sure this is a bug, or just that something is missing when compiling and running out of the pkgs directory.

bobgus commented 7 years ago

I took a look at the travis-cl.org link and he is getting the exact same error.

The routine 'finalize' is having a problem. I put an echo statement in the code

(and it appears that the nil problem is occurring at the end of the calling list. No problem with finalize with earlier items in the list.) bogus - was looking at wrong test

I commented out that whole test and everything else runs to completion.

FedericoCeratto commented 7 years ago

@bobgus I temporarily disabled the failing tests and now Travis CI is successful. Not having an OS X at hand makes the troubleshooting tricky.

bobgus commented 7 years ago

Yes, that is what I did. It certainly kills the errors.

Perhaps the real solution to the problem (if there really is one) is to wait for another version of nim, clang, or macOS.

bobgus commented 7 years ago

The error does not show on Linux?

bobgus commented 7 years ago

I was looking at the previous test - with the loop. The line 168 error is coming from the next test. Since the key string starts out with nil (see line 165), perhaps the error is the 'expected' error.

It could be a more graceful test by surrounding line 168 with a try: except: with appropriate filter and assert. It could also echo "nil in key string detected"..

bobgus commented 7 years ago

The try: except: also needs to be in the libsodium/sodium.nim around line 621, something like:

    try:
      rc = crypto_generichash_final(s, h, h_len)
    except:
      raise

I get a strange complaint:

libsodium/sodium.nim(621, 5) Error: identifier expected, but found 'keyword try'

The cause of this error is not so obvious to me at the moment.

FedericoCeratto commented 7 years ago

@bobgus was the try/except under the "let" block? It should be outside

bobgus commented 7 years ago

Yes, indented as if it were part of the "let" block.

I moved it out of the let and now things are working more rationally, but I haven't figured out everything. I am reading and learning more of your code. An educational opportunity...

bobgus commented 7 years ago

I did uninstall/install of lib sodium.

I took off the skip and # from generic multipart hashing and the test works fine (my bogus flailing from before made it suspect)

  [OK] generic multipart hashing

The generic multipart hashing key = nil is still a problem.

Traceback (most recent call last)
test_sodium.nim(169)     test_sodium
sodium.nim(621)          finalize
SIGSEGV: Illegal storage access. (Attempt to read from nil?)