9412 Commits

Author SHA1 Message Date
Edward Thomson
87a4a4506b ssh_exec: support GIT_SSH_COMMAND
Look for the `GIT_SSH_COMMAND` environment variable and prefer it to
`GIT_SSH`. The `GIT_SSH_COMMAND` will execute via the shell, which is
useful to provide additional arguments.
2025-12-02 20:57:46 +00:00
Edward Thomson
12998e8cad ssh_exec: escape remote paths properly
When sending paths to the remote server, escape them properly.
Escape them with a single quote, followed by the escaped character,
followed by another single quote. This prevents misparsing on the
remote side and potential command injection.
2025-12-02 20:57:46 +00:00
Edward Thomson
11b9586e35 str: allow escaping with prefix and suffix
Allow `git_str_puts_escaped` to take an escaping prefix and an escaping
suffix; this allows for more options, including the ability to better
support escaping executed paths.
2025-12-02 20:57:46 +00:00
Edward Thomson
6060c1cc89 str: add case insensitive suffixcmp 2025-12-02 20:57:46 +00:00
Edward Thomson
e45f41418c ssh_exec: don't use sh for ssh execution
Construct the arguments for the ssh exec as an explicit array, instead
of trying to create a command-line for sh. The latter may use user input
(the remote path) so this may be vulnerable to command injection.
2025-12-02 20:57:46 +00:00
Edward Thomson
b6518d4f04 process: resolve paths for win32
When using `git_process_new` on win32, resolve the path to the
application in the same way that we do on POSIX.

Search `PATH` for command to execute (unless the given executable is
fully qualified). In addition, better match Windows executable lookup
behavior itself (allowing the command to be `foo`, and looking for a
matching `foo.exe` or `foo.cmd`.)
2025-12-01 22:54:48 +00:00
Edward Thomson
00efb8633a process: improved process execution with shell
By default, `git_process_new` will no longer try to prepare a single
string to execute with the shell. Instead, by default, arguments remain
parameterized and the command to execute is located within the `PATH`.

The shell can also still optionally be used (so that additional
arguments can be included and variables handled appropriately) but this
is done by keeping arguments parameterized for safety.

This new behavior prevents accidental misuse and potential command-line
injection.
2025-12-01 22:54:48 +00:00
Edward Thomson
ee46e32536 fs: improve executable search on Windows
Ensure that when we look for an executable on Windows that we add
executable suffixes (`.exe`, `.cmd`). Without this, we would not support
looking for (eg) `ssh`, since we actually need to identify a file named
`ssh.exe` (or `ssh.cmd`) in `PATH`.
2025-12-01 21:46:30 +00:00
Edward Thomson
437379ec2d fs: improve path-in-executable location
* Do not search `PATH` for fully- or partially-qualified filenames
  (eg, `foo/bar`)
* Ensure that a file in the `PATH` is executable before returning it
2025-12-01 21:46:25 +00:00
bakersdozen123
87b2dce1f1 ssh: fix custom ssh heap buffer overflow
The `ssh_custom_free()` function calls `strlen()` on the `publickey` 
field, which stores binary data, not a null-terminated string. This 
causes a heap buffer overflow when the public key data is not 
null-terminated or contains embedded null bytes.

The `publickey` field stores binary data, as required by the underlying 
`libssh2_userauth_publickey()` function, which accepts a public key 
parameter of the type `const unsigned char*`. 

Use the stored `publickey_len` instead of `strlen()` to determine the 
correct buffer size.
2025-12-01 21:39:51 +00:00
Edward Thomson
94ba816f66 Revert "commit: fix const declaration"
This reverts commit cf19ddc522, which
was breaking for several projects.
2024-10-30 17:31:33 -04:00
Edward Thomson
3353f78e8e Merge pull request #6931 from libgit2/ethomson/v1.8.3 2024-10-26 20:03:57 +01:00
Ludovic Courtès
a44f198f92 Apply suggestions from code review
Co-authored-by: Edward Thomson <ethomson@edwardthomson.com>
2024-10-26 19:29:23 +01:00
Ludovic Courtès
65a7ff0644 http: Initialize ‘on_status’ when using the http-parser backend.
Fixes a bug likely introduced in
d396819101 (in 1.8.1) whereby
‘proxy_settings.on_status’ would be left uninitialized when using the
‘http-parser’ backend, eventually leading to a segfault in
‘http_parser_execute’.  Valgrind would report use of the uninitialized
value like so:

   Conditional jump or move depends on uninitialised value(s)
      at 0x50CD533: http_parser_execute (http_parser.c:910)
      by 0x4928504: git_http_parser_execute (httpparser.c:82)
      by 0x4925C42: client_read_and_parse (httpclient.c:1178)
      by 0x4926F27: git_http_client_read_response (httpclient.c:1458)
      by 0x49255FE: http_stream_read (http.c:427)
      by 0x4929B90: git_smart__recv (smart.c:29)
      by 0x492C147: git_smart__store_refs (smart_protocol.c:58)
      by 0x4929F6C: git_smart__connect (smart.c:171)
      by 0x4904DCE: git_remote_connect_ext (remote.c:963)
      by 0x48A15D2: clone_into (clone.c:449)
      by 0x48A15D2: git__clone (clone.c:546)
      by 0x4010E9: main (libgit2-proxy.c:20)
2024-10-26 19:28:58 +01:00
Martin Marmsoler
cc2082aa9b Add assert
Description: In an older version of libgit2 in git_object_lookup_prefix was a check that repo is valid, but now there is repo->oid_type in the git_object_lookup and must be checked as well
2024-06-11 23:12:41 +02:00
Edward Thomson
eb00b48d91 fixup! alloc: introduce debug allocators 2024-05-15 22:38:33 +01:00
Edward Thomson
afb2ef21bc util: don't return system allocated strings in realpath
realpath(3) _may_ allocate strings (if the second param is NULL) using
the system allocator. However, callers need an assurance that they can
free memory using git__free. If we made realpath do an allocation, then
make sure that we strdup it into our allocator's memory.

More importantly, avoid this behavior by always providing a buffer to
p_realpath invocations.
2024-05-13 11:30:25 +01:00
Edward Thomson
aaed67f786 alloc: introduce debug allocators
Instead of tweaking the `stdalloc` allocator when
`GIT_DEBUG_STRICT_ALLOC` is defined, actually create a debugging
allocator. This allows us to ensure that we are strict about things like
not expecting `malloc(0)` to do something useful, but we can also
introduce an excessively pedantic `realloc` implementation that _always_
creates a new buffer, throws away its original `ptr`, and overwrites the
data that's there with garbage. This may be helpful to identify places
that make assumptions about realloc.
2024-05-13 11:30:25 +01:00
Edward Thomson
c7af393a48 Merge pull request #6815 from libgit2/ethomson/signed_comparedness
tree: avoid mixed signedness comparison
2024-05-13 11:29:34 +01:00
Edward Thomson
f5c6b6ab14 Merge pull request #6814 from libgit2/ethomson/alloc
Update git_array allocator to obey strict aliasing rules
2024-05-13 11:29:25 +01:00
Edward Thomson
9a2afb7785 Merge pull request #6813 from libgit2/ethomson/opt_alloc
cli: include alloca on illumos / solaris / sunos
2024-05-13 11:29:04 +01:00
Edward Thomson
54218b5506 array: treat git_array ptrs as void *
Avoid sloppy aliasing in our (re-)allocation, which is undefined
behavior. This has been problematic before and was helped by `volatile`
(see b62a6a13b2) but that is not
technically correct, and some compilers / architectures do not
understand that `ptr` is changing due to its aliasing.

Just make `git_array_alloc` behave like `realloc`, taking a `void *` and
returning a `void *`.
2024-05-13 10:48:56 +01:00
Edward Thomson
2fb07fd0e1 rand: avoid uninitialized loadavg warnings 2024-05-13 10:24:33 +01:00
Edward Thomson
99ba44608f tree: avoid mixed signedness comparison
Promote mode to `uint32_t` before comparing it to an `uint16_t` to avoid
mixed signed comparison warnings.
2024-05-13 10:22:44 +01:00
Edward Thomson
b1d6fd0858 cli: include alloca on illumos / solaris / sunos 2024-05-13 10:21:24 +01:00
Edward Thomson
26e0bd4ca3 Merge pull request #6806 from libgit2/ethomson/fetch_opts
remote: drop bitfields in git_remote_fetch_options
2024-05-13 09:55:39 +01:00
Sven Strickroth
60f219e80b Revparse: Correctly accept ref with '@' at the end
Signed-off-by: Sven Strickroth <email@cs-ware.de>
2024-05-08 17:36:18 +02:00
Edward Thomson
2d649ccd23 remote: drop bitfields in git_remote_fetch_options
In attempting to make a clever change that added fetch options as flags,
while keeping ABI and API compatibility, we screwed up. Bitfields in
structs are implementation-specific and are not necessarily ABI
compatible across compilers.

Make `update_fetchhead` a flags value which is weirdly named, but
that's a future problem. This removes the `report_unchanged` option from
API.
2024-05-06 15:46:21 +01:00
Edward Thomson
2fd37e1bfe transport: support sha256 oids 2024-04-29 22:19:11 +01:00
Edward Thomson
ffd881eb4a transport: provide a useful error message during cancellation
Since 3618a2a, `git_error_last` does not return NULL when there was no
error. Adapt to this when testing for a user cancelling a callback but
not setting an error message, testing for `klass` of `GIT_ERROR_NONE`.
2024-04-29 09:44:30 +01:00
Edward Thomson
85d42ea10e Merge pull request #6796 from ConradIrwin/no-oob
Bounds check for pack index read
2024-04-23 08:12:04 +01:00
Edward Thomson
fb1797de63 Merge remote-tracking branch 'origin/main' into libgit2-httpparser 2024-04-23 00:09:50 +01:00
Edward Thomson
d02b549dab http: make llhttp the default 2024-04-22 22:21:23 +01:00
Edward Thomson
d396819101 http: abstract http parsing out of httpclient
Avoid #ifdef's in httpclient.c, and move http parsing into its own file.
2024-04-22 22:21:23 +01:00
Edward Thomson
06cafdf9d8 pack: upcast to size_t for bounds checking 2024-04-19 09:58:47 +01:00
Edward Thomson
93c94446cd Merge pull request #6792 from barracuda156/apple
process.c: fix environ for macOS
2024-04-19 09:46:25 +01:00
Edward Thomson
9ddf612a00 Merge pull request #6788 from libgit2/ethomson/user_agent
Allow more control over the user-agent
2024-04-18 21:02:59 +01:00
Conrad Irwin
6e8227ab38 Bounds check for pack index read
Fixes: https://github.com/libgit2/libgit2/issues/6795

Co-Authored-By: Bennet <bennetbo@gmx.de>
2024-04-15 09:51:14 -06:00
Jason Haslam
387d01c186 cmake: remove workaround that isn't compatible with Windows on ARM 2024-04-10 21:29:54 -06:00
Sergey Fedorov
4b043541ab process.c: fix environ for macOS 2024-04-08 03:46:17 +08:00
Edward Thomson
4839f4fbfc http: allow users more control over user-agent
Users can now override the "product" portion of the user-agent (via
GIT_OPT_SET_USER_AGENT_PRODUCT). This continues to default to "git/2.0",
but users may define their own string, or may opt out of sending a
user-agent entirely (by passing an empty string). Similarly, users may
now also opt-out of sending any additional "comment" information by
setting the GIT_OPT_SET_USER_AGENT value to an empty string.
2024-03-28 10:10:50 +00:00
Edward Thomson
4d19e8c9c5 settings: pull settings out into its own file 2024-03-28 10:10:46 +00:00
Florian Pircher
34073bf2e5 commit: Fix git_commit_create_from_stage without author and committer 2024-03-24 23:24:31 +01:00
Edward Thomson
0f12a011ab Merge pull request #6770 from libgit2/ethomson/ctype
cast characters to unsigned when classifying characters
2024-03-18 11:31:39 +00:00
Edward Thomson
8e6beb3d16 ctype: switch to git__ ctype functions
Use the `git__` ctype functions (`git__isdigit` and friends) instead of
explicitly casting.
2024-03-18 11:07:47 +00:00
Edward Thomson
647f8eb987 ctype: only use custom functions on Windows
The Microsoft C runtime (MSVCRT) may take a heavy lock on the
locale in order to figure out how the `ctype` functions work.
This is deeply slow. Provide our own to avoid that.

On POSIX, provide emulation for that functionality using the ctype
functions, but compress the return value into a `bool`, and cast the
value to an `unsigned char`.
2024-03-18 11:07:47 +00:00
Edward Thomson
dd35af37d8 repository: rearrange git_repository_item_t values
Update the ordering of `GIT_REPOSITORY_ITEM_WORKTREE_CONFIG` to avoid
breaking the ABI unnecessarily.
2024-03-17 21:52:11 +00:00
Edward Thomson
2eb3fecd03 fetch: avoid API breaking-changes from v1.7
Update `git_fetch_options` to break out the fetch options into
individual options. This prevents creating an API breaking change from
v1.7.0. `git_remote_update_tips` retains the `update_flags` to also
avoid an API breaking change.
2024-03-17 21:26:27 +00:00
Edward Thomson
cc7764f6a6 config: correct fetching the HIGHEST_LEVEL config
Also, add a test for fetching the `GIT_CONFIG_HIGHEST_LEVEL`.
2024-03-17 14:11:40 +00:00
Edward Thomson
47b7d72d2c Merge pull request #6759 from adamharrison/PR/mbedtls3
Allow libgit2 to be compiled with mbedtls3.
2024-03-16 18:10:05 +00:00