]> arthur.barton.de Git - netatalk.git/blobdiff - bin/megatron/macbin.c
- merge branch-netatalk-afp-3x-dev, HEAD was tagged before
[netatalk.git] / bin / megatron / macbin.c
index 639e675ea52896e24e307979665d981edb74e28c..bf85a080b2fffc27e0e177e3e6e11709c4b6fab1 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: macbin.c,v 1.9 2002-01-04 04:45:47 sibaz Exp $
+ * $Id: macbin.c,v 1.12 2005-04-28 20:49:19 bfernhomberg Exp $
  */
 
 #ifdef HAVE_CONFIG_H
@@ -18,7 +18,6 @@
 #endif /* HAVE_UNISTD_H */
 #include <string.h>
 #include <strings.h>
-#include <atalk/logger.h>
 #include <ctype.h>
 #include <stdio.h>
 #include <time.h>
@@ -186,9 +185,9 @@ int bin_read( fork, buffer, length )
     fprintf( stderr, "bin_read: remaining length is %d\n", bin.forklen[fork] );
 #endif /* DEBUG >= 3 */
 
-    if ( bin.forklen[ fork ] < 0 ) {
-       fprintf( stderr, "This should never happen, dude!\n" );
-       return( bin.forklen[ fork ] );
+    if (bin.forklen[fork] > length) {
+       fprintf(stderr, "This should never happen, dude! length %d, fork length == %u\n", length, bin.forklen[fork]);
+       return bin.forklen[fork];
     }
 
     if ( bin.forklen[ fork ] == 0 ) {
@@ -287,13 +286,14 @@ int bin_write( fork, buffer, length )
        perror( "Couldn't write to macbinary file:" );
        return( cc );
     }
-    bin.forklen[ fork ] -= length;
 
-    if ( bin.forklen[ fork ] < 0 ) {
-       fprintf( stderr, "This should never happen, dude!\n" );
-       return( bin.forklen[ fork ] );
+    if (length > bin.forklen[fork]) {
+       fprintf(stderr, "This should never happen, dude! length %d, fork length %u\n", length, bin.forklen[fork]);
+       return bin.forklen[fork];
     }
 
+    bin.forklen[fork] -= length;
+
 /*
  * add the padding at end of data and resource forks
  */
@@ -596,13 +596,14 @@ int test_header(void)
         return -1;
 
     /* macbinary forks aren't larger than 0x7FFFFF */
+    /* we allow forks to be larger, breaking the specs */
     memcpy(&cc, head_buf + 83, sizeof(cc));
     cc = ntohl(cc);
-    if (cc > 0x7FFFFF)
+    if (cc > 0x7FFFFFFF)
         return -1;
     memcpy(&cc, head_buf + 87, sizeof(cc));
     cc = ntohl(cc);
-    if (cc > 0x7FFFFF)
+    if (cc > 0x7FFFFFFF)
         return -1;