Fix confusion between size_t and ssize_t
readfile returns a value of type ssize_t (signed) and returns -1 if an error occurs. In auth_readdb_internal, however, we were assigning the return value of readfile to a variable of type size_t (unsigned), but then testing this unsigned value to see if it was < 0, a contradiction. We would thus simultaneously fail to report the error in readfile and would end up with a corrupted length value.
This commit is contained in:
parent
e6629ab5f6
commit
cbde2faab2
|
@ -961,6 +961,7 @@ int auth_readdb_internal(auth_mod_t *am, int always)
|
|||
FILE *f;
|
||||
char *data, *s;
|
||||
size_t len, i, n, N;
|
||||
ssize_t slen;
|
||||
auth_passwd_t *apw;
|
||||
|
||||
if (!am->am_stat)
|
||||
|
@ -1002,7 +1003,7 @@ int auth_readdb_internal(auth_mod_t *am, int always)
|
|||
if (am->am_stat)
|
||||
stat(am->am_db, am->am_stat); /* too bad if this fails */
|
||||
|
||||
len = readfile(am->am_home, f, &buffer, 1);
|
||||
slen = readfile(am->am_home, f, &buffer, 1);
|
||||
|
||||
#if HAVE_FLOCK
|
||||
/* Release shared lock on the database file */
|
||||
|
@ -1016,8 +1017,9 @@ int auth_readdb_internal(auth_mod_t *am, int always)
|
|||
|
||||
fclose(f);
|
||||
|
||||
if (len < 0)
|
||||
if (slen < 0)
|
||||
return -1;
|
||||
len = (size_t)slen;
|
||||
|
||||
/* Count number of entries in new buffer */
|
||||
for (i = am->am_anonymous, s = data = buffer;
|
||||
|
@ -1208,7 +1210,7 @@ ssize_t readfile(su_home_t *home,
|
|||
buffer[len] = '\0';
|
||||
*contents = buffer;
|
||||
|
||||
return len;
|
||||
return (ssize_t)len;
|
||||
}
|
||||
|
||||
/* ====================================================================== */
|
||||
|
|
Loading…
Reference in New Issue