[dpdk-dev] [PATCH v3 1/1] fbarray: get fbarrays from containerized secondary
Burakov, Anatoly
anatoly.burakov at intel.com
Mon Jul 22 11:25:39 CEST 2019
On 12-Jul-19 3:22 AM, Yasufumi Ogawa wrote:
> On 2019/07/11 22:14, Burakov, Anatoly wrote:
>> On 11-Jul-19 12:57 PM, Yasufumi Ogawa wrote:
>>> On 2019/07/11 19:53, Burakov, Anatoly wrote:
>>>> On 11-Jul-19 11:31 AM, yasufum.o at gmail.com wrote:
>>>>> From: Yasufumi Ogawa <ogawa.yasufumi at lab.ntt.co.jp>
>>>>>
>>>> <...>
>>>>
>>>>> + if (getpid() == 1) {
>>>>> + FILE *hn_fp;
>>>>> + hn_fp = fopen("/etc/hostname", "r");
>>>>> + if (hn_fp == NULL) {
>>>>> + RTE_LOG(ERR, EAL,
>>>>> + "Cannot open '/etc/hostname' for secondary\n");
>>>>> + return -1;
>>>>> + }
>>>>> +
>>>>> + /* with docker, /etc/hostname just has one entry of
>>>>> hostname */
>>>>> + if (fscanf(hn_fp, "%s", proc_id) == EOF) {
>>>>
>>>> Apologies for not pointing this out earlier, but do i understand
>>>> correctly that there's no bounds checking here, and fscanf() will
>>>> write however many bytes it wants?
>>> I understand "%s" is not appropriate. hostname is 12 bytes char and I
>>> thought proc_id[16] is enough, but it is unsafe. In addition,
>>> hostname can be defined by user with docker's option, so it should be
>>> enough for user defined name.
>>>
>>> How do you think expecting max 32 chars of hostname and set boundary
>>> "%32s" as following?
>>>
>>> proc_id[33]; /* define proc id from hostname less than 33
>>> bytes. */
>>> ...
>>> if (fscanf(hn_fp, "%32s", proc_id) == EOF) {
>>>
>>
>> As long as it takes NULL-termination into account as well, it should
>> be OK. I can't recall off the top of my head if %32s includes NULL
>> terminator (probably not?).
> Do you agree if initialize with NULL chars to ensure proc_id is
> NULL-terminated? As tested on my environment, "%Ns" sets next of Nth
> char as NULL, but it seems more reliable.
> proc_id[33] = { 0 };
>
> Yasufumi
>
Yes, that should be OK.
--
Thanks,
Anatoly
More information about the dev
mailing list