Patch: 'unsigned < 0' doesn't work (ITS#1705) ================ Written by Hallvard B. Furuseth and placed into the public domain. This software is not subject to any license of the University of Oslo. ================ This code tested whether an unsigned variable was negative. In dntest.c, the bug happened if strlen(buf)==0. In entropy.c, the code didn't catch if the return value from read() was -1. -1 is converted to U_MAX when it meets `unsigned '. Hallvard B. Furuseth , March 2002. diff -u2 -r libraries/libldap/dntest.c libraries/libldap/dntest.c --- libraries/libldap/dntest.c Fri Feb 8 21:53:04 2002 +++ libraries/libldap/dntest.c Sun Mar 31 16:43:06 2002 @@ -73,6 +73,6 @@ fgets( buf, sizeof( buf ), stdin ); - len = strlen( buf ) - 1; - if ( len >= 0 && buf[ len ] == '\n' ) { + len = strlen( buf ); + if ( len > 0 && buf[ --len ] == '\n' ) { buf[ len ] = '\0'; } diff -u2 -r libraries/libldap/getdn.c libraries/libldap/getdn.c --- libraries/libldap/getdn.c Sun Feb 24 00:24:43 2002 +++ libraries/libldap/getdn.c Sun Mar 31 16:14:57 2002 @@ -1712,5 +1712,5 @@ len = endPos - startPos - escapes; - assert( len >= 0 ); + assert( endPos >= startPos + escapes ); val->bv_len = len; if ( escapes == 0 ) { diff -u2 -r libraries/liblutil/entropy.c libraries/liblutil/entropy.c --- libraries/liblutil/entropy.c Fri Jan 4 21:17:43 2002 +++ libraries/liblutil/entropy.c Sun Mar 31 16:05:00 2002 @@ -49,5 +49,5 @@ /* should return nbytes */ - if( rc < nbytes ) return -1; + if( rc != nbytes ) return -1; return 0; diff -u2 -r servers/slapd/limits.c servers/slapd/limits.c --- servers/slapd/limits.c Tue Jan 22 08:30:32 2002 +++ servers/slapd/limits.c Sun Mar 31 16:00:31 2002 @@ -56,9 +56,9 @@ } - d = ndn->bv_len - lm[0]->lm_dn_pat.bv_len; /* ndn shorter than dn_pat */ - if ( d < 0 ) { + if ( ndn->bv_len < lm[0]->lm_dn_pat.bv_len ) { break; } + d = ndn->bv_len - lm[0]->lm_dn_pat.bv_len; /* allow exact match for SUBTREE only */