/*
- * $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
#endif /* HAVE_UNISTD_H */
#include <string.h>
#include <strings.h>
-#include <atalk/logger.h>
#include <ctype.h>
#include <stdio.h>
#include <time.h>
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 ) {
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
*/
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;