|
| 1 | +From 52f3cb58093cdccffd87af9c97fd4ba61a0b848d Mon Sep 17 00:00:00 2001 |
| 2 | +From: Rohit Rawat < [email protected]> |
| 3 | +Date: Mon, 27 Jan 2025 12:36:21 +0000 |
| 4 | +Subject: [PATCH] Fix CVE-2024-53263 |
| 5 | + |
| 6 | +Backported from https://github.com/git-lfs/git-lfs/commit/0345b6f816e611d050c0df67b61f0022916a1c90 |
| 7 | + |
| 8 | +--- |
| 9 | + creds/creds.go | 12 +++++++++--- |
| 10 | + 1 file changed, 9 insertions(+), 3 deletions(-) |
| 11 | + |
| 12 | +diff --git a/creds/creds.go b/creds/creds.go |
| 13 | +index 0cc6762..f4e1432 100644 |
| 14 | +--- a/creds/creds.go |
| 15 | ++++ b/creds/creds.go |
| 16 | +@@ -53,11 +53,14 @@ func (credWrapper *CredentialHelperWrapper) FillCreds() error { |
| 17 | + // as input. |
| 18 | + type Creds map[string][]string |
| 19 | + |
| 20 | +-func bufferCreds(c Creds) *bytes.Buffer { |
| 21 | ++func bufferCreds(c Creds) (*bytes.Buffer, error) { |
| 22 | + buf := new(bytes.Buffer) |
| 23 | + |
| 24 | + for k, v := range c { |
| 25 | + for _, item := range v { |
| 26 | ++ if strings.Contains(item, "\n") { |
| 27 | ++ return nil, errors.Errorf(tr.Tr.Get("credential value for %s contains newline: %q", k, item)) |
| 28 | ++ } |
| 29 | + buf.Write([]byte(k)) |
| 30 | + buf.Write([]byte("=")) |
| 31 | + buf.Write([]byte(item)) |
| 32 | +@@ -65,7 +68,7 @@ func bufferCreds(c Creds) *bytes.Buffer { |
| 33 | + } |
| 34 | + } |
| 35 | + |
| 36 | +- return buf |
| 37 | ++ return buf, nil |
| 38 | + } |
| 39 | + |
| 40 | + type CredentialHelperContext struct { |
| 41 | +@@ -323,7 +326,10 @@ func (h *commandCredentialHelper) exec(subcommand string, input Creds) (Creds, e |
| 42 | + if err != nil { |
| 43 | + return nil, errors.New(tr.Tr.Get("failed to find `git credential %s`: %v", subcommand, err)) |
| 44 | + } |
| 45 | +- cmd.Stdin = bufferCreds(input) |
| 46 | ++ cmd.Stdin, err = bufferCreds(input) |
| 47 | ++ if err != nil { |
| 48 | ++ return nil, errors.New(tr.Tr.Get("invalid input to `git credential %s`: %v", subcommand, err)) |
| 49 | ++ } |
| 50 | + cmd.Stdout = output |
| 51 | + /* |
| 52 | + There is a reason we don't read from stderr here: |
| 53 | +-- |
| 54 | +2.40.4 |
| 55 | + |
0 commit comments