<feed xmlns='http://www.w3.org/2005/Atom'>
<title>git/git.c, branch v2.8.2</title>
<subtitle>Mirror of https://git.kernel.org/pub/scm/git/git.git/
</subtitle>
<id>https://git.shady.money/git/atom?h=v2.8.2</id>
<link rel='self' href='https://git.shady.money/git/atom?h=v2.8.2'/>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/'/>
<updated>2016-03-07T01:17:37Z</updated>
<entry>
<title>setup: make startup_info available everywhere</title>
<updated>2016-03-07T01:17:37Z</updated>
<author>
<name>Jeff King</name>
<email>peff@peff.net</email>
</author>
<published>2016-03-05T22:10:27Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=46c3cd44d7a1e8a33ad66c017ac9e3575cc88c00'/>
<id>urn:sha1:46c3cd44d7a1e8a33ad66c017ac9e3575cc88c00</id>
<content type='text'>
Commit a60645f (setup: remember whether repository was
found, 2010-08-05) introduced the startup_info structure,
which records some parts of the setup_git_directory()
process (notably, whether we actually found a repository or
not).

One of the uses of this data is for functions to behave
appropriately based on whether we are in a repo. But the
startup_info struct is just a pointer to storage provided by
the main program, and the only program that sets it up is
the git.c wrapper. Thus builtins have access to
startup_info, but externally linked programs do not.

Worse, library code which is accessible from both has to be
careful about accessing startup_info. This can be used to
trigger a die("BUG") via get_sha1():

	$ git fast-import &lt;&lt;-\EOF
	tag foo
	from HEAD:./whatever
	EOF

	fatal: BUG: startup_info struct is not initialized.

Obviously that's fairly nonsensical input to feed to
fast-import, but we should never hit a die("BUG"). And there
may be other ways to trigger it if other non-builtins
resolve sha1s.

So let's point the storage for startup_info to a static
variable in setup.c, making it available to all users of the
library code. We _could_ turn startup_info into a regular
extern struct, but doing so would mean tweaking all of the
existing use sites. So let's leave the pointer indirection
in place.  We can, however, drop any checks for NULL, as
they will always be false (and likewise, we can drop the
test covering this case, which was a rather artificial
situation using one of the test-* programs).

Signed-off-by: Jeff King &lt;peff@peff.net&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>Merge branch 'jk/tighten-alloc'</title>
<updated>2016-02-26T21:37:16Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2016-02-26T21:37:16Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=11529ecec914d2f0d7575e6d443c2d5a6ff75424'/>
<id>urn:sha1:11529ecec914d2f0d7575e6d443c2d5a6ff75424</id>
<content type='text'>
Update various codepaths to avoid manually-counted malloc().

* jk/tighten-alloc: (22 commits)
  ewah: convert to REALLOC_ARRAY, etc
  convert ewah/bitmap code to use xmalloc
  diff_populate_gitlink: use a strbuf
  transport_anonymize_url: use xstrfmt
  git-compat-util: drop mempcpy compat code
  sequencer: simplify memory allocation of get_message
  test-path-utils: fix normalize_path_copy output buffer size
  fetch-pack: simplify add_sought_entry
  fast-import: simplify allocation in start_packfile
  write_untracked_extension: use FLEX_ALLOC helper
  prepare_{git,shell}_cmd: use argv_array
  use st_add and st_mult for allocation size computation
  convert trivial cases to FLEX_ARRAY macros
  use xmallocz to avoid size arithmetic
  convert trivial cases to ALLOC_ARRAY
  convert manual allocations to argv_array
  argv-array: add detach function
  add helpers for allocating flex-array structs
  harden REALLOC_ARRAY and xcalloc against size_t overflow
  tree-diff: catch integer overflow in combine_diff_path allocation
  ...
</content>
</entry>
<entry>
<title>Merge branch 'ak/git-strip-extension-from-dashed-command'</title>
<updated>2016-02-26T21:37:13Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2016-02-26T21:37:13Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=dede29612a723a7da9f489fecbdf02500a018430'/>
<id>urn:sha1:dede29612a723a7da9f489fecbdf02500a018430</id>
<content type='text'>
Code simplification.

* ak/git-strip-extension-from-dashed-command:
  git.c: simplify stripping extension of a file in handle_builtin()
</content>
</entry>
<entry>
<title>convert manual allocations to argv_array</title>
<updated>2016-02-22T22:50:32Z</updated>
<author>
<name>Jeff King</name>
<email>peff@peff.net</email>
</author>
<published>2016-02-22T22:44:21Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=850d2fec53ee188bab9e458f77906041ac7f1904'/>
<id>urn:sha1:850d2fec53ee188bab9e458f77906041ac7f1904</id>
<content type='text'>
There are many manual argv allocations that predate the
argv_array API. Switching to that API brings a few
advantages:

  1. We no longer have to manually compute the correct final
     array size (so it's one less thing we can screw up).

  2. In many cases we had to make a separate pass to count,
     then allocate, then fill in the array. Now we can do it
     in one pass, making the code shorter and easier to
     follow.

  3. argv_array handles memory ownership for us, making it
     more obvious when things should be free()d and and when
     not.

Most of these cases are pretty straightforward. In some, we
switch from "run_command_v" to "run_command" which lets us
directly use the argv_array embedded in "struct
child_process".

Signed-off-by: Jeff King &lt;peff@peff.net&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>git.c: simplify stripping extension of a file in handle_builtin()</title>
<updated>2016-02-22T07:52:43Z</updated>
<author>
<name>Alexander Kuleshov</name>
<email>kuleshovmail@gmail.com</email>
</author>
<published>2016-02-22T07:18:29Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=63ca1c099c36e61b0e9cd7fa0b912c0b9d89b628'/>
<id>urn:sha1:63ca1c099c36e61b0e9cd7fa0b912c0b9d89b628</id>
<content type='text'>
The handle_builtin() starts from stripping of command extension if
STRIP_EXTENSION is enabled. Actually STRIP_EXTENSION does not used
anywhere else.

This patch introduces strip_extension() helper to strip STRIP_EXTENSION
extension from argv[0] with the strip_suffix() instead of manually
stripping.

Signed-off-by: Alexander Kuleshov &lt;kuleshovmail@gmail.com&gt;
Helped-by: Jeff King &lt;peff@peff.net&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>Merge branch 'nd/clear-gitenv-upon-use-of-alias'</title>
<updated>2016-02-17T18:13:31Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2016-02-17T18:13:31Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=dbda66b0e283494c35958316c9b1c47b6e6c9f59'/>
<id>urn:sha1:dbda66b0e283494c35958316c9b1c47b6e6c9f59</id>
<content type='text'>
The automatic typo correction applied to an alias was broken
with a recent change already in 'master'.

* nd/clear-gitenv-upon-use-of-alias:
  restore_env(): free the saved environment variable once we are done
  git: simplify environment save/restore logic
  git: protect against unbalanced calls to {save,restore}_env()
  git: remove an early return from save_env_before_alias()
</content>
</entry>
<entry>
<title>restore_env(): free the saved environment variable once we are done</title>
<updated>2016-02-02T23:42:59Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2016-02-02T23:42:59Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=8384c139cb9409fb3cf5ef70afff263917581258'/>
<id>urn:sha1:8384c139cb9409fb3cf5ef70afff263917581258</id>
<content type='text'>
Just like we free orig_cwd, which is the value of the original
working directory saved in save_env_before_alias(), once we are
done with it, the contents of orig_env[] array, saved in the
save_env_before_alias() function should be freed; otherwise,
the second and subsequent calls to save/restore pair will leak
the memory allocated in save_env_before_alias().

Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>git: simplify environment save/restore logic</title>
<updated>2016-01-27T23:45:55Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2016-01-27T06:52:02Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=441981bc85ea2b648d7ffb2515b371071208e657'/>
<id>urn:sha1:441981bc85ea2b648d7ffb2515b371071208e657</id>
<content type='text'>
The only code that cares about the value of the global variable
saved_env_before_alias after the previous fix is handle_builtin()
that turns into a glorified no-op when the variable is true, so the
logic could safely be lifted to its caller, i.e. the caller can
refrain from calling it when the variable is set.

This variable tells us if save_env_before_alias() was called (with
or without matching restore_env()), but the sole caller of the
function, handle_alias(), always calls it as the first thing, so we
can consider that the variable essentially keeps track of the fact
that handle_alias() has ever been called.

It turns out that handle_builtin() and handle_alias() are called
only from one function in a way that the value of the variable
matters, which is run_argv(), and it already keeps track of the
fact that it already called handle_alias().

So we can simplify the whole thing by:

- Change handle_builtin() to always make a direct call to the
  builtin implementation it finds, and make sure the caller
  refrains from calling it if handle_alias() has ever been
  called;

- Remove saved_env_before_alias variable, and instead use the
  local "done_alias" variable maintained inside run_argv() to
  make the same decision.

Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>git: protect against unbalanced calls to {save,restore}_env()</title>
<updated>2016-01-27T23:19:03Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2016-01-27T06:50:27Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=2e1175d43d05e83fe836e1c8c8e7c25b7ee659ae'/>
<id>urn:sha1:2e1175d43d05e83fe836e1c8c8e7c25b7ee659ae</id>
<content type='text'>
We made sure that save_env_before_alias() does not skip saving the
environment when asked to (which led to use-after-free of orig_cwd
in restore_env() in the buggy version) with the previous step.

Protect against future breakage where somebody adds new callers of
these functions in an unbalanced fashion.

Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>git: remove an early return from save_env_before_alias()</title>
<updated>2016-01-27T23:12:37Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2016-01-26T19:46:53Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=9d1d2b7fad9bec6320a2058c625787c835864960'/>
<id>urn:sha1:9d1d2b7fad9bec6320a2058c625787c835864960</id>
<content type='text'>
When help.autocorrect is in effect, an attempt to auto-execute an
uniquely corrected result of a misspelt alias will result in an
irrelevant error message.  The codepath that causes this calls
save_env_before_alias() and restore_env() in handle_alias(), and
that happens twice.  A global variable orig_cwd is allocated to hold
the return value of getcwd() in save_env_before_alias(), which is
then used in restore_env() to go back to that directory and finally
free(3)'d there.

However, save_env_before_alias() is not prepared to be called twice.
It returns early when it knows it has already been called, leaving
orig_cwd undefined, which is then checked in the second call to
restore_env(), and by that time, the memory that used to hold the
contents of orig_cwd is either freed or reused to hold something
else, and this is fed to chdir(2), causing it to fail.  Even if it
did not fail (i.e. reading of the already free'd piece of memory
yielded a directory path that we can chdir(2) to), it then gets
free(3)'d.

Fix this by making sure save_env() does do the saving when called.

While at it, add a minimal test for help.autocorrect facility.

Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
</feed>
