From cbde2faab2d7ec245b4b84475abdc8bdbba01c74 Mon Sep 17 00:00:00 2001
From: Travis Cross <tc@traviscross.com>
Date: Mon, 25 Jun 2012 06:01:37 +0000
Subject: [PATCH] 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.
---
 libs/sofia-sip/libsofia-sip-ua/iptsec/auth_module.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/libs/sofia-sip/libsofia-sip-ua/iptsec/auth_module.c b/libs/sofia-sip/libsofia-sip-ua/iptsec/auth_module.c
index 0814c8c780..087810ebc7 100644
--- a/libs/sofia-sip/libsofia-sip-ua/iptsec/auth_module.c
+++ b/libs/sofia-sip/libsofia-sip-ua/iptsec/auth_module.c
@@ -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;
 }
 
 /* ====================================================================== */