# [PATCH] Fix typo in http-push.c

6 messages from 2005-11-29 to 2005-11-29. Participants: Jan Andres, Junio C Hamano, Johannes Schindelin.
Thread: https://gitlist.dev/t/2703

## Jan Andres, 2005-11-29 00:51

Subject: [PATCH] Fix typo in http-push.c
Message-ID: <20051129005154.GA3076@pitr.home.jan>
URL: https://gitlist.dev/e/20051129005154.GA3076%40pitr.home.jan

```
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


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, 2005-11-29 06:03

Subject: Re: [PATCH] Fix typo in http-push.c
Message-ID: <7vbr04ng7h.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7vbr04ng7h.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <20051129005154.GA3076@pitr.home.jan>

```
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, 2005-11-29 08:24

Subject: Re: [PATCH] Fix typo in http-push.c
Message-ID: <Pine.LNX.4.63.0511290923390.16927@wbgn013.biozentrum.uni-wuerzburg.de>
URL: https://gitlist.dev/e/Pine.LNX.4.63.0511290923390.16927%40wbgn013.biozentrum.uni-wuerzburg.de
In-Reply-To: <20051129005154.GA3076@pitr.home.jan>

```
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, 2005-11-29 13:35

Subject: Re: [PATCH] Fix typo in http-push.c
Message-ID: <20051129133537.GA490@pitr.home.jan>
URL: https://gitlist.dev/e/20051129133537.GA490%40pitr.home.jan
In-Reply-To: <Pine.LNX.4.63.0511290923390.16927@wbgn013.biozentrum.uni-wuerzburg.de>

```
Hi,

On Tue, 29. Nov. 2005 at 09:24:47 +0100, Johannes Schindelin wrote:
> 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, 2005-11-29 15:30

Subject: [PATCH] Fix typo in http-push.c, take two
Message-ID: <20051129153046.GA9091@pitr.home.jan>
URL: https://gitlist.dev/e/20051129153046.GA9091%40pitr.home.jan
In-Reply-To: <20051129133537.GA490@pitr.home.jan>

```
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>

---

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, 2005-11-29 16:40

Subject: Re: [PATCH] Fix typo in http-push.c
Message-ID: <Pine.LNX.4.63.0511291739090.12136@wbgn013.biozentrum.uni-wuerzburg.de>
URL: https://gitlist.dev/e/Pine.LNX.4.63.0511291739090.12136%40wbgn013.biozentrum.uni-wuerzburg.de
In-Reply-To: <20051129133537.GA490@pitr.home.jan>

```
Hi,

On Tue, 29 Nov 2005, Jan Andres wrote:

> [...]
>
> +				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

```
