[OpenAFS-devel] 1.3.70 - incorrect arguments passed to sprintf in util/snprintf.c

Rainer Toebbicke rtb@pclella.cern.ch
26 Aug 2004 11:55:10 +0200


--=-iozxGNN4WTgqGdOq8a0t
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

In 1.3.70, the arguments passed in sprintf to a '%u' pattern should be
whatever '%u' expects, which is not necessarily of type afs_uintmax_t:
On a normal i386 Linux an IP address 1.2.3.4 prints as 1.0.2.0 because
of the 'long long' argument. 

The attached patch typecasts everything to "unsigned int" at the last
possible moment: this is for the '%I' pattern and the numbers will
always be <= 255 anyway, so it continues to work even on machines where
'unsigned int' is less than 4 bytes long.



--=-iozxGNN4WTgqGdOq8a0t
Content-Disposition: attachment; filename=patch_snprintf
Content-Transfer-Encoding: quoted-printable
Content-Type: text/x-patch; name=patch_snprintf; charset=ISO-8859-1

*** openafs/src/util/snprintf.c.0rig	Mon Aug  9 22:57:10 2004
--- openafs/src/util/snprintf.c	Thu Aug 26 11:36:48 2004
***************
*** 436,444 ****
  		} else {
  		    x =3D "%u.%u.%u.%u";
  		}
! 		sprintf(xbuf, x, (UVAL & 0xff000000) >> 24,
! 			(UVAL & 0x00ff0000) >> 16, (UVAL & 0x0000ff00) >> 8,
! 			(UVAL & 0x000000ff));
  		x =3D xbuf;
  		len =3D strlen(xbuf);
  	    }
--- 436,444 ----
  		} else {
  		    x =3D "%u.%u.%u.%u";
  		}
! 		sprintf(xbuf, x, (unsigned int)((UVAL & 0xff000000) >> 24),	/* typecast=
 to whatever '%u' is! */
! 			(unsigned int)((UVAL & 0x00ff0000) >> 16), (unsigned int)((UVAL & 0x00=
00ff00) >> 8),
! 			(unsigned int)(UVAL & 0x000000ff));
  		x =3D xbuf;
  		len =3D strlen(xbuf);
  	    }

--=-iozxGNN4WTgqGdOq8a0t--