Subject: misc/1094: Sup when files are store in machine byte order
To: None <gnats-admin@sun-lamp.cs.berkeley.edu>
From: None <christos@deshaw.com>
List: netbsd-bugs
Date: 06/02/1995 05:50:05
>Number:         1094
>Category:       misc
>Synopsis:       Sup when files are store in machine byte order
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    misc-bug-people (Misc Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Jun  2 05:50:02 1995
>Originator:     
>Organization:
	Disorganization Inc.
>Release:        Jun 2, 1995
>Environment:
NetBSD/sparc
System: NetBSD sparx.deshaw.com 1.0A NetBSD 1.0A (SPARX) #27: Thu May 25 16:20:05 EDT 1995 christos@sparx.deshaw.com:/tmp_mnt/src/NetBSD/NetBSD-current/src/sys/arch/sparc/compile/SPARX sparc


>Description:
	- Sup when files are stored in machine byte order.
	- Sup uses "int" when trying to write a "long".

	Also appended is a small c program to convert existing
	little endian when.* files into network byte order on
	a big endian machine.

>How-To-Repeat:
	Try sharing the same sup directory on an i386 and sparc machine.
>Fix:
*** supcmeat.c.dist	Fri Dec 17 02:44:28 1993
--- supcmeat.c	Fri Jun  2 08:18:24 1995
***************
*** 128,133 ****
--- 128,134 ----
  #else
  #include <varargs.h>
  #endif
+ #include <netinet/in.h>
  
  TREE *lastT;				/* last filenames in collection */
  jmp_buf sjbuf;				/* jump location for network errors */
***************
*** 334,339 ****
--- 335,341 ----
  	if (f >= 0) {
  		if (read(f,(char *)&lasttime,sizeof(long)) != sizeof(long))
  			lasttime = 0;
+ 		lasttime = ntohl(lasttime);
  		(void) close (f);
  	} else
  		lasttime = 0;
***************
*** 1272,1278 ****
  	char tname[STRINGLENGTH],fname[STRINGLENGTH];
  	char relsufix[STRINGLENGTH];
  	char collrelname[STRINGLENGTH];
! 	long tloc;
  	FILE *finishfile;		/* record of all filenames */
  	int f,finishone();
  
--- 1274,1280 ----
  	char tname[STRINGLENGTH],fname[STRINGLENGTH];
  	char relsufix[STRINGLENGTH];
  	char collrelname[STRINGLENGTH];
! 	long tloc, nscantime;
  	FILE *finishfile;		/* record of all filenames */
  	int f,finishone();
  
***************
*** 1342,1348 ****
  		(void) requestend ();
  		return;
  	}
! 	(void) write (f,(char *)&scantime,sizeof(int));
  	(void) close (f);
  	if (protver >= 6) {
  		/* At this point we have let the server go */
--- 1344,1351 ----
  		(void) requestend ();
  		return;
  	}
! 	nscantime = htonl(scantime);
! 	(void) write (f,(char *)&nscantime,sizeof(long));
  	(void) close (f);
  	if (protver >= 6) {
  		/* At this point we have let the server go */
*** supcmisc.c.dist	Fri Dec 17 02:44:28 1993
--- supcmisc.c	Fri Jun  2 08:16:11 1995
***************
*** 56,61 ****
--- 56,62 ----
  #include <varargs.h>
  #endif
  #include "supcdefs.h"
+ #include <netinet/in.h>
  
  struct liststruct {		/* uid and gid lists */
  	char *Lname;		/* name */
***************
*** 97,102 ****
--- 98,104 ----
  	if (f >= 0) {
  		if (read(f,(char *)&twhen,sizeof(long)) != sizeof(long))
  			twhen = 0;
+ 		twhen = ntohl(twhen);
  		(void) close (f);
  	} else
  		twhen = 0;
*** /dev/null	Thu May 25 21:49:44 1995
--- cvt.c	Fri Jun  2 08:28:29 1995
***************
*** 0 ****
--- 1,48 ----
+ #include <stdio.h>
+ #include <stdlib.h>
+ #include <unistd.h>
+ #include <fcntl.h>
+ 
+ int
+ main(argc, argv)
+ 	int argc;
+ 	char *argv[];
+ {
+ 	long b, a;
+ 	char *bc = (char *) &b;
+ 	char *ac = (char *) &a;
+ 	int fd;
+ 
+ 	if (argc != 2) {
+ 		(void) fprintf(stderr, "Usage: %s <filename>\n", argv[0]);
+ 		return 1;
+ 	}
+ 
+ 	if ((fd = open(argv[1], O_RDWR)) == -1) {
+ 		perror("open");
+ 		return 1;
+ 	}
+ 
+ 	if (read(fd, &b, sizeof(b)) != sizeof(b)) {
+ 		perror("read");
+ 		return 1;
+ 	}
+ 
+ 	if (lseek(fd, 0, SEEK_SET) == -1) {
+ 		perror("lseek");
+ 		return 1;
+ 	}
+ 
+ 	ac[0] = bc[3];
+ 	ac[1] = bc[2];
+ 	ac[2] = bc[1];
+ 	ac[3] = bc[0];
+ 
+ 	if (write(fd, &a, sizeof(a)) != sizeof(a)) {
+ 		perror("write");
+ 		return 1;
+ 	}
+ 
+ 	(void) close(fd);
+ 	return 0;
+ }
>Audit-Trail:
>Unformatted: