[LTP] [PATCH v3 04/16] API/cgroup: Implement tst_cg_load_config

Luke Nowakowski-Krijger luke.nowakowskikrijger@canonical.com
Wed Apr 27 19:38:00 CEST 2022


Hi Richard and Li,

On Thu, Mar 17, 2022 at 12:33 AM Richard Palethorpe <rpalethorpe@suse.de>
wrote:

> Hello Luke,
>
> >
> > Thank you for pointing all these things out. I forgot about all the
> shenanigans that can happen when you don't sanity check string stuff :)
> >
> > A few solutions to creating the scanff format are:
> > 1) pre-processor trick to concatenate defines into a string, something
> like this
> > #define _tostr(str) #str
> > #define tostr(str) _tostr(str)
> > #define CONFIG_FORMAT "%" tostr(CTRL_NAME_MAX) "s\t%d\t%d\t%"
> tostr(PATH_MAX) "s\t%d\t%d\t%" tostr(NAME_MAX) "s"
> >
> > 2) just hardcode the lengths to avoid all of this nonsense above
>
> I would have done 2 in this case, but you figured out 1, so feel free to
> use that. In fact that would be a nice addition to LTP's standard macros
> (but with TST_ prefix).
>
> Just note that the maximum conversion length doesn't include
> the null character. scanf will write the null character after the
> maximum conversion length. Also I'm not sure the field length comes
> after '%' or that you use 's' with a length; possibly it should be
> '%c63' to scan a 64 byte null terminated string. However please double
> check the man page.
>
> You can use %s with a length which makes things easier and automatically
appends the null character.


> >
> > 3) just create the format at runtime
>
> IIRC this is considered unsafe and will result in warnings and errors.
>
> >
> > I'm more or less asking what you think is best to avoid sending out all
> of the patches and then discussing this / if there is a better way.
> >
>
>
Sorry for the delay on these patches, got caught up in many other things
again.

I have submitted a pull request for review, didn't want to spam 19 patches
on the ML. Its my first time doing a pull request.. are you guys able to
review and accept from there? If so here it is
https://github.com/linux-test-project/ltp/pull/933



> --
> Thank you,
> Richard.
>

Thanks,
- Luke
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20220427/d5509a23/attachment-0001.htm>


More information about the ltp mailing list