sprintf() in not a buffer, could create any issue

This commit is contained in:
Patrick Siegl
2019-03-31 23:49:26 +02:00
parent 40fa7d4c2e
commit de7b6be8fd
4 changed files with 11 additions and 11 deletions

View File

@@ -60,7 +60,7 @@ static struct option longopts[] = {
{NULL, 0, NULL, 0}};
// Write the bytes to either stdout, or /dev/random.
bool outputBytes(uint8_t *bytes, uint32_t length, uint32_t entropy, bool writeDevRandom, char **message) {
bool outputBytes(uint8_t *bytes, uint32_t length, uint32_t entropy, bool writeDevRandom, const char **message) {
if (!writeDevRandom) {
if (fwrite(bytes, 1, length, stdout) != length) {
*message = "Unable to write output from Infinite Noise Multiplier";

View File

@@ -93,7 +93,7 @@ void prepareOutputBuffer() {
// changes, not both, so alternate reading bits from them. We get 1 INM bit of output
// per byte read. Feed bits from the INM to the health checker. Return the expected
// bits of entropy.
uint32_t extractBytes(uint8_t *bytes, uint32_t length, uint8_t *inBuf, char **message, bool *errorFlag) {
uint32_t extractBytes(uint8_t *bytes, uint32_t length, uint8_t *inBuf, const char **message, bool *errorFlag) {
inmClearEntropyLevel();
uint32_t i;
for (i = 0u; i < length; i++) {
@@ -202,7 +202,7 @@ bool isSuperUser(void) {
// let's do it recursive, because if sth. fails we can easily wipe the malloc()
infnoise_devlist_node_t* inf_get_devstrings(struct ftdi_context* ftdic,
struct ftdi_device_list* curdev,
char** message,
const char** message,
infnoise_devlist_node_t* bgn,
infnoise_devlist_node_t* end) {
if( curdev != NULL ) {
@@ -214,7 +214,7 @@ infnoise_devlist_node_t* inf_get_devstrings(struct ftdi_context* ftdic,
cur->description, sizeof(cur->description),
cur->serial, sizeof(cur->serial));
if (rc < 0) {
sprintf(*message, "ftdi_usb_get_strings failed: %d (%s)", rc, ftdi_get_error_string(ftdic));
*message = ftdi_get_error_string(ftdic);
free( cur );
return NULL;
}
@@ -240,7 +240,7 @@ infnoise_devlist_node_t* inf_get_devstrings(struct ftdi_context* ftdic,
// Return a list of all infinite noise multipliers found.
infnoise_devlist_node_t* listUSBDevices(char **message) {
infnoise_devlist_node_t* listUSBDevices(const char **message) {
struct ftdi_context ftdic;
if(ftdi_init(&ftdic) < 0) {
*message = "Failed to init";
@@ -267,7 +267,7 @@ infnoise_devlist_node_t* listUSBDevices(char **message) {
}
// Initialize the Infinite Noise Multiplier USB interface.
bool initializeUSB(struct ftdi_context *ftdic, char **message, char *serial) {
bool initializeUSB(struct ftdi_context *ftdic, const char **message, char *serial) {
ftdi_init(ftdic);
struct ftdi_device_list *devlist;

View File

@@ -16,7 +16,7 @@
struct infnoise_context {
struct ftdi_context ftdic;
uint32_t entropyThisTime;
char *message;
const char *message;
bool errorFlag;
//uint8_t keccakState[KeccakPermutationSizeInBytes];
@@ -41,7 +41,7 @@ struct _infnoise_devlist_node_t {
*
* returns: NULL when none found or infnoise_devlist_node
*/
infnoise_devlist_node_t* listUSBDevices(char **message);
infnoise_devlist_node_t* listUSBDevices(const char **message);
/*
* initialize the Infinite Noise TRNG - must be called once before readData() works

View File

@@ -51,14 +51,14 @@ void inmDumpStats(void);
extern double inmK, inmExpectedEntropyPerBit;
bool initializeUSB(struct ftdi_context *ftdic, char **message,char *serial);
bool initializeUSB(struct ftdi_context *ftdic, const char **message,char *serial);
void prepareOutputBuffer();
struct timespec;
double diffTime(struct timespec *start, struct timespec *end);
uint32_t extractBytes(uint8_t *bytes, uint32_t length, uint8_t *inBuf, char **message, bool *errorFlag);
uint32_t extractBytes(uint8_t *bytes, uint32_t length, uint8_t *inBuf, const char **message, bool *errorFlag);
bool outputBytes(uint8_t *bytes, uint32_t length, uint32_t entropy, bool writeDevRandom, char **message);
bool outputBytes(uint8_t *bytes, uint32_t length, uint32_t entropy, bool writeDevRandom, const char **message);
uint32_t processBytes(uint8_t *bytes, uint8_t *result, uint32_t *entropy, uint32_t *numBits, uint32_t *bytesWritten, bool raw,
uint32_t outputMultiplier);