Re: [PATCH v2] arch: s390: appldata: using strncpy() and strnlen() instead of sprintf()

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

 



On 05/28/2013 12:53 AM, walter harms wrote:
> Am 27.05.2013 11:55, schrieb Chen Gang:
>> diff --git a/arch/s390/appldata/appldata_base.c b/arch/s390/appldata/appldata_base.c
>> index bae0f40..87a2209 100644
>> --- a/arch/s390/appldata/appldata_base.c
>> +++ b/arch/s390/appldata/appldata_base.c
>> @@ -212,7 +212,9 @@ appldata_timer_handler(ctl_table *ctl, int write,
>>  		return 0;
>>  	}
>>  	if (!write) {
>> -		len = sprintf(buf, appldata_timer_active ? "1\n" : "0\n");
>> +		strncpy(buf, appldata_timer_active ? "1\n" : "0\n",
>> +			ARRAY_SIZE(buf));
> 
> an other way would be
> 
> buf[]="0\n";
> if (appldata_timer_active) buf[0]='1';
> 
> 
>> +		len = strnlen(buf, ARRAY_SIZE(buf));
> 
> can len ever change ?
> 

I do not know whether it will be changed, but we need treat it that it
may be changed in the future.

I guess it uses "?\n" as a protocol between kernel mode and user mode.
This patch fix the 'protocol' transferring issue independent of the
'protocol' itself.

In the future, the 'protocol' updates to new version (e.g. append
additional characters, which will still compitable with the original
version), what this patch have done will be still effective.


Thanks.
-- 
Chen Gang

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




[Index of Archives]     [Kernel Development]     [Kernel Announce]     [Kernel Newbies]     [Linux Networking Development]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Device Mapper]

  Powered by Linux