fixes
authorChristian Grothoff <christian@grothoff.org>
Thu, 17 Jun 2010 21:56:21 +0000 (21:56 +0000)
committerChristian Grothoff <christian@grothoff.org>
Thu, 17 Jun 2010 21:56:21 +0000 (21:56 +0000)
src/fs/fs_directory.c
src/fs/fs_download.c
src/fs/fs_search.c
src/fs/gnunet-service-fs.c
src/peerinfo/gnunet-service-peerinfo.c
src/statistics/statistics_api.c
src/topology/gnunet-daemon-topology.c
src/transport/plugin_transport_tcp.c
src/transport/plugin_transport_udp.c
src/util/os_priority.c

index 9c13073ab1707cdc86d777b7a98c3fd145cc7d0d..fca2fc78639edbc5a311f90fe6bfdbe6a1a29291 100644 (file)
@@ -401,16 +401,24 @@ GNUNET_FS_directory_builder_add (struct GNUNET_FS_DirectoryBuilder *bld,
 
   GNUNET_assert (! GNUNET_FS_uri_test_ksk (uri));
   if (NULL != data)
-    if (GNUNET_FS_uri_test_chk (uri))
-      fsize = GNUNET_FS_uri_chk_get_file_size (uri);
-    else
-      {
-       curi = GNUNET_FS_uri_loc_get_uri (uri);
-       fsize = GNUNET_FS_uri_chk_get_file_size (curi);
-       GNUNET_FS_uri_destroy (curi);
-      }
+    {
+      GNUNET_assert (! GNUNET_FS_uri_test_sks (uri));
+      if (GNUNET_FS_uri_test_chk (uri))
+       {
+         fsize = GNUNET_FS_uri_chk_get_file_size (uri);
+       }
+      else
+       {
+         curi = GNUNET_FS_uri_loc_get_uri (uri);
+         GNUNET_assert (NULL != curi);
+         fsize = GNUNET_FS_uri_chk_get_file_size (curi);
+         GNUNET_FS_uri_destroy (curi);
+       }
+    }
   else
-    fsize = 0; /* not given */
+    {
+      fsize = 0; /* not given */
+    }
   if (fsize > MAX_INLINE_SIZE)
     fsize = 0; /* too large */
   uris = GNUNET_FS_uri_to_string (uri);
index b27aef8cd00ef54ca52a17d958bbe51197c6a5f8..057f57b538d705a59ffb9436070ed418dfdee66e 100644 (file)
@@ -330,10 +330,14 @@ schedule_block_download (struct GNUNET_FS_DownloadContext *dc,
          GNUNET_HashCode query;
 
          GNUNET_CRYPTO_hash_to_aes_key (&key, &sk, &iv);
-         GNUNET_CRYPTO_aes_encrypt (block, len,
-                                    &sk,
-                                    &iv,
-                                    enc);
+         if (-1 == GNUNET_CRYPTO_aes_encrypt (block, len,
+                                              &sk,
+                                              &iv,
+                                              enc))
+           {
+             GNUNET_break (0);
+             goto do_download;
+           }
          GNUNET_CRYPTO_hash (enc, len, &query);
          if (0 == memcmp (&query,
                           &chk->query,
@@ -364,6 +368,7 @@ schedule_block_download (struct GNUNET_FS_DownloadContext *dc,
          return;
        }
     }
+ do_download:
   if (fh != NULL)
     GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (fh));
   if (depth < dc->treedepth)
@@ -915,11 +920,16 @@ process_result_with_request (void *cls,
       ppos = ppos->next;
     }
   GNUNET_CRYPTO_hash_to_aes_key (&sm->chk.key, &skey, &iv);
-  GNUNET_CRYPTO_aes_decrypt (prc->data,
-                            prc->size,
-                            &skey,
-                            &iv,
-                            pt);
+  if (-1 == GNUNET_CRYPTO_aes_decrypt (prc->data,
+                                      prc->size,
+                                      &skey,
+                                      &iv,
+                                      pt))
+    {
+      GNUNET_break (0);
+      dc->emsg = GNUNET_strdup ("internal error decrypting content");
+      goto signal_error;
+    }
   off = compute_disk_offset (GNUNET_ntohll (dc->uri->data.chk.file_length),
                             sm->offset,
                             sm->depth,
index 21fd7e8f1b797de51d41cbac875e5422072f9d6f..da61cea57e65c16e4d9d27cecb011bac706cdba4 100644 (file)
@@ -574,11 +574,15 @@ process_kblock (struct GNUNET_FS_SearchContext *sc,
     }
   /* decrypt */
   GNUNET_CRYPTO_hash_to_aes_key (&sc->requests[i].key, &skey, &iv);
-  GNUNET_CRYPTO_aes_decrypt (&kb[1],
-                            size - sizeof (struct KBlock),
-                            &skey,
-                            &iv,
-                            pt);
+  if (-1 == GNUNET_CRYPTO_aes_decrypt (&kb[1],
+                                      size - sizeof (struct KBlock),
+                                      &skey,
+                                      &iv,
+                                      pt))
+    {
+      GNUNET_break (0);
+      return;
+    }
   /* parse */
   eos = memchr (pt, 0, sizeof (pt));
   if (NULL == eos)
@@ -654,11 +658,15 @@ process_nblock (struct GNUNET_FS_SearchContext *sc,
     }
   /* decrypt */
   GNUNET_CRYPTO_hash_to_aes_key (&sc->requests[i].key, &skey, &iv);
-  GNUNET_CRYPTO_aes_decrypt (&nb[1],
-                            size - sizeof (struct NBlock),
-                            &skey,
-                            &iv,
-                            pt);
+  if (-1 == GNUNET_CRYPTO_aes_decrypt (&nb[1],
+                                      size - sizeof (struct NBlock),
+                                      &skey,
+                                      &iv,
+                                      pt))
+    {
+      GNUNET_break (0);
+      return;
+    }
   /* parse */
   eos = memchr (pt, 0, sizeof (pt));
   if (NULL == eos)
@@ -736,11 +744,15 @@ process_sblock (struct GNUNET_FS_SearchContext *sc,
                      strlen (identifier), 
                      &key);
   GNUNET_CRYPTO_hash_to_aes_key (&key, &skey, &iv);
-  GNUNET_CRYPTO_aes_decrypt (&sb[1],
-                            len,
-                            &skey,
-                            &iv,
-                            pt);
+  if (-1 == GNUNET_CRYPTO_aes_decrypt (&sb[1],
+                                      len,
+                                      &skey,
+                                      &iv,
+                                      pt))
+    {
+      GNUNET_break (0);
+      return;
+    }
   /* parse */
   off = GNUNET_STRINGS_buffer_tokenize (pt,
                                        len, 
index 874c2ecc5b91406fdfff43edb33d4ab2648b82b9..90d0cabaf288dee002d01ddda57bd4d96dc87349 100644 (file)
@@ -760,7 +760,7 @@ is_closer (const GNUNET_HashCode *key,
  *            targets for (or NULL for none)
  * @param key ID of the peer 
  * @param value 'struct ConnectedPeer' of the peer
- * @return GNUNET_YES (always continue iteration)2
+ * @return GNUNET_YES (always continue iteration)
  */
 static int
 consider_migration (void *cls,
@@ -842,11 +842,12 @@ consider_migration (void *cls,
     }
   if (msize == 0)
     return GNUNET_YES; /* no content available */
+#if DEBUG_FS
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-             "Trying to migrate `%s' (%u bytes) to `%s'\n",
-             GNUNET_h2s (&mb->query),
+             "Trying to migrate at least %u bytes to peer `%s'\n",
              msize,
-             GNUNET_i2s (&cppid));
+             GNUNET_h2s (key));
+#endif
   cp->cth 
     = GNUNET_CORE_notify_transmit_ready (core,
                                         0, GNUNET_TIME_UNIT_FOREVER_REL,
index 7c1f53d4bd4ea05556d6203a137e43f3fdc67899..63c605705774ceffdb78aa804b331986932d6f03 100644 (file)
@@ -606,10 +606,11 @@ discard_hosts_helper (void *cls, const char *fn)
   int size;
 
   size = GNUNET_DISK_fn_read (fn, buffer, sizeof (buffer));
-  if ((size < sizeof (struct GNUNET_MessageHeader)) && (0 != UNLINK (fn)))
+  if (size < sizeof (struct GNUNET_MessageHeader))
     {
-      GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING |
-                                GNUNET_ERROR_TYPE_BULK, "unlink", fn);
+      if (0 != UNLINK (fn))
+       GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING |
+                                 GNUNET_ERROR_TYPE_BULK, "unlink", fn);
       return GNUNET_OK;
     }
   hello = (const struct GNUNET_HELLO_Message *) buffer;
index 4ba459c46da71ae30ad9e05c72a07bf48d05fd73..3289745b15300cc09348c33b56e4604433404aea 100644 (file)
@@ -196,7 +196,7 @@ static int
 try_connect (struct GNUNET_STATISTICS_Handle *ret)
 {
   if (ret->client != NULL)
-    return GNUNET_OK;
+    return GNUNET_YES;
   ret->client = GNUNET_CLIENT_connect (ret->sched, "statistics", ret->cfg);
   if (ret->client != NULL)
     return GNUNET_YES;
@@ -235,9 +235,12 @@ finish (struct GNUNET_STATISTICS_Handle *h, int code)
   struct GNUNET_STATISTICS_GetHandle *pos = h->current;
   h->current = NULL;
   schedule_action (h);
-  if (pos->cont != NULL)
-    pos->cont (pos->cls, code);
-  free_action_item (pos);
+  if (pos != NULL)
+    {
+      if (pos->cont != NULL)
+       pos->cont (pos->cls, code);
+      free_action_item (pos);
+    }
 }
 
 
index a73c64da0dddb4e6ccbb0ca9727d5007d977f405..e1c90462278d057fd069525ad1312d16d81491a2 100644 (file)
@@ -1068,17 +1068,16 @@ read_friends_file (const struct GNUNET_CONFIGURATION_Handle *cfg)
       return;
     }
   if (GNUNET_OK != GNUNET_DISK_file_test (fn))
-    GNUNET_DISK_fn_write (fn, NULL, 0, GNUNET_DISK_PERM_USER_READ
-        | GNUNET_DISK_PERM_USER_WRITE);
+    GNUNET_DISK_fn_write (fn, NULL, 0, 
+                         GNUNET_DISK_PERM_USER_READ
+                         | GNUNET_DISK_PERM_USER_WRITE);
   if (0 != STAT (fn, &frstat))
     {
       if ((friends_only) || (minimum_friend_count > 0))
-        {
-          GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                     _("Could not read friends list `%s'\n"), fn);
-         GNUNET_free (fn);
-          return;
-        }
+       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                   _("Could not read friends list `%s'\n"), fn);
+      GNUNET_free (fn);
+      return;
     }
   if (frstat.st_size == 0)
     {
index fca1b1f158fcc254bf61b47c789b3317c6fe1656..7e3bc080c00f3a7b2d52be086fd28be6a63264b0 100644 (file)
@@ -443,7 +443,11 @@ tcp_address_to_string (void *cls,
       GNUNET_break (0);
       return NULL;
     }
-  inet_ntop (af, sb, buf, INET6_ADDRSTRLEN);
+  if (NULL == inet_ntop (af, sb, buf, INET6_ADDRSTRLEN))
+    {
+      GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "inet_ntop");
+      return NULL;
+    }
   GNUNET_snprintf (rbuf,
                   sizeof (rbuf),
                   (af == AF_INET6) ? "[%s]:%u" : "%s:%u",
@@ -859,9 +863,13 @@ run_gnunet_nat_client (struct Plugin *plugin, const char *addr, size_t addrlen)
     case AF_INET:
       if (addrlen != sizeof (struct sockaddr_in))
         return;
-      inet_ntop (AF_INET,
-                 &((struct sockaddr_in *) sa)->sin_addr,
-                 inet4, INET_ADDRSTRLEN);
+      if (NULL == inet_ntop (AF_INET,
+                            &((struct sockaddr_in *) sa)->sin_addr,
+                            inet4, INET_ADDRSTRLEN))
+       {
+         GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "inet_ntop");
+         return;
+       }
       address_as_string = GNUNET_strdup (inet4);
       break;
     case AF_INET6:
index 82ccaa8cb73e956bd232cc61c90b26ea43d7b34f..5afb804dc07ffa2ee45d48c85cfc8e57745afca8 100644 (file)
@@ -581,9 +581,13 @@ run_gnunet_nat_client (struct Plugin *plugin, const char *addr, size_t addrlen)
     case AF_INET:
       if (addrlen != sizeof (struct sockaddr_in))
         return;
-      inet_ntop (AF_INET,
-                 &((struct sockaddr_in *) sa)->sin_addr,
-                 inet4, INET_ADDRSTRLEN);
+      if (NULL == inet_ntop (AF_INET,
+                            &((struct sockaddr_in *) sa)->sin_addr,
+                            inet4, INET_ADDRSTRLEN))
+       {
+         GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "inet_ntop");
+         return;
+       }
       address_as_string = GNUNET_strdup (inet4);
       break;
     case AF_INET6:
@@ -1097,7 +1101,13 @@ udp_demultiplexer(struct Plugin *plugin, struct GNUNET_PeerIdentity *sender, con
       if (sender_addr->ss_family == AF_INET)
         {
           memset(&addr_buf, 0, sizeof(addr_buf));
-          inet_ntop(AF_INET, &((struct sockaddr_in *) sender_addr)->sin_addr, addr_buf, INET_ADDRSTRLEN);
+          if (NULL == inet_ntop (AF_INET, 
+                                &((struct sockaddr_in *) sender_addr)->sin_addr, addr_buf, 
+                                INET_ADDRSTRLEN))
+           {
+             GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "inet_ntop");
+             return;
+           }
           outgoing_probe = find_probe(plugin, &addr_buf[0]);
           if (outgoing_probe != NULL)
             {
index 7e6750e8be02cdba0292070da62aee4809afed1a..a9f79fe96b4a8938745c03776228689391c3da5e 100644 (file)
@@ -430,6 +430,11 @@ GNUNET_OS_process_status (pid_t proc, enum GNUNET_OS_ProcessStatusType *type,
 
   GNUNET_assert (0 != proc);
   ret = waitpid (proc, &status, WNOHANG);
+  if (ret < 0)
+    {
+      GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
+      return GNUNET_SYSERR;
+    }
   if (0 == ret)
     {
       *type = GNUNET_OS_PROCESS_RUNNING;