Skip to content
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

Remove unsafe access to Socket.Address #93

Merged
merged 1 commit into from
Oct 26, 2017

Conversation

mcfedr
Copy link
Contributor

@mcfedr mcfedr commented Oct 11, 2017

Description

asAddr funcs were passing unsafe pointers outside of the callbacks in which try should be used
Using callback to make all the access within these callbacks

Motivation and Context

Fixes bug where IPv6 address was 'cast' to sockaddr but actually was zero'd beyond the length of sockaddr_in and packets written to the wrong address

Checklist:

  • I have submitted a CLA form
  • [N/A] If applicable, I have updated the documentation accordingly.
  • [N/A] If applicable, I have added tests to cover my changes.

@mcfedr
Copy link
Contributor Author

mcfedr commented Oct 11, 2017

I think this might need some review, unfortunately the diff is worse than it needs to be because quite a bit of code just gets indented

@billabt
Copy link
Collaborator

billabt commented Oct 11, 2017

Yeah, this’ll take awhile. I’ll get to it as soon as I can. At a quick glance, I like it a lot. I’ve always been a bit leery of these functions and was never quite satisfied. Did you submit a CLA? Unfortunately, I can’t take the contribution without one.

@mcfedr
Copy link
Contributor Author

mcfedr commented Oct 11, 2017

Ok, ill see about the CLA asap. Tomorrow I'll have time to test the changes I've made a bit more thoroughly, I wanted to throw it up here now. I think there are quite a few more manipulations of sockaddr that could be changed as well, although the others look like that shouldn't cause problems.

With this I was trying to write packet to some IP address aaaa::bbbb:cccc, but they were actually written to aaaa::bbbb:0000

@mcfedr
Copy link
Contributor Author

mcfedr commented Oct 11, 2017

Must say, its not very encouraging for the open source nature of the project having to give IBM a license to do what they want with the code.

@billabt
Copy link
Collaborator

billabt commented Oct 11, 2017

I know what you mean. It’s the lawyers who’ve gummed up the works. I’m getting ready to retire on November 2 and still plan on maintaining this and a few other repos that I’m responsible for and I found out that after I retire, I’ll need to submit a CLA if I want to keep maintaining them. Go figure!!! 🤣

asAddr funcs were passing unsafe pointers outside of the callbacks in which try should be used
Using callback to make all the access within these callbacks
Fixes bug where IPv6 address was 'cast' to sockaddr but actually was zero'd beyond the length of sockaddr_in and packets written to the wrong address
@codecov-io
Copy link

codecov-io commented Oct 12, 2017

Codecov Report

Merging #93 into master will increase coverage by 1.15%.
The diff coverage is 53.96%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #93      +/-   ##
==========================================
+ Coverage   49.31%   50.46%   +1.15%     
==========================================
  Files           3        3              
  Lines        2610     2473     -137     
==========================================
- Hits         1287     1248      -39     
+ Misses       1323     1225      -98
Flag Coverage Δ
#Socket 50.46% <53.96%> (+1.15%) ⬆️
Impacted Files Coverage Δ
Sources/Socket/Socket.swift 52.5% <49%> (+0.61%) ⬆️
Sources/Socket/SocketUtils.swift 28.2% <73.68%> (+10.7%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 60cf41b...2d58a7a. Read the comment docs.

@billabt
Copy link
Collaborator

billabt commented Oct 19, 2017

@mcfedr Did you decide whether or not to submit a CLA? I've just about completed the review of this PR and anticipate being able to accept it soon providing I have a CLA. Thanks.

@mcfedr
Copy link
Contributor Author

mcfedr commented Oct 19, 2017 via email

@billabt
Copy link
Collaborator

billabt commented Oct 20, 2017

@mcfrdr: Can you send me a copy? Apparently he hasn’t received it. Please send to my email address, babt@me.com. Thanks.

@mcfedr
Copy link
Contributor Author

mcfedr commented Oct 20, 2017 via email

@billabt
Copy link
Collaborator

billabt commented Oct 23, 2017

@mcfedr: I've got just one concern with this PR. Maybe there's a way around it, maybe it's the best or only way of doing it. Not sure. The concern is using the exception mechanism to control flow like you do with NotAnError. It's definitely a novel way of doing it but it almost seems abusive of the exception mechanism, no? I've been looking at a better way of doing it but so far have come up blank. Did you also look at alternative ways?

The biggest issue I have with using the exception mechanism for normal flow is performance. It's kinda heavy handed.

On the plus side, the only time that NotAnError is thrown is when the accept is interrupted so I guess you could call that an exception to the normal flow.

If I (or you) can't come up with a better way by Wednesday, I'm going to go with it and do the merge. However, I do request that you change the name of NotAnError to OperationInterrupted or something similar. Makes it clearer to a reader exactly what is going on and why the exception is being thrown.

Thanks.

@mcfedr
Copy link
Contributor Author

mcfedr commented Oct 23, 2017

I agree, it felt wrong writing it, but its the only way I could think of to do that early return inside the closures.

Your name is much better, I'll definitely make that change.

@billabt
Copy link
Collaborator

billabt commented Oct 23, 2017

Ok, cool. I'm in agreement. Make the name change and once it passes CI, I'll do the merge. Thanks.

@billabt
Copy link
Collaborator

billabt commented Oct 23, 2017

@mcfedr: Something like this maybe?

enum OperationInterrupted:  Swift.Error {
    case accept
}

Then throw it like this...

throw OperationInterrupted.accept

Indicating the accept operation was interrupted.

@billabt
Copy link
Collaborator

billabt commented Oct 25, 2017

@mcfedr: If it's ok with you, I'll do the merge and then make the change as I outlined above and then do the release.

@billabt billabt merged commit eaddb73 into Kitura:master Oct 26, 2017
billabt pushed a commit that referenced this pull request Oct 26, 2017
billabt pushed a commit that referenced this pull request Oct 26, 2017
…was included in PR #93.  This makes things clearer.  Also, made the new exception part of Socket to avoid redundant declarations.
@mcfedr
Copy link
Contributor Author

mcfedr commented Oct 26, 2017 via email

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.

None yet

3 participants