[Date Prev][Date Next] [Chronological] [Thread] [Top]

(ITS#4872) Non-portable comparison in wait4msg() (result.c) causes infinite loop



Full_Name: Carsten Agger
Version: 2.3.20
OS: OSE
URL: ftp://ftp.openldap.org/incoming/
Submission from: (NULL) (194.237.142.21)


On our architecture (OSE running on an AXE processor), time_t is an unsigned
int.

This means that this code, as found in the wait4msg function in 
libraries/libldap/result.c, will break:

>
>       if ( rc == LDAP_MSG_X_KEEP_LOOKING && tvp != NULL ) {
>                       tmp_time = time( NULL );
>                       tv0.tv_sec -= ( tmp_time - start_time );
>                       if ( tv0.tv_sec <= 0 ) {
>                               rc = 0; /* timed out */
>                               ld->ld_errno = LDAP_TIMEOUT;
>                               break;
>                       }
>                       tv.tv_sec = tv0.tv_sec;
>                         ...
>           }

Why? Because if (start_time > tmp_time), the condition 
( tv0.tv_sec <= 0 ) will never evaluate to TRUE, and the break will
never be executed - yielding an infinite loop.

Solution: rewrite in a portable way, e.g. (as suggested by Pierangelo Masarati
on 
the bugs mailing list) by testing if the
value of tv_sec would be negative after subtracting ( tmp_time -
start_time ) before assigning it.