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

crypto: have fixed NodeBIOs return EOF. #5105

Closed
wants to merge 1 commit into from
Closed

Conversation

agl
Copy link
Contributor

@agl agl commented Feb 5, 2016

Prior to this change, the NodeBIO objects used to wrap fixed data had
num equal to -1. This caused them to return -1 and set the retry flags
when they ran out of data. Since the data is fixed, that's incorrect.
Instead they should return zero to signal EOF.

This change adds a new, static function, NodeBIO::NewFixed to create a
BIO that wraps fixed data and which returns zero when exhausted.

The practical impact of this is limited since most (all?) the parsing
functions that these BIOs get passed to consider any return value less
than one to be EOF and ignore the retry flags anyway.

@Fishrock123 Fishrock123 added crypto Issues and PRs related to the crypto subsystem. c++ Issues and PRs that require attention from people who are familiar with C++. labels Feb 5, 2016
@Fishrock123
Copy link
Contributor

cc @nodejs/crypto

@agl agl changed the title ucrypto: have fixed NodeBIOs return EOF. crypto: have fixed NodeBIOs return EOF. Feb 5, 2016
@Trott
Copy link
Member

Trott commented Feb 6, 2016

Is it possible/reasonable to write a JS-land test for this change?

@@ -27,6 +28,21 @@ BIO* NodeBIO::New() {
}


BIO* NodeBIO::NewFixed(const char *data, size_t len) {
Copy link
Member

Choose a reason for hiding this comment

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

Nit, but let's use const char* data here. This is how it is in the rest of the file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(Done.)

@indutny
Copy link
Member

indutny commented Feb 6, 2016

@agl thank you so much for this PR. Just curious, what would be needed to be done if we were using BIO_s_mem() instead of custom BIO?

@indutny
Copy link
Member

indutny commented Feb 6, 2016

One nit, otherwise LGTM

@indutny
Copy link
Member

indutny commented Feb 6, 2016

cc @bnoordhuis

@indutny
Copy link
Member

indutny commented Feb 6, 2016

@Trott I don't think that there is any user-facing JS property or function that exposes EOF behavior of BIO buffers.

@bnoordhuis
Copy link
Member

LGTM sans nits that Fedor pointed out. CI: https://ci.nodejs.org/job/node-test-pull-request/1589/

Prior to this change, the NodeBIO objects used to wrap fixed data had
`num` equal to -1. This caused them to return -1 and set the retry flags
when they ran out of data. Since the data is fixed, that's incorrect.
Instead they should return zero to signal EOF.

This change adds a new, static function, NodeBIO::NewFixed to create a
BIO that wraps fixed data and which returns zero when exhausted.

The practical impact of this is limited since most (all?) the parsing
functions that these BIOs get passed to consider any return value less
than one to be EOF and ignore the retry flags anyway.
@agl
Copy link
Contributor Author

agl commented Feb 11, 2016

what would be needed to be done if we were using BIO_s_mem() instead of custom BIO?

OpenSSL does provide BIO_new_mem_buf for this. However, the important difference is that it doesn't make a copy of the data and depends on the given pointer out-living the BIO. That doesn't appear to be suitable here.

You can see it also does effectively the same thing as this code by setting num to zero so that the EOF behaviour is correct.

Using a plain BIO_s_mem() would work, and it would take a copy of the data if one wrote into it, but you would still have to set the EOF value because the default is -1.

@indutny
Copy link
Member

indutny commented Feb 11, 2016

Ok, thank you very much for explanation @agl !

@agl
Copy link
Contributor Author

agl commented Feb 11, 2016

Is it possible/reasonable to write a JS-land test for this change?

I did look into that and it would be possible to test this if I could find a case that pushed a different value on the error queue when the BIO returned premature EOF vs signaling an error. Somewhere in OpenSSL there is probably something that does that, but I couldn't easily find it in the code paths that node.js is using.

@indutny
Copy link
Member

indutny commented Feb 11, 2016

LGTM

@agl
Copy link
Contributor Author

agl commented Feb 11, 2016

(I amended the change, because I'm used to Gerrit, but that seems to have blown away the line comments. Sorry if that was the wrong thing to do! I believe that I address them all.)

@indutny
Copy link
Member

indutny commented Feb 11, 2016

@agl that's fine, we can still view them by clicking on them in this thread.

@indutny
Copy link
Member

indutny commented Feb 11, 2016

Landed in 773b901, thank you!

@indutny indutny closed this Feb 11, 2016
indutny pushed a commit that referenced this pull request Feb 11, 2016
Prior to this change, the NodeBIO objects used to wrap fixed data had
`num` equal to -1. This caused them to return -1 and set the retry flags
when they ran out of data. Since the data is fixed, that's incorrect.
Instead they should return zero to signal EOF.

This change adds a new, static function, NodeBIO::NewFixed to create a
BIO that wraps fixed data and which returns zero when exhausted.

The practical impact of this is limited since most (all?) the parsing
functions that these BIOs get passed to consider any return value less
than one to be EOF and ignore the retry flags anyway.

PR-URL: #5105
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Fedor Indutny <fedor@indutny.com>
rvagg pushed a commit that referenced this pull request Feb 15, 2016
Prior to this change, the NodeBIO objects used to wrap fixed data had
`num` equal to -1. This caused them to return -1 and set the retry flags
when they ran out of data. Since the data is fixed, that's incorrect.
Instead they should return zero to signal EOF.

This change adds a new, static function, NodeBIO::NewFixed to create a
BIO that wraps fixed data and which returns zero when exhausted.

The practical impact of this is limited since most (all?) the parsing
functions that these BIOs get passed to consider any return value less
than one to be EOF and ignore the retry flags anyway.

PR-URL: #5105
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Fedor Indutny <fedor@indutny.com>
stefanmb pushed a commit to stefanmb/node that referenced this pull request Feb 23, 2016
Prior to this change, the NodeBIO objects used to wrap fixed data had
`num` equal to -1. This caused them to return -1 and set the retry flags
when they ran out of data. Since the data is fixed, that's incorrect.
Instead they should return zero to signal EOF.

This change adds a new, static function, NodeBIO::NewFixed to create a
BIO that wraps fixed data and which returns zero when exhausted.

The practical impact of this is limited since most (all?) the parsing
functions that these BIOs get passed to consider any return value less
than one to be EOF and ignore the retry flags anyway.

PR-URL: nodejs#5105
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Fedor Indutny <fedor@indutny.com>
MylesBorins pushed a commit that referenced this pull request Mar 1, 2016
Prior to this change, the NodeBIO objects used to wrap fixed data had
`num` equal to -1. This caused them to return -1 and set the retry flags
when they ran out of data. Since the data is fixed, that's incorrect.
Instead they should return zero to signal EOF.

This change adds a new, static function, NodeBIO::NewFixed to create a
BIO that wraps fixed data and which returns zero when exhausted.

The practical impact of this is limited since most (all?) the parsing
functions that these BIOs get passed to consider any return value less
than one to be EOF and ignore the retry flags anyway.

PR-URL: #5105
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Fedor Indutny <fedor@indutny.com>
MylesBorins pushed a commit that referenced this pull request Mar 1, 2016
Prior to this change, the NodeBIO objects used to wrap fixed data had
`num` equal to -1. This caused them to return -1 and set the retry flags
when they ran out of data. Since the data is fixed, that's incorrect.
Instead they should return zero to signal EOF.

This change adds a new, static function, NodeBIO::NewFixed to create a
BIO that wraps fixed data and which returns zero when exhausted.

The practical impact of this is limited since most (all?) the parsing
functions that these BIOs get passed to consider any return value less
than one to be EOF and ignore the retry flags anyway.

PR-URL: #5105
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Fedor Indutny <fedor@indutny.com>
MylesBorins pushed a commit that referenced this pull request Mar 2, 2016
Prior to this change, the NodeBIO objects used to wrap fixed data had
`num` equal to -1. This caused them to return -1 and set the retry flags
when they ran out of data. Since the data is fixed, that's incorrect.
Instead they should return zero to signal EOF.

This change adds a new, static function, NodeBIO::NewFixed to create a
BIO that wraps fixed data and which returns zero when exhausted.

The practical impact of this is limited since most (all?) the parsing
functions that these BIOs get passed to consider any return value less
than one to be EOF and ignore the retry flags anyway.

PR-URL: #5105
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Fedor Indutny <fedor@indutny.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ Issues and PRs that require attention from people who are familiar with C++. crypto Issues and PRs related to the crypto subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants