All of lore.kernel.org
 help / color / mirror / Atom feed
From: Josef Bacik <josef@redhat.com>
To: Jim Meyering <jim@meyering.net>
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 2/4] restore: don't corrupt stack for a zero-length command-line argument
Date: Fri, 20 Apr 2012 14:40:59 -0400	[thread overview]
Message-ID: <20120420184059.GC1957@localhost.localdomain> (raw)
In-Reply-To: <1334943408-6720-3-git-send-email-jim@meyering.net>

On Fri, Apr 20, 2012 at 07:36:46PM +0200, Jim Meyering wrote:
> From: Jim Meyering <meyering@redhat.com>
> 
> Given a zero-length directory name, the trailing-slash removal
> code would test dir_name[-1], and if it were found to be a slash,
> would set it to '\0'.
> ---
>  restore.c |    8 +++-----
>  1 file changed, 3 insertions(+), 5 deletions(-)
> 
> diff --git a/restore.c b/restore.c
> index 250c9d3..f049105 100644
> --- a/restore.c
> +++ b/restore.c
> @@ -849,11 +849,9 @@ int main(int argc, char **argv)
>  	strncpy(dir_name, argv[optind + 1], 128);
> 
>  	/* Strip the trailing / on the dir name */
> -	while (1) {
> -		len = strlen(dir_name);
> -		if (dir_name[len - 1] != '/')
> -			break;
> -		dir_name[len - 1] = '\0';
> +	len = strlen(dir_name);
> +	while (len && dir_name[--len] == '/')) {
> +		dir_name[len] = '\0';
>  	}

Oops I didn't notice this until I was looking at patch 3, can you take out that
extra ) here so the patch is bisectable.  Thanks,

Josef

  parent reply	other threads:[~2012-04-20 18:40 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-20 17:36 btrfs-utils: minor buffer-overrun fixes Jim Meyering
2012-04-20 17:36 ` [PATCH 1/4] mkfs: use strdup in place of strlen,malloc,strcpy sequence Jim Meyering
2012-04-20 18:36   ` Josef Bacik
2012-04-20 17:36 ` [PATCH 2/4] restore: don't corrupt stack for a zero-length command-line argument Jim Meyering
2012-04-20 18:37   ` Josef Bacik
2012-04-20 18:40   ` Josef Bacik [this message]
2012-04-20 17:36 ` [PATCH 3/4] avoid strncpy-induced buffer overrun Jim Meyering
2012-04-20 18:42   ` Josef Bacik
2012-04-20 19:26     ` Jim Meyering
2012-04-20 17:36 ` [PATCH 4/4] mkfs: avoid heap-buffer-read-underrun for zero-length "size" arg Jim Meyering
2012-04-20 18:41   ` Josef Bacik

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=20120420184059.GC1957@localhost.localdomain \
    --to=josef@redhat.com \
    --cc=jim@meyering.net \
    --cc=linux-btrfs@vger.kernel.org \
    /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.