[unix-pc.bugs] dstconvert: Patch to make sure it will work with *any* binary

lenny@icus.islp.ny.us (Lenny Tropiano) (04/06/89)

Here's a small patch to dstconvert that will make sure that it will work
with *any* non-shared libaries compiled binary. This means if it was loaded
with the -N, -z, etc.. switched, now the magic flag bits are masked, and
then checked.  Mike Levin (magnus!levin) sent me his version, I modified
it slightly to work like /bin/file does with the /etc/magic checking.

-- Feed to patch -- -- Feed to patch -- -- Feed to patch -- -- Feed to patch --
*** o.dstconvert.c	Thu Apr  6 00:56:52 1989
--- dstconvert.c	Thu Apr  6 01:00:15 1989
***************
*** 35,41
  
  #undef TRUE
  #define TRUE		1
! #define	MAGICNUM	0522	/* magic number of a mc68k binary for UNIX pc */
  #define	SHAREDLIB	04	/* magic number of a shared library binary */
  
  main(argc, argv)

--- 35,42 -----
  
  #undef TRUE
  #define TRUE		1
! #define	MAGICMASK	0177770 /* taken from /etc/magic */
! #define	MAGICNUM	0520	/* magic number of a mc68k binary for UNIX pc */
  #define	SHAREDLIB	04	/* magic number of a shared library binary */
  
  main(argc, argv)
***************
*** 109,115
  	/* read the first two bytes, which contains the magic number */
  
  	fread(&magic, sizeof(magic),1,fp);
! 	if (magic != MAGICNUM) {
  		fprintf(stderr,"%s: not a binary file\n", progname);
  		exit(1);
  	}

--- 110,116 -----
  	/* read the first two bytes, which contains the magic number */
  
  	fread(&magic, sizeof(magic),1,fp);
! 	if ((magic & MAGICMASK) != MAGICNUM) {
  		fprintf(stderr,"%s: not a binary file\n", progname);
  		exit(1);
  	}
-- 
Lenny Tropiano             ICUS Software Systems         [w] +1 (516) 582-5525
lenny@icus.islp.ny.us      Telex; 154232428 ICUS         [h] +1 (516) 968-8576
{talcott,decuac,boulder,hombre,pacbell,sbcs}!icus!lenny  attmail!icus!lenny
        ICUS Software Systems -- PO Box 1; Islip Terrace, NY  11752