fixing 1584
[oweals/gnunet.git] / src / fs / fs_search.c
index af405bfc0a2a5744f337c6191bc6179baabcfa41..a6418f786ba7237053b18c736d639b8625b0ecba 100644 (file)
@@ -4,7 +4,7 @@
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
-     by the Free Software Foundation; either version 2, or (at your
+     by the Free Software Foundation; either version 3, or (at your
      option) any later version.
 
      GNUnet is distributed in the hope that it will be useful, but
@@ -107,6 +107,7 @@ notify_client_chk_result (struct GNUNET_FS_SearchContext *sc,
   pi.value.search.specifics.result.meta = sr->meta;
   pi.value.search.specifics.result.uri = sr->uri;
   pi.value.search.specifics.result.result = sr;
+  pi.value.search.specifics.result.applicability_rank = sr->optional_support;
   sr->client_info = GNUNET_FS_search_make_status_ (&pi, sc);
 }
 
@@ -573,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)
@@ -653,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)
@@ -735,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, 
@@ -1148,6 +1161,7 @@ GNUNET_FS_search_start_searching_ (struct GNUNET_FS_SearchContext *sc)
          keyword = &sc->uri->data.ksk.keywords[i][1];
          GNUNET_CRYPTO_hash (keyword, strlen (keyword), &hc);
          pk = GNUNET_CRYPTO_rsa_key_create_from_hash (&hc);
+         GNUNET_assert (pk != NULL);
          GNUNET_CRYPTO_rsa_key_get_public (pk, &pub);
          GNUNET_CRYPTO_rsa_key_free (pk);
          GNUNET_CRYPTO_hash (&pub,
@@ -1334,6 +1348,8 @@ GNUNET_FS_search_start (struct GNUNET_FS_Handle *h,
 {
   struct GNUNET_FS_SearchContext *ret;
   ret = search_start (h, uri, anonymity, options, cctx, NULL);
+  if (ret == NULL)
+    return NULL;
   ret->top = GNUNET_FS_make_top (h, &GNUNET_FS_search_signal_suspend_, ret);
   return ret;
 }
@@ -1408,6 +1424,9 @@ search_result_free (void *cls,
   if (NULL != sr->download)
     {
       sr->download->search = NULL;
+      sr->download->top = GNUNET_FS_make_top (sr->download->h,
+                                             &GNUNET_FS_download_signal_suspend_,
+                                             sr->download);
       if (NULL != sr->download->serialization)
        {
          GNUNET_FS_remove_sync_file_ (sc->h,