Fix IndexError in GitConfigParser when config value ends in new line · gitpython-developers/GitPython@47e5738 · GitHub
Skip to content

Commit 47e5738

Browse files
committed
Fix IndexError in GitConfigParser when config value ends in new line
Improve the guarding `if` check in `GitConfigParser`'s `string_decode` function to safely handle empty strings and prevent `IndexError`s when accessing string elements. This resolves an IndexError in the `GitConfigParser`'s `.read()` method when the config file contains a quoted value containing a trailing new line. Fixes: #1887
1 parent bc7bd22 commit 47e5738

3 files changed

Lines changed: 11 additions & 7 deletions

File tree

fuzzing/fuzz-targets/fuzz_config.py

Lines changed: 2 additions & 6 deletions

git/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ def _read(self, fp: Union[BufferedReader, IO[bytes]], fpname: str) -> None:
452452
e = None # None, or an exception.
453453

454454
def string_decode(v: str) -> str:
455-
if v[-1] == "\\":
455+
if v and v[-1] == "\\":
456456
v = v[:-1]
457457
# END cut trailing escapes to prevent decode error
458458

test/test_config.py

Lines changed: 8 additions & 0 deletions

0 commit comments

Comments
 (0)