]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
Fix confusion between size_t and ssize_t
authorTravis Cross <tc@traviscross.com>
Mon, 25 Jun 2012 06:01:37 +0000 (06:01 +0000)
committerTravis Cross <tc@traviscross.com>
Mon, 25 Jun 2012 06:38:30 +0000 (06:38 +0000)
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

index 0814c8c780670dc4ecd3029c9aa30b60902e7704..087810ebc7848609f0dc58bf5785dcd98d34db4b 100644 (file)
@@ -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;
 }
 
 /* ====================================================================== */