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
Conversation
crypto/rand/randfile.c
Outdated
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); |
There was a problem hiding this comment.
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);
crypto/rand/randfile.c
Outdated
#endif | ||
for (;;) { | ||
if ((in = openssl_fopen(file, "rb")) == NULL) { | ||
RANDerr(RAND_F_RAND_LOAD_FILE, RAND_R_CANNOT_FOPEN); |
There was a problem hiding this comment.
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?
crypto/rand/randfile.c
Outdated
return 1; | ||
} | ||
if (stat(file, &sb) >= 0 && !S_ISREG(sb.st_mode)) { | ||
RANDerr(RAND_F_RAND_WRITE_FILE, RAND_R_NOT_IFREG); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same thing here
Okay, additional commit pushed that does your suggestions, @levitte
|
Cool. I'll do a double check on VMS tomorrow (way too tired to do it now) |
so, @levitte did I break VMS or did it work? :) |
[ahem] I was distracted... trying it now |
You’re not allowed to have a life ☺
|
Stop scaring me ;-) |
There was a problem hiding this 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.
Thanks! commit 9ee344f |
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)) |
There was a problem hiding this comment.
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
...
Good point. New PR coming up.
|
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.