{"thread":{"id":"4420","subject":"[PATCH] Off-by-one error in get_path_prefix(), found by Valgrind","startedAt":"2006-06-07T17:01:40Z","lastAt":"2006-06-07T18:47:03Z","messageCount":4,"participants":["Pavel Roskin","Rene Scharfe","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"21384","messageId":"20060607170140.13372.64613.stgit@dv.roinet.com","threadId":"4420","inReplyTo":null,"subject":"[PATCH] Off-by-one error in get_path_prefix(), found by Valgrind","fromName":"Pavel Roskin","fromEmail":"proski@gnu.org","sentAt":"2006-06-07T17:01:40Z","receivedAt":"2006-06-07T17:01:40Z","isPatch":true,"sender":{"key":"proski@gnu.org","avatar":null},"body":"From: Pavel Roskin <proski@gnu.org>\n\nSigned-off-by: Pavel Roskin <proski@gnu.org>\n---\n\n builtin-tar-tree.c |    4 ++--\n 1 files changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin-tar-tree.c b/builtin-tar-tree.c\nindex 5f740cf..05da1f2 100644\n--- a/builtin-tar-tree.c\n+++ b/builtin-tar-tree.c\n@@ -166,8 +166,8 @@ static unsigned int ustar_header_chksum(\n static int get_path_prefix(const struct strbuf *path, int maxlen)\n {\n \tint i = path->len;\n-\tif (i > maxlen)\n-\t\ti = maxlen;\n+\tif (i >= maxlen)\n+\t\ti = maxlen - 1;\n \twhile (i > 0 && path->buf[i] != '/')\n \t\ti--;\n \treturn i;\n"},{"id":"21387","messageId":"20060607180543.GA26638@lsrfire.ath.cx","threadId":"4420","inReplyTo":"20060607170140.13372.64613.stgit@dv.roinet.com","subject":"Re: [PATCH] Off-by-one error in get_path_prefix(), found by Valgrind","fromName":"Rene Scharfe","fromEmail":"rene.scharfe@lsrfire.ath.cx","sentAt":"2006-06-07T18:05:43Z","receivedAt":"2006-06-07T18:05:43Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"On Wed, Jun 07, 2006 at 01:01:40PM -0400, Pavel Roskin wrote:\n> From: Pavel Roskin <proski@gnu.org>\n> \n> Signed-off-by: Pavel Roskin <proski@gnu.org>\n> ---\n> \n>  builtin-tar-tree.c |    4 ++--\n>  1 files changed, 2 insertions(+), 2 deletions(-)\n> \n> diff --git a/builtin-tar-tree.c b/builtin-tar-tree.c\n> index 5f740cf..05da1f2 100644\n> --- a/builtin-tar-tree.c\n> +++ b/builtin-tar-tree.c\n> @@ -166,8 +166,8 @@ static unsigned int ustar_header_chksum(\n>  static int get_path_prefix(const struct strbuf *path, int maxlen)\n>  {\n>  \tint i = path->len;\n> -\tif (i > maxlen)\n> -\t\ti = maxlen;\n> +\tif (i >= maxlen)\n> +\t\ti = maxlen - 1;\n>  \twhile (i > 0 && path->buf[i] != '/')\n>  \t\ti--;\n>  \treturn i;\n\nArgh, yes.  Thanks, Pavel!  However, the other branch is incorrect, too:\naccessing path->buf[path->len] is wrong, even if it's within the buffer.\nIn order to use a length variable to point to the end of some string we\nneed to subtract 1. *sigh*  So, how about this one instead?\n\nSigned-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>\n\ndiff --git a/builtin-tar-tree.c b/builtin-tar-tree.c\nindex 5f740cf..7663b9b 100644\n--- a/builtin-tar-tree.c\n+++ b/builtin-tar-tree.c\n@@ -168,8 +168,9 @@ static int get_path_prefix(const struct \n \tint i = path->len;\n \tif (i > maxlen)\n \t\ti = maxlen;\n-\twhile (i > 0 && path->buf[i] != '/')\n+\tdo {\n \t\ti--;\n+\t} while (i > 0 && path->buf[i] != '/');\n \treturn i;\n }\n \n"},{"id":"21390","messageId":"1149705204.11931.3.camel@dv","threadId":"4420","inReplyTo":"20060607180543.GA26638@lsrfire.ath.cx","subject":"Re: [PATCH] Off-by-one error in get_path_prefix(), found by Valgrind","fromName":"Pavel Roskin","fromEmail":"proski@gnu.org","sentAt":"2006-06-07T18:33:24Z","receivedAt":"2006-06-07T18:33:24Z","isPatch":true,"sender":{"key":"proski@gnu.org","avatar":null},"body":"On Wed, 2006-06-07 at 20:05 +0200, Rene Scharfe wrote:\n> Argh, yes.  Thanks, Pavel!\n\nActually, thanks to Julian Seward for Valgrind.\n\n>   However, the other branch is incorrect, too:\n> accessing path->buf[path->len] is wrong, even if it's within the buffer.\n> In order to use a length variable to point to the end of some string we\n> need to subtract 1. *sigh*  So, how about this one instead?\n\nFine with me.  Thank you for noticing!\n\n-- \nRegards,\nPavel Roskin\n"},{"id":"21394","messageId":"7v8xo8hkgo.fsf@assigned-by-dhcp.cox.net","threadId":"4420","inReplyTo":"1149705204.11931.3.camel@dv","subject":"Re: [PATCH] Off-by-one error in get_path_prefix(), found by Valgrind","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-06-07T18:47:03Z","receivedAt":"2006-06-07T18:47:03Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Pavel Roskin <proski@gnu.org> writes:\n\n> On Wed, 2006-06-07 at 20:05 +0200, Rene Scharfe wrote:\n>> Argh, yes.  Thanks, Pavel!\n>\n> Actually, thanks to Julian Seward for Valgrind.\n>\n>>   However, the other branch is incorrect, too:\n>> accessing path->buf[path->len] is wrong, even if it's within the buffer.\n>> In order to use a length variable to point to the end of some string we\n>> need to subtract 1. *sigh*  So, how about this one instead?\n>\n> Fine with me.  Thank you for noticing!\n\nThanks both.  Applied.\n"}]}