https://bugs.kde.org/show_bug.cgi?id=359485

            Bug ID: 359485
           Summary: KRandom::random reads 16384 bytes from /dev/urandom
                    per invocation instead of 4
           Product: frameworks-kcoreaddons
           Version: unspecified
          Platform: openSUSE RPMs
                OS: Linux
            Status: UNCONFIRMED
          Severity: normal
          Priority: NOR
         Component: general
          Assignee: mp...@kde.org
          Reporter: crrodrig...@opensuse.org
                CC: kdelibs-b...@kde.org

reads 16384 bytes from /dev/urandom per invocation, this is because QFile
stream is buffered by default.

Reproducible: Always

Steps to Reproduce:
Call  KRandom::random from any application

Actual Results:  
reads 16384 bytes from /dev/urandom

Expected Results:  
A read of sizeof(seed)

git diff
diff --git a/src/lib/randomness/krandom.cpp b/src/lib/randomness/krandom.cpp
index da78388..93b917d 100644
--- a/src/lib/randomness/krandom.cpp
+++ b/src/lib/randomness/krandom.cpp
@@ -43,7 +43,7 @@ int KRandom::random()
         unsigned int seed;
         init = true;
         QFile urandom(QStringLiteral("/dev/urandom"));
-        bool opened = urandom.open(QIODevice::ReadOnly);
+        bool opened = urandom.open(QIODevice::ReadOnly |
QIODevice::Unbuffered);
         if (!opened || urandom.read((char *)&seed, sizeof(seed)) !=
sizeof(seed)) {
             // No /dev/urandom... try something else.
             srand(getpid());

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to