All of lore.kernel.org
 help / color / mirror / Atom feed
From: Goffredo Baroncelli <kreijack@libero.it>
To: Eduardo Silva <eduardo.silva@oracle.com>
Cc: Olaf van der Spek <olafvdspek@gmail.com>,
	Jeremy Sanders <jeremy@jeremysanders.net>,
	linux-btrfs@vger.kernel.org
Subject: Re: [PATCH] Btrfs-progs use safe string manipulation functions
Date: Thu, 10 Feb 2011 19:39:46 +0100	[thread overview]
Message-ID: <4D5430F2.700@libero.it> (raw)
In-Reply-To: <1297344585.28159.12.camel@monotop>

On 02/10/2011 02:29 PM, Eduardo Silva wrote:
> On Thu, 2011-02-10 at 12:39 +0100, Olaf van der Spek wrote:
>> On Thu, Feb 10, 2011 at 12:37 PM, Jeremy Sanders
>> <jeremy@jeremysanders.net> wrote:
>>> Olaf van der Spek wrote:
>>>
>>>> On Thu, Feb 10, 2011 at 12:08 PM, Thomas Bellman <bellman@nsc.liu.se>
>>>> wrote:
>>>>> strncpy(args.name, source, BTRFS_PATH_NAME_MAX);
>>>>> args.name[BTRFS_PATH_NAME_MAX] = '\0';
>>>>
>>>> That's silly. Isn't there a sane safe variant of strcpy?
>>>
>>> There's strlcpy, but it's not in glibc because of possible truncation
>>> errors!
>>
>> Then use a private wrapper.
>>
> 
> Here's the new patch:
> 
> ----
> [PATCH] Add safe string manipulation functions
> 
> Deprecate direct use of strcpy(3)
> The following string manipulation function has been added:
> 
>    - string_copy() : wrapper of strcpy(3)
>    - string_ncopy(): wrapper of strncpy(3)
> 
> both function compose safe NULL terminated strings.
> ----
> 
> I check that the code most of the time raise an error if the path is too
> long, so the new wrappers should be ok...
> 
> best, 
> 
> Eduardo Silva
>  
[...]
+char *string_copy(char *dest, const char *src)
+{
+	if (!dest || !src) {
+		fprintf(stderr, "ERROR: invalid string_copy() parameters");
+		exit(EXIT_FAILURE);
+	}
+
+	memset(dest, '\0', sizeof(dest));

What is the purpose of the line above ?  sizeof(dest) is a const value
(typically 4 or 8) !

I agree with Olaf that string_copy() is usefulness.

I suggest you to improve the check of the string length before the copy
(not in the copy function), and raising an error when the length of the
string is too long.

Regards
G.Baroncelli

  parent reply	other threads:[~2011-02-10 18:39 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-07 12:22 [PATCH] Btrfs-progs use safe string manipulation functions Eduardo Silva
2011-02-07 18:17 ` Goffredo Baroncelli
2011-02-10 11:08 ` Thomas Bellman
2011-02-10 11:21   ` Olaf van der Spek
2011-02-10 11:37     ` Jeremy Sanders
2011-02-10 11:39       ` Olaf van der Spek
2011-02-10 13:29         ` Eduardo Silva
2011-02-10 13:34           ` Olaf van der Spek
2011-02-10 13:41             ` Eduardo Silva
     [not found]             ` <1297345079.28159.14.camel@monotop>
2011-02-10 13:52               ` Olaf van der Spek
2011-02-10 14:00                 ` Eduardo Silva
2011-02-10 14:05                   ` Olaf van der Spek
2011-02-10 18:39           ` Goffredo Baroncelli [this message]
2011-02-11 12:41           ` Lars Wirzenius
2011-02-10 11:54       ` Lars Wirzenius
2011-02-10 12:27         ` Olaf van der Spek
2011-02-10 12:41           ` Thomas Bellman
2011-02-10 15:17       ` Olaf van der Spek
2011-02-10 11:49   ` Eduardo Silva

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4D5430F2.700@libero.it \
    --to=kreijack@libero.it \
    --cc=eduardo.silva@oracle.com \
    --cc=jeremy@jeremysanders.net \
    --cc=kreijack@inwind.it \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=olafvdspek@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.