8000 fix the calling convention on the bunch of stuff by stew · Pull Request #2877 · unisonweb/unison · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix the calling convention on the bunch of stuff #2877

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 9, 2022
Merged

Conversation

stew
Copy link
Member
@stew stew commented Feb 9, 2022

Things that were returning failures were not getting all three constructor arguments from the stack.

We were never possibly handling faliures to decodeCert correctly before. This also adds a test for certs that should fail to parse

This reinstates the test that was failing that we commented out as a fix for the recent problems with TLS handshakes

8000
@stew stew requested review from pchiusano, aryairani and dolio February 9, 2022 06:45
. TLetD fail BX (TCon Ty.failureRef 0 [stack1, stack2])
[ (0, ([BX, BX, BX],)
. TAbss [stack1, stack2, stack3]
. TLetD fail BX (TCon Ty.failureRef 0 [stack1, stack2, stack3])
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

failure has 3 constructor arguments, not two

outIoFailBox :: forall v. Var v => v -> v -> v -> v -> ANormal v
outIoFailBox stack1 stack2 fail result =
outIoFailBox :: forall v. Var v => v -> v -> v -> v -> v -> ANormal v
outIoFailBox stack1 stack2 stack3 fail result =
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

failure has 3 constructor arguments, not 2

$ outIoFailBox stack1 stack2 fail result
where (unit, stack1, stack2, fail, result) = fresh5
$ outIoFailBox stack1 stack2 stack3 fail result
where (unit, stack1, stack2, stack3, fail, result) = fresh6
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

failure has 3 constructor arguments

@stew
Copy link
Member Author
stew commented Feb 9, 2022

oops, I mislabeled the branch, this actually fixes #2834

8000

flatten (Right (Left e)) = Left (Failure Ty.tlsFailureRef (Util.Text.pack (show e)) unitValue)
flatten (Right (Right (Left e))) = Left e
flatten (Right (Right (Right a))) = Right a

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this new version operates on a a -> IO (Either Failure b) instead of a -> IO b

Left l -> Left l
asCert :: PEM -> Either String X.SignedCertificate
asCert pem = X.decodeSignedCertificate $ pemContent pem
in
declareForeign Tracked "Tls.decodeCert.impl.v3" boxToEFBox . mkForeignTls $
declareForeign Tracked "Tls.decodeCert.impl.v3" boxToEFBox . mkForeignTlsE $
Copy link
Member Author
@stew stew Feb 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

call our new version which expects us to return an Either Failure a instead of just a when we were just using the version that ignored the fact that we were returning an Either, all values looked like success unless they threw exceptions. in the case of bad data, the Left was misinterpreted as success

test> this_should_not_work=match (decodeCert.impl (toUtf8 not_a_cert) with
Left _ -> [Ok "failed"]
Right _ -> [Fail "um, that was a schmificate"]

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this catches the previous error where failures were ignored because of the broken calling convention

@@ -4,42 +4,26 @@
-- generated with:
-- openssl req -newkey rsa:2048 -subj '/CN=test.unison.cloud/O=Unison/C=US' -nodes -keyout key.pem -x509 -days 3650 -out cert.pem

join strs = List.foldLeft (a -> b -> b ++ a ++ "\n") "" strs
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was broken, it should have been b ++ "\n" ++ a and this is why adding a newer cert didn't work and exposed the big in decodeCert

@aryairani
Copy link
Contributor

Amazing, thanks @stew. I will hold off on ✅ because I don't know enough about the runtime.

@stew
Copy link
Member Author
stew commented Feb 9, 2022

I think that this shows that a lot of our IO stuff is under tested, especially in the Failure cases

@stew
Copy link
Member Author
stew commented Feb 9, 2022

Amazing, thanks @stew. I will hold off on white_check_mark because I don't know enough about the runtime.

I will continue on the path of fixing very complex bugs that I myself introduced in order to make myself look smarter ;)

Copy link
Contributor
@dolio dolio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these changes look okay; at least the parts that I'm familiar with.

@pchiusano pchiusano merged commit df3fd3d into trunk Feb 9, 2022
@pchiusano pchiusano deleted the fix/2387 branch February 9, 2022 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0