Re: [PATCH] sysfs.txt: update show method notes about sprintf/snprintf/scnprintf usage

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Cc Jonathan and linux-doc

On (06/24/15 23:03), Greg KH <gregkh@xxxxxxxxxxxxxxxxxxx> (gregkh@xxxxxxxxxxxxxxxxxxx) wrote:
[..]
> > > -- show() should always use scnprintf().
> > > +- show() must not use snprintf() when formatting a value to be
> > > +  returned to user space. For small single values you can use
> > > +  sprintf() otherwise you must use scnprintf().
> > 
> > Well, a single value can easily overflow
> > 
> > 	sprintf(buf, "%s", dev->large_value);
> 
> That's an obviously foolish sysfs attribute, if you do that, you deserve
> the kernel crash :)

:)

And the 'always use scnprintf()' rule keeps all of us on the safe
side (almost for free).

> > Probably the wording better be "if you guarantee that overflow will
> > never happen, then you can use ...".
> 
> For a document that no one has obviously read in the past 5 years, I
> really doubt we need to work too hard on the exact specific wording of
> it.

Oh, it's especially pleasant and satisfactory to ignore
a well-written and scrupulous documentation  :)  just kidding.

	-ss
--
To unsubscribe from this list: send the line "unsubscribe linux-api" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux