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

Cleanup RAND_load_file,RAND_write_file #3864

Closed
wants to merge 1 commit into from
Closed

Cleanup RAND_load_file,RAND_write_file #3864

wants to merge 1 commit into from

Conversation

richsalz
Copy link
Contributor

@richsalz richsalz commented Jul 5, 2017

Document an internal assumption that these are only for use with files,
and return an error if not. That made the code much simpler.
Also only write 256 bytes, we don't need more than that from a security
perspective.

This was pulled out from #3862.

@richsalz richsalz added branch: master Merge to master branch approval: review pending This pull request needs review by a committer labels Jul 5, 2017
@richsalz richsalz self-assigned this Jul 5, 2017
@richsalz richsalz mentioned this pull request Jul 5, 2017
bytes = (bytes == -1) ? 2048 : bytes; /* ok, is 2048 enough? */
setbuf(in, NULL); /* don't do buffered reads */
if (stat(file, &sb) < 0 || !S_ISREG(sb.st_mode)) {
RANDerr(RAND_F_RAND_LOAD_FILE, RAND_R_NOT_IFREG);
Copy link
Member

Choose a reason for hiding this comment

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

Please make that RAND_R_NOT_A_REGULAR_FILE. You might also want to add something like this:

        ERR_add_error_data(2, "Filename=", file);

#endif
for (;;) {
if ((in = openssl_fopen(file, "rb")) == NULL) {
RANDerr(RAND_F_RAND_LOAD_FILE, RAND_R_CANNOT_FOPEN);
Copy link
Member

Choose a reason for hiding this comment

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

RAND_R_CANNOT_OPEN_FILE, and perhaps same additional data as above?

return 1;
}
if (stat(file, &sb) >= 0 && !S_ISREG(sb.st_mode)) {
RANDerr(RAND_F_RAND_WRITE_FILE, RAND_R_NOT_IFREG);
Copy link
Member

Choose a reason for hiding this comment

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

Same thing here

@richsalz
Copy link
Contributor Author

richsalz commented Jul 5, 2017 via email

@levitte
Copy link
Member

levitte commented Jul 5, 2017

Cool. I'll do a double check on VMS tomorrow (way too tired to do it now)

@richsalz
Copy link
Contributor Author

richsalz commented Jul 6, 2017

so, @levitte did I break VMS or did it work? :)

@levitte
Copy link
Member

levitte commented Jul 6, 2017

[ahem] I was distracted... trying it now

@richsalz
Copy link
Contributor Author

richsalz commented Jul 6, 2017 via email

@levitte
Copy link
Member

levitte commented Jul 6, 2017

Stop scaring me ;-)

Copy link
Member

@levitte levitte left a comment

Choose a reason for hiding this comment

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

I appears fine on VMS too

Document an internal assumption that these are only for use with files,
and return an error if not. That made the code much simpler.
Leave it as writing 1024 bytes, even though we don't need more than 256
from a security perspective.  But the amount isn't specified, now, so we
can change it later if we want.
@richsalz
Copy link
Contributor Author

richsalz commented Jul 6, 2017

Thanks! commit 9ee344f

@richsalz richsalz closed this Jul 6, 2017
@richsalz richsalz deleted the update-rand-file branch July 6, 2017 18:11
levitte pushed a commit that referenced this pull request Jul 6, 2017
Document an internal assumption that these are only for use with files,
and return an error if not. That made the code much simpler.
Leave it as writing 1024 bytes, even though we don't need more than 256
from a security perspective.  But the amount isn't specified, now, so we
can change it later if we want.

Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from #3864)
* As for the buffer parameter, we only use NULL here, so that passes as
* well...
*/
# define setbuf(fp,buf) (setbuf)((__FILE_ptr32)(fp), (char_ptr32)(buf))
Copy link
Contributor

Choose a reason for hiding this comment

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

If this is removed, then one doesn't need typedef char *char_ptr32...

@richsalz
Copy link
Contributor Author

richsalz commented Jul 6, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approval: review pending This pull request needs review by a committer branch: master Merge to master branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants