Skip to content

Commit

Permalink
Remove fwrite() from entbuff.c
Browse files Browse the repository at this point in the history
  • Loading branch information
mikemol committed Apr 16, 2012
1 parent 73b8902 commit 96cd06c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 24 deletions.
10 changes: 0 additions & 10 deletions doc/entbuff.8
Expand Up @@ -107,11 +107,6 @@ was not run with appropriate permissions to add entropy to the kernel's entropy
.B entbuff
as a user which has those capabilities.

.RE
Error writing to random device
.RS
The program was not written with write permissions to the random device file. Run the program again with the correct permissions. (Generally, root.)

.RE
Error: high threshold(%i) must be greater than low threshold(%i)
.RS
Expand Down Expand Up @@ -222,11 +217,6 @@ The error messages can be made more consistent with each other.

We could test for the ability to add entropy to the entropy pool before extract an appreciable amount.

We're currently using
.B ioctl (2)
to add entropy, and then subsequently attempting to use
.B fwrite (3)
to do the same. This is an artifact of insufficient code cleanup after adding the ioctl() call. The fwrite should no longer be there. Likewise, neither should any logs or errors dependent on it.
.SH AUTHOR
Michael Mol <mikemol at gmail dot com>

Expand Down
17 changes: 3 additions & 14 deletions src/entbuff.c
Expand Up @@ -166,23 +166,12 @@ size_t buffer_to_rand_internal(const int to_transfer)
break;
}

size_t written = fwrite(entbuff + buff_read_pos, 1, to_transfer, fdRandom);

if(0 == written)
{
if(ferror(fdRandom))
{
perror("Error writing to random device");
abort();
}
}

if(g_log_buffer_to_rand)
{
fprintf(stderr, "-W: Write. written(%zu) = buff_read_pos(%d), to_transfer(%d)\n", written, buff_read_pos, to_transfer);
fprintf(stderr, "-W: Write. buff_read_pos(%d), to_transfer(%d)\n", buff_read_pos, to_transfer);
}

buff_read_pos += written;
buff_read_pos += to_transfer;
if(g_log_buffer_to_rand)
{
fprintf(stderr,"-W: New buff_read_pos(%d)\n", buff_read_pos);
Expand All @@ -193,7 +182,7 @@ size_t buffer_to_rand_internal(const int to_transfer)
fprintf(stderr, "Internal error: READ past end of buffer!\n");
abort();
}
return written;
return to_transfer;
}

size_t buffer_to_rand(const size_t to_transfer)
Expand Down

0 comments on commit 96cd06c

Please sign in to comment.