microsoft / git

A fork of Git containing Microsoft-specific patches.
http://git-scm.com/
Other
782 stars 92 forks source link

fixup! scalar: add the `cache-server` command #653

Closed derrickstolee closed 4 months ago

derrickstolee commented 5 months ago

A user reported that a use of 'scalar cache-server --set ...' on Linux resulted in a failure with message

  munmap_chunk(): invalid pointer
  Aborted (core dumped)

It turns out that the cmd_cache_server() method has several invalid mechanisms around command parsing. Specifically in this case, it is attempting to free() the strings that are loaded from command-line options. These strings are not actually owned by the process and should not be freed. In fact, they should be stored as 'const' pointers to make the compiler complain about freeing them.

There are a few other things that also seemed odd that I took the liberty to fix while here. For one, the "--list" option used a nonstandard version of OPT_STRING() only so it could set "(default)" as the value when no string is provided. However, this does not work as expected, and "--list" always requires a value. Make that explicit.

Add tests that check some of the critical paths of this command, including the "--list" command querying the gvfs/config endpoint of the remote URL. This works even without using "scalar clone --gvfs-protocol" because it is only setting Git config as an end-result.