[illumos-Developer] Webrev for bug 561: Strange characters when executing "format"

Gary Mills mills at cc.umanitoba.ca
Fri Jul 8 13:41:09 PDT 2011


On Fri, Jul 08, 2011 at 08:08:13AM -0700, Garrett D'Amore wrote:
> 
>    Oh right, strncpy vs strlcpy.   Ick.  I hate the non terminating
>    behavior of strncpy.

The more I stare at the code just below my change, the more I see
that it can't possibly work.  This is it, introduced in changeset
12610,5daa5746f6ae to fix Opensolaris bug #6957124:

	(void) strncpy(p, inquiry.inq_vid, sizeof (inquiry.inq_vid));
	p += sizeof (inquiry.inq_vid) - 1;
	*p++ = '-';
	p = strncpy(p, inquiry.inq_pid, sizeof (inquiry.inq_pid));
	p += sizeof (inquiry.inq_pid) - 1;
	*p++ = '-';
	p = strncpy(p, inquiry.inq_revision, sizeof (inquiry.inq_revision));

The three values in the inquiry data are space-padded in fixed-length
fields, not null terminated.  The code to create a disk name from this
data already exists as the get_generic_disk_name() function in the
`format' source.  I'll be posting a new webrev soon with this function
substituted.  Unfortunately, I can't test it, but it pretty well has
to work.

-- 
-Gary Mills-        -Unix Group-        -Computer and Network Services-



More information about the Developer mailing list