properly check for gnd files
authorChristian Grothoff <christian@grothoff.org>
Sun, 27 Jun 2010 13:13:07 +0000 (13:13 +0000)
committerChristian Grothoff <christian@grothoff.org>
Sun, 27 Jun 2010 13:13:07 +0000 (13:13 +0000)
src/fs/fs_directory.c

index 03065958e20413e83db4c70282821aaf64ec388d..6698ad0102503a90e37ece68f5d4d40b8cbd1498 100644 (file)
@@ -201,10 +201,16 @@ GNUNET_FS_directory_list_contents (size_t size,
   struct GNUNET_CONTAINER_MetaData *md;
   char *filename;
 
+  if ( (offset == 0) &&
+       ( (size < 8 + sizeof (uint32_t)) ||
+        (0 != memcmp (cdata, GNUNET_FS_DIRECTORY_MAGIC, 8)) ) )
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                 _("MAGIC mismatch.  This is not a GNUnet directory.\n"));
+      return GNUNET_SYSERR;
+    }
   pos = offset;
-  if ( (pos == 0) && 
-       (size >= 8 + sizeof (uint32_t)) &&
-       (0 == memcmp (cdata, GNUNET_FS_DIRECTORY_MAGIC, 8)) )
+  if (offset == 0) 
     {
       memcpy (&mdSize, &cdata[8], sizeof (uint32_t));
       mdSize = ntohl (mdSize);