threads / patch / 2703

patchFix typo in http-push.c

Subject: [PATCH] Fix typo in http-push.c

## tl;dr

6 messages between Nov 29, 2005 and Nov 29, 2005. Diffs are folded; open one to read it.

replies: 5people: 3as markdown or json

Jan Andres· Nov 29, 2005, 00:51 UTC · lore
Hi guys,

Please find below the patch for a typo in http-push.c (in the maint branch), which caused git-http-push to segfault on my Linux i386 box.

Regards, Jan

Show changes to http-push.c +1 −1
diff --git a/http-push.c b/http-push.c
index 76c7886..ad78982 100644
--- a/http-push.c
+++ b/http-push.c
@@ -784,7 +784,7 @@ static void handle_new_lock_ctx(struct x
 					strtol(ctx->cdata + 7, NULL, 10);
 		} else if (!strcmp(ctx->name, DAV_ACTIVELOCK_TOKEN)) {
 			if (!strncmp(ctx->cdata, "opaquelocktoken:", 16)) {
-				lock->token = xmalloc(strlen(ctx->cdata - 15));
+				lock->token = xmalloc(strlen(ctx->cdata) - 15);
 				strcpy(lock->token, ctx->cdata + 16);
 			}
 		}
-- 
Jan Andres <jandres@gmx.net>
Junio C Hamano· Nov 29, 2005, 06:03 UTC · re: Jan Andres · lore

Re: [PATCH] Fix typo in http-push.c

Jan Andres <jandres@gmx.net> writes:
> Please find below the patch for a typo in http-push.c (in the maint
> branch), which caused git-http-push to segfault on my Linux i386 box.

Thanks. Next time around please sign-off your patches (see Documentation/SubmittingPatches).

Johannes Schindelin· Nov 29, 2005, 08:24 UTC · re: Jan Andres · lore

Re: [PATCH] Fix typo in http-push.c

Hi,
On Tue, 29 Nov 2005, Jan Andres wrote:
> -				lock->token = xmalloc(strlen(ctx->cdata - 15));
> +				lock->token = xmalloc(strlen(ctx->cdata) - 15);
>  				strcpy(lock->token, ctx->cdata + 16);
Why not
+				lock->token = xmalloc(strlen(ctx->cdata + 16));

Ciao, Dscho

Jan Andres· Nov 29, 2005, 13:35 UTC · re: Johannes Schindelin · lore

Re: [PATCH] Fix typo in http-push.c

Hi,
On Tue, 29. Nov. 2005 at 09:24:47 +0100, Johannes Schindelin wrote:
Show 11 quoted lines
> Hi,
> 
> On Tue, 29 Nov 2005, Jan Andres wrote:
> 
> > -				lock->token = xmalloc(strlen(ctx->cdata - 15));
> > +				lock->token = xmalloc(strlen(ctx->cdata) - 15);
> >  				strcpy(lock->token, ctx->cdata + 16);
> 
> Why not
> 
> +				lock->token = xmalloc(strlen(ctx->cdata + 16));
Looks more efficient indeed, but wouldn't we have to use
+				lock->token = xmalloc(strlen(ctx->cdata + 16) + 1);
so as to account for the trailing NUL?
Regards
-- 
Jan Andres <jandres@gmx.net>
Jan Andres· Nov 29, 2005, 15:30 UTC · re: Jan Andres · lore

[PATCH] Fix typo in http-push.c, take two

Ok, so this is my final(?) proposal for the fix.
---

Fix a bug in handle_new_lock_ctx()'s memory allocation which may cause segfaults.

Signed-off-by: Jan Andres <jandres@gmx.net>
---
Show changes to http-push.c +2 −1
diff --git a/http-push.c b/http-push.c
index 76c7886..bbb5118 100644
--- a/http-push.c
+++ b/http-push.c
@@ -784,7 +784,8 @@ static void handle_new_lock_ctx(struct x
 					strtol(ctx->cdata + 7, NULL, 10);
 		} else if (!strcmp(ctx->name, DAV_ACTIVELOCK_TOKEN)) {
 			if (!strncmp(ctx->cdata, "opaquelocktoken:", 16)) {
-				lock->token = xmalloc(strlen(ctx->cdata - 15));
+				lock->token =
+					xmalloc(strlen(ctx->cdata + 16) + 1);
 				strcpy(lock->token, ctx->cdata + 16);
 			}
 		}
---
0.99.9.GIT
-- 
Jan Andres <jandres@gmx.net>
Johannes Schindelin· Nov 29, 2005, 16:40 UTC · re: Jan Andres · lore

Re: [PATCH] Fix typo in http-push.c

Hi,
On Tue, 29 Nov 2005, Jan Andres wrote:
Show 5 quoted lines
> [...]
>
> +				lock->token = xmalloc(strlen(ctx->cdata + 16) + 1);
> 
> so as to account for the trailing NUL?

Of course! That's why I wanted to write "strlen(ctx->cdata + 15)", but I fsck'ed up. Sorry.

Ciao, Dscho

← back to recent threads