getrandomtext did not work as expected. needed to set a better seed

master
Steffen Pohle 1 month ago
parent 7239983744
commit 1a0e166f55

1
.gitignore vendored

@ -4,6 +4,7 @@ fbconfig.config
*.o *.o
*.so.* *.so.*
*.so *.so
test-getrandom
test-webserver test-webserver
test-json test-json
test-ssl test-ssl

@ -1,3 +1,7 @@
2026-04-15:
- getrandomtext did not init with a good seed value. using the sample from the
linux man pages.
2026-04-04: 2026-04-04:
- WebRequestBuffer::GerCookie did not return the correct cookie - WebRequestBuffer::GerCookie did not return the correct cookie
- test-webserver: added some basic data in and output. - test-webserver: added some basic data in and output.

@ -18,7 +18,7 @@ noconfig: help
endif endif
all: dep $(TARGET) test-udp test-tcpserver test-tcpclient test-ssl test-json test-webserver all: dep $(TARGET) test-udp test-tcpserver test-tcpclient test-ssl test-json test-webserver test-getrandom
-include .depend -include .depend
@ -37,6 +37,9 @@ configwindows: clean
test-webserver: $(TARGET) test-webserver.o test-webserver: $(TARGET) test-webserver.o
$(CXX) test-webserver.o -o $@ -lUDPTCPNetwork -L./ -I./ $(LDFLAGS) $(CXX) test-webserver.o -o $@ -lUDPTCPNetwork -L./ -I./ $(LDFLAGS)
test-getrandom: $(TARGET) test-getrandom.o
$(CXX) test-getrandom.o -o $@ -lUDPTCPNetwork -L./ -I./ $(LDFLAGS)
test-tcpserver: $(TARGET) test-tcpserver.o test-tcpserver: $(TARGET) test-tcpserver.o
$(CXX) test-tcpserver.o -o $@ -lUDPTCPNetwork -L./ -I./ $(LDFLAGS) $(CXX) test-tcpserver.o -o $@ -lUDPTCPNetwork -L./ -I./ $(LDFLAGS)

@ -5,7 +5,7 @@ ETCPREFIX = /etc
LINUXVERSION = 1 LINUXVERSION = 1
CXX = g++ CXX = g++
CXXFLAGS = -ggdb -fPIC -pg -Wno-write-strings -I./ -std=c++11 -DBUILD_LINUX=1 CXXFLAGS = -fPIC -pg -Wno-write-strings -I./ -std=c++11 -DBUILD_LINUX=1
LDFLAGS = -lm -pg -lssl -lcrypto LDFLAGS = -lm -pg -lssl -lcrypto
TARGET = lib$(OBJLIB_NAME).so.$(VERSION) TARGET = lib$(OBJLIB_NAME).so.$(VERSION)

@ -375,6 +375,10 @@ std::string getsha256sum(std::string *in) {
std::string getrandomtext(int numbytes) { std::string getrandomtext(int numbytes) {
std::string text = ""; std::string text = "";
unsigned int seed;
seed = arc4random();
srand(seed);
for (int i = 0; i < numbytes; i++) { for (int i = 0; i < numbytes; i++) {
char c = ((rand() % (90-48)) + 48); char c = ((rand() % (90-48)) + 48);

@ -0,0 +1,21 @@
#include <string.h>
#include <unistd.h>
#include "UDPTCPNetwork.h"
int main (int argc, char **argv) {
std::string user_salt;
user_salt = getrandomtext(16); debug ("test:%s", user_salt.c_str());
user_salt = getrandomtext(16); debug ("test:%s", user_salt.c_str());
user_salt = getrandomtext(16); debug ("test:%s", user_salt.c_str());
user_salt = getrandomtext(16); debug ("test:%s", user_salt.c_str());
user_salt = getrandomtext(16); debug ("test:%s", user_salt.c_str());
user_salt = getrandomtext(16); debug ("test:%s", user_salt.c_str());
user_salt = getrandomtext(16); debug ("test:%s", user_salt.c_str());
user_salt = getrandomtext(16); debug ("test:%s", user_salt.c_str());
user_salt = getrandomtext(16); debug ("test:%s", user_salt.c_str());
user_salt = getrandomtext(16); debug ("test:%s", user_salt.c_str());
return 0;
};

@ -156,6 +156,15 @@ void client () {
int main (int argc, char **argv) { int main (int argc, char **argv) {
pid_t pid; pid_t pid;
std::string user_salt;
user_salt = getrandomtext(16); debug ("test:%s", user_salt.c_str());
user_salt = getrandomtext(16); debug ("test:%s", user_salt.c_str());
user_salt = getrandomtext(16); debug ("test:%s", user_salt.c_str());
user_salt = getrandomtext(16); debug ("test:%s", user_salt.c_str());
user_salt = getrandomtext(16); debug ("test:%s", user_salt.c_str());
#if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__) #if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__)
#else #else
pid = fork(); pid = fork();

Loading…
Cancel
Save