NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

lib/46751: arc4random_addrandom(3) always reinitializes



>Number:         46751
>Category:       lib
>Synopsis:       arc4random_addrandom(3) always reinitializes
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Jul 28 21:35:00 +0000 2012
>Originator:     matt martin
>Release:        
>Organization:
>Environment:
>Description:
A negation was dropped (looks like in 1.11 -> 1.12)

static inline void
_arc4random_addrandom_unlocked(u_char *dat, int datlen)
{
        if (__predict_false(rs.initialized)) { // <-- here
                arc4_init(&rs);
        }
        arc4_addrandom(&rs, dat, datlen);
}

Since arc4_init() calls arc4_stir() and calling anything else will wind up 
calling arc4_init() this doesn't seem to break anything. Looks like it'll just 
throw away whatever changes arc4random_addrandom() made if nothing had 
(ever...) been called before it.
>How-To-Repeat:
Looking at 
http://cvsweb.netbsd.org/bsdweb.cgi/~checkout~/src/lib/libc/gen/arc4random.c?rev=1.13&content-type=text/plain
>Fix:
Replace the negation.

static inline void
_arc4random_addrandom_unlocked(u_char *dat, int datlen)
{
        if (__predict_false(!rs.initialized)) {
                arc4_init(&rs);
        }
        arc4_addrandom(&rs, dat, datlen);
}



Home | Main Index | Thread Index | Old Index