mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Anders Larsen <al@alarsen.net>
To: Tong Zhang <ztong0001@gmail.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH v1] qnx4_match: do not over run the buffer
Date: Sat, 21 Nov 2020 22:40:17 +0100	[thread overview]
Message-ID: <2474566.rpppqFFLNx@alarsen.net> (raw)
In-Reply-To: <20201120212120.2502522-1-ztong0001@gmail.com>

On Friday, 2020-11-20 22:21 Tong Zhang wrote:
> the di_fname may not terminated by '\0', use strnlen to prevent buffer
> overrun
> 
> ---
>  fs/qnx4/namei.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/qnx4/namei.c b/fs/qnx4/namei.c
> index 8d72221735d7..c0e79094f578 100644
> --- a/fs/qnx4/namei.c
> +++ b/fs/qnx4/namei.c
> @@ -40,7 +40,7 @@ static int qnx4_match(int len, const char *name,
>  	} else {
>  		namelen = QNX4_SHORT_NAME_MAX;
>  	}
> -	thislen = strlen( de->di_fname );
> +	thislen = strnlen( de->di_fname, QNX4_SHORT_NAME_MAX );

that should be
+	thislen = strnlen( de->di_fname, namelen );
otherwise the length of a filename would always be limited to QNX4_SHORT_NAME_MAX (16) characters.

>  	if ( thislen > namelen )
>  		thislen = namelen;

These two lines can be dropped now, as the result of strnlen() cannot exceed namelen anyway.

Cheers
Anders



  reply	other threads:[~2020-11-21 21:40 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-20 21:21 Tong Zhang
2020-11-21 21:40 ` Anders Larsen [this message]
2020-11-21 21:47   ` Tong Zhang
2020-11-21 21:57     ` Anders Larsen
2020-11-22  1:27       ` Tong Zhang

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=2474566.rpppqFFLNx@alarsen.net \
    --to=al@alarsen.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ztong0001@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®