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]

 



On (06/25/15 00:55), Seymour, Shane M wrote:
> Changed the documentation to allow sprintf() for small
> single values and explicitly say snprintf() must never be used in
> a show function to format data to be returned to user space.
> 
> Change based on a discussion about the patch
> st: convert DRIVER_ATTR macros to DRIVER_ATTR_RO
> 
> Suggested-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
> Signed-off-by: Shane Seymour <shane.seymour@xxxxxx>
> ---
> --- a/Documentation/filesystems/sysfs.txt	2015-06-22 14:18:40.278620871 -0500
> +++ b/Documentation/filesystems/sysfs.txt	2015-06-24 13:42:21.344446532 -0500
> @@ -212,7 +212,9 @@ Other notes:
>  - show() methods should return the number of bytes printed into the
>    buffer. This is the return value of scnprintf().
>  
> -- 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);

Probably the wording better be "if you guarantee that overflow will
never happen, then you can use ...".

	-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