coreutils
[Top][All Lists]
Advanced

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

Re: [PATCH] maint: prohibit use of strncpy


From: Jim Meyering
Subject: Re: [PATCH] maint: prohibit use of strncpy
Date: Fri, 25 May 2012 16:41:36 +0200

Eric Blake wrote:
> On 05/24/2012 08:23 AM, Jim Meyering wrote:
>> The use of strncpy is so seldom justifiable, that it is best
>> just to avoid it altogether.  Thus, we should enforce that:
>>
>>>From 22695d676de21d0af6d50ca8218eeb49b45608ab Mon Sep 17 00:00:00 2001
>> From: Jim Meyering <address@hidden>
>> Date: Thu, 24 May 2012 16:21:34 +0200
>> Subject: [PATCH] maint: prohibit use of strncpy
>>
>> * cfg.mk (sc_prohibit_strncpy): New syntax-check rule.
>> Exempt pinky.c and who.c, at least for now.
>> ---
>>  cfg.mk | 9 +++++++++
>>  1 file changed, 9 insertions(+)
>>
>> diff --git a/cfg.mk b/cfg.mk
>> index 7a86c2a..ff5d996 100644
>> --- a/cfg.mk
>> +++ b/cfg.mk
>> @@ -403,6 +403,12 @@ sc_prohibit_strncmp:
>>        { echo '$(ME): use STREQ_LEN or STRPREFIX instead of str''ncmp' \
>>              1>&2; exit 1; } || :
>>
>> +# Really.  You don't want to use this function.
>> +sc_prohibit_strncpy:
>> +    @prohibit='\<str''ncpy *\('                                     \
>> +    halt='do not use str''ncpy, period'                             \
>> +      $(_sc_search_regexp)
>
>
> This seems like it is worth floating into gnulib's maint.mk.

That was my plan.
I notice that libvirt has had a similar rule for a couple of years.

This rule has two minor improvements over the one in coreutils:
I removed the str''ncpy obfuscation, since it wasn't needed,
and added comments.


>From 71b2855288794404177296fab5db2f851db7a8a8 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Fri, 25 May 2012 16:38:49 +0200
Subject: [PATCH] maint.mk: add strncpy-prohibiting syntax-check rule

* top/maint.mk (sc_prohibit_strncpy): New rule, from coreutils.
---
 ChangeLog    | 5 +++++
 top/maint.mk | 8 ++++++++
 2 files changed, 13 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index 686228c..1252100 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2012-05-25  Jim Meyering  <address@hidden>
+
+       maint.mk: add strncpy-prohibiting syntax-check rule
+       * top/maint.mk (sc_prohibit_strncpy): New rule, from coreutils.
+
 2012-05-24  Jim Meyering  <address@hidden>

        maint.mk: compute $(gpg_key_ID) more portably
diff --git a/top/maint.mk b/top/maint.mk
index 9746410..11cb6a6 100644
--- a/top/maint.mk
+++ b/top/maint.mk
@@ -332,6 +332,14 @@ sc_prohibit_strcmp:
        halt='$(ME): replace strcmp calls above with STREQ/STRNEQ'      \
          $(_sc_search_regexp)

+# Really.  You don't want to use this function.
+# It may fail to NUL-terminate the destination,
+# and always NUL-pads out to the specified length.
+sc_prohibit_strncpy:
+       @prohibit='\<strncpy *\('                                       \
+       halt='do not use strncpy, period'                               \
+         $(_sc_search_regexp)
+
 # Pass EXIT_*, not number, to usage, exit, and error (when exiting)
 # Convert all uses automatically, via these two commands:
 # git grep -l '\<exit *(1)' \
--
1.7.10.2.565.gbd578b5



reply via email to

[Prev in Thread] Current Thread [Next in Thread]