Skip to contentSkip to conversation

Fix typo in http-push.c

PATCH In review Jan Andres 3 participants 6 messages Jun 15, 2016

lore
Share & tools
lore

Jan Andres

author
#0 lore raw

PATCH 1/1 Fix typo in http-push.c

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

http-push.c +1 -1
index 76c7886..ad78982 100644
@@ -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);
 			}
 		}
Signature · 1 line
Jan Andres <[email protected]>
#1 lore raw
Quoted 2 lines · Jan Andres

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).

#2 lore raw
In reply to Jan Andres

Hi,

http-push.c static void handle_new_lock_ctx(struct x · line 788

Quoted 3 lines · Jan Andres
http-push.c +1 -1
-				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

author
#3 lore raw

Hi,

Review

Quoted 11 lines · Johannes Schindelin

Hi,

http-push.c static void handle_new_lock_ctx(struct x · line 788

Quoted 3 lines · Jan Andres
http-push.c +1 -1
-				lock->token = xmalloc(strlen(ctx->cdata - 15));
+				lock->token = xmalloc(strlen(ctx->cdata) - 15);
 				strcpy(lock->token, ctx->cdata + 16);

Why not

(quoted diff) +1 -0
+				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

Signature · 1 line
Jan Andres <[email protected]>
author
#4 lore raw

PATCH 1/1 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.

---

http-push.c +2 -1
index 76c7886..bbb5118 100644
@@ -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

Signature · 1 line
Jan Andres <[email protected]>
#5 lore raw
In reply to Jan Andres

Hi,

Quoted 5 lines · Jan Andres

[...]

(quoted diff) +1 -0
+				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