summaryrefslogtreecommitdiff
AgeCommit message (Collapse)AuthorFilesLines
2017-09-14pkt-line: check write_in_full() errors against "< 0"Libravatar Jeff King1-15/+14
As with the previous two commits, we prefer to check write_in_full()'s return value to see if it is negative, rather than comparing it to the input length. These cases actually flip the logic to check for success, making conversion a little different than in other cases. We could of course write: if (write_in_full(...) >= 0) return 0; return error(...); But our usual method of spelling write() error checks is just "< 0". So let's flip the logic for each of these conditionals to our usual style. Signed-off-by: Jeff King <peff@peff.net> Reviewed-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-09-14convert less-trivial versions of "write_in_full() != len"Libravatar Jeff King3-4/+5
The prior commit converted many sites to check the return value of write_in_full() for negativity, rather than a mismatch with the input length. This patch covers similar cases, but where the return value is stored in an intermediate variable. These should get the same treatment, but they need to be reviewed more carefully since it would be a bug if the return value is stored in an unsigned type (which indeed, it is in one of the cases). Signed-off-by: Jeff King <peff@peff.net> Reviewed-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-09-14avoid "write_in_full(fd, buf, len) != len" patternLibravatar Jeff King16-27/+26
The return value of write_in_full() is either "-1", or the requested number of bytes[1]. If we make a partial write before seeing an error, we still return -1, not a partial value. This goes back to f6aa66cb95 (write_in_full: really write in full or return error on disk full., 2007-01-11). So checking anything except "was the return value negative" is pointless. And there are a couple of reasons not to do so: 1. It can do a funny signed/unsigned comparison. If your "len" is signed (e.g., a size_t) then the compiler will promote the "-1" to its unsigned variant. This works out for "!= len" (unless you really were trying to write the maximum size_t bytes), but is a bug if you check "< len" (an example of which was fixed recently in config.c). We should avoid promoting the mental model that you need to check the length at all, so that new sites are not tempted to copy us. 2. Checking for a negative value is shorter to type, especially when the length is an expression. 3. Linus says so. In d34cf19b89 (Clean up write_in_full() users, 2007-01-11), right after the write_in_full() semantics were changed, he wrote: I really wish every "write_in_full()" user would just check against "<0" now, but this fixes the nasty and stupid ones. Appeals to authority aside, this makes it clear that writing it this way does not have an intentional benefit. It's a historical curiosity that we never bothered to clean up (and which was undoubtedly cargo-culted into new sites). So let's convert these obviously-correct cases (this includes write_str_in_full(), which is just a wrapper for write_in_full()). [1] A careful reader may notice there is one way that write_in_full() can return a different value. If we ask write() to write N bytes and get a return value that is _larger_ than N, we could return a larger total. But besides the fact that this would imply a totally broken version of write(), it would already invoke undefined behavior. Our internal remaining counter is an unsigned size_t, which means that subtracting too many byte will wrap it around to a very large number. So we'll instantly begin reading off the end of the buffer, trying to write gigabytes (or petabytes) of data. Signed-off-by: Jeff King <peff@peff.net> Reviewed-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-09-14get-tar-commit-id: check write_in_full() return against 0Libravatar Jeff King1-2/+1
We ask to write 41 bytes and make sure that the return value is at least 41. This is the same "dangerous" pattern that was fixed in the prior commit (wherein a negative return value is promoted to unsigned), though it is not dangerous here because our "41" is a constant, not an unsigned variable. But we should convert it anyway to avoid modeling a dangerous construct. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-09-14config: avoid "write_in_full(fd, buf, len) < len" patternLibravatar Jeff King1-4/+2
The return type of write_in_full() is a signed ssize_t, because we may return "-1" on failure (even if we succeeded in writing some bytes). But "len" itself is may be an unsigned type (the function takes a size_t, but of course we may have something else in the calling function). So while it seems like: if (write_in_full(fd, buf, len) < len) die_errno("write error"); would trigger on error, it won't if "len" is unsigned. The compiler sees a signed/unsigned comparison and promotes the signed value, resulting in (size_t)-1, the highest possible size_t (or again, whatever type the caller has). This cannot possibly be smaller than "len", and so the conditional can never trigger. I scoured the code base for cases of this, but it turns out that these two in git_config_set_multivar_in_file_gently() are the only ones. Here our "len" is the difference between two size_t variables, making the result an unsigned size_t. We can fix this by just checking for a negative return value directly, as write_in_full() will never return any value except -1 or the full count. There's no addition to the test suite here, since you need to convince write() to fail in order to see the problem. The simplest reproduction recipe I came up with is to trigger ENOSPC: # make a limited-size filesystem dd if=/dev/zero of=small.disk bs=1M count=1 mke2fs small.disk mkdir mnt sudo mount -o loop small.disk mnt cd mnt sudo chown $USER:$USER . # make a config file with some content git config --file=config one.key value git config --file=config two.key value # now fill up the disk dd if=/dev/zero of=fill # and try to delete a key, which requires copying the rest # of the file to config.lock, and will fail on write() git config --file=config --unset two.key That final command should (and does after this patch) produce an error message due to the failed write, and leave the file intact. Instead, it silently ignores the failure and renames config.lock into place, leaving you with a totally empty config file! Reported-by: demerphq <demerphq@gmail.com> Signed-off-by: Jeff King <peff@peff.net> Reviewed-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-09-10RelNotes: further fixes for 2.14.2 from the master frontLibravatar Junio C Hamano1-0/+59
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-09-10Merge branch 'jt/doc-pack-objects-fix' into maintLibravatar Junio C Hamano1-6/+11
Doc updates. * jt/doc-pack-objects-fix: Doc: clarify that pack-objects makes packs, plural
2017-09-10Merge branch 'jn/vcs-svn-cleanup' into maintLibravatar Junio C Hamano6-86/+56
Code clean-up. * jn/vcs-svn-cleanup: vcs-svn: move remaining repo_tree functions to fast_export.h vcs-svn: remove repo_delete wrapper function vcs-svn: remove custom mode constants vcs-svn: remove more unused prototypes and declarations
2017-09-10Merge branch 'bc/vcs-svn-cleanup' into maintLibravatar Junio C Hamano3-17/+10
Code clean-up. * bc/vcs-svn-cleanup: vcs-svn: rename repo functions to "svn_repo" vcs-svn: remove unused prototypes
2017-09-10Merge branch 'jk/doc-the-this' into maintLibravatar Junio C Hamano1-2/+2
Doc clean-up. * jk/doc-the-this: doc: fix typo in sendemail.identity
2017-09-10Merge branch 'rs/commit-h-single-parent-cleanup' into maintLibravatar Junio C Hamano1-5/+0
Code clean-up. * rs/commit-h-single-parent-cleanup: commit: remove unused inline function single_parent()
2017-09-10Merge branch 'mg/format-ref-doc-fix' into maintLibravatar Junio C Hamano3-8/+9
Doc fix. * mg/format-ref-doc-fix: Documentation/git-for-each-ref: clarify peeling of tags for --format Documentation: use proper wording for ref format strings
2017-09-10Merge branch 'sb/submodule-parallel-update' into maintLibravatar Junio C Hamano1-1/+0
Code clean-up. * sb/submodule-parallel-update: submodule.sh: remove unused variable
2017-09-10Merge branch 'hv/t5526-andand-chain-fix' into maintLibravatar Junio C Hamano1-4/+4
Test fix. * hv/t5526-andand-chain-fix: t5526: fix some broken && chains
2017-09-10Merge branch 'sb/sha1-file-cleanup' into maintLibravatar Junio C Hamano2-2/+2
Code clean-up. * sb/sha1-file-cleanup: sha1_file: make read_info_alternates static
2017-09-10Merge branch 'rs/t1002-do-not-use-sum' into maintLibravatar Junio C Hamano2-35/+35
Test simplification. * rs/t1002-do-not-use-sum: t1002: stop using sum(1)
2017-09-10Merge branch 'ah/doc-empty-string-is-false' into maintLibravatar Junio C Hamano2-6/+7
Doc update. * ah/doc-empty-string-is-false: doc: clarify "config --bool" behaviour with empty string
2017-09-10Merge branch 'rs/merge-microcleanup' into maintLibravatar Junio C Hamano1-2/+2
Code clean-up. * rs/merge-microcleanup: merge: use skip_prefix()
2017-09-10Merge branch 'rs/find-pack-entry-bisection' into maintLibravatar Junio C Hamano1-2/+2
Code clean-up. * rs/find-pack-entry-bisection: sha1_file: avoid comparison if no packed hash matches the first byte
2017-09-10Merge branch 'rs/apply-lose-prefix-length' into maintLibravatar Junio C Hamano2-8/+5
Code clean-up. * rs/apply-lose-prefix-length: apply: remove prefix_length member from apply_state
2017-09-10Merge branch 'rj/add-chmod-error-message' into maintLibravatar Junio C Hamano1-3/+3
Message fix. * rj/add-chmod-error-message: builtin/add: add detail to a 'cannot chmod' error message
2017-09-10Merge branch 'jk/hashcmp-memcmp' into maintLibravatar Junio C Hamano1-8/+1
Code clean-up. * jk/hashcmp-memcmp: hashcmp: use memcmp instead of open-coded loop
2017-09-10Merge branch 'rs/t3700-clean-leftover' into maintLibravatar Junio C Hamano1-0/+1
A test fix. * rs/t3700-clean-leftover: t3700: fix broken test under !POSIXPERM
2017-09-10Merge branch 'jc/perl-git-comment-typofix' into maintLibravatar Junio C Hamano1-1/+1
A comment fix. * jc/perl-git-comment-typofix: perl/Git.pm: typofix in a comment
2017-09-10Merge branch 'mf/no-dashed-subcommands' into maintLibravatar Junio C Hamano5-10/+10
Code clean-up. * mf/no-dashed-subcommands: scripts: use "git foo" not "git-foo"
2017-09-10Merge branch 'ab/ref-filter-no-contains' into maintLibravatar Junio C Hamano1-1/+1
A test fix. * ab/ref-filter-no-contains: tests: don't give unportable ">" to "test" built-in, use -gt
2017-09-10Merge branch 'rs/archive-excluded-directory' into maintLibravatar Junio C Hamano2-11/+85
"git archive" did not work well with pathspecs and the export-ignore attribute. We may want to resurrect the "we don't archive an empty directory" bonus patch, but I do not mind merging the above early to 'next' and leave it as a separate follow-up enhancement. cf. <20170820090629.tumvqwzkromcykjf@sigill.intra.peff.net> * rs/archive-excluded-directory: archive: don't queue excluded directories archive: factor out helper functions for handling attributes t5001: add tests for export-ignore attributes and exclude pathspecs
2017-09-10Merge branch 'mg/killed-merge' into maintLibravatar Junio C Hamano3-4/+31
Killing "git merge --edit" before the editor returns control left the repository in a state with MERGE_MSG but without MERGE_HEAD, which incorrectly tells the subsequent "git commit" that there was a squash merge in progress. This has been fixed. * mg/killed-merge: merge: save merge state earlier merge: split write_merge_state in two merge: clarify call chain Documentation/git-merge: explain --continue
2017-09-10Merge branch 'tb/apply-with-crlf' into maintLibravatar Junio C Hamano4-16/+71
"git apply" that is used as a better "patch -p1" failed to apply a taken from a file with CRLF line endings to a file with CRLF line endings. The root cause was because it misused convert_to_git() that tried to do "safe-crlf" processing by looking at the index entry at the same path, which is a nonsense---in that mode, "apply" is not working on the data in (or derived from) the index at all. This has been fixed. * tb/apply-with-crlf: apply: file commited with CRLF should roundtrip diff and apply convert: add SAFE_CRLF_KEEP_CRLF
2017-09-10Merge branch 'cc/subprocess-handshake-missing-capabilities' into maintLibravatar Junio C Hamano1-2/+2
When handshake with a subprocess filter notices that the process asked for an unknown capability, Git did not report what program the offending subprocess was running. This has been corrected. We may want a follow-up fix to tighten the error checking, though. * cc/subprocess-handshake-missing-capabilities: sub-process: print the cmd when a capability is unsupported
2017-09-10Merge branch 'as/grep-quiet-no-match-exit-code-fix' into maintLibravatar Junio C Hamano2-1/+6
"git grep -L" and "git grep --quiet -L" reported different exit codes; this has been corrected. * as/grep-quiet-no-match-exit-code-fix: git-grep: correct exit code with --quiet and -L
2017-09-10Merge branch 'kd/stash-with-bash-4.4' into maintLibravatar Junio C Hamano1-2/+9
bash 4.4 or newer gave a warning on NUL byte in command substitution done in "git stash"; this has been squelched. * kd/stash-with-bash-4.4: stash: prevent warning about null bytes in input
2017-09-10Merge branch 'rs/win32-syslog-leakfix' into maintLibravatar Junio C Hamano1-0/+2
Memory leak in an error codepath has been plugged. * rs/win32-syslog-leakfix: win32: plug memory leak on realloc() failure in syslog()
2017-09-10Merge branch 'rs/unpack-entry-leakfix' into maintLibravatar Junio C Hamano1-2/+3
Memory leak in an error codepath has been plugged. * rs/unpack-entry-leakfix: sha1_file: release delta_stack on error in unpack_entry()
2017-09-10Merge branch 'rs/fsck-obj-leakfix' into maintLibravatar Junio C Hamano1-11/+11
Memory leak in an error codepath has been plugged. * rs/fsck-obj-leakfix: fsck: free buffers on error in fsck_obj()
2017-09-10Merge branch 'ur/svn-local-zone' into maintLibravatar Junio C Hamano1-1/+1
"git svn" used with "--localtime" option did not compute the tz offset for the timestamp in question and instead always used the current time, which has been corrected. * ur/svn-local-zone: git svn fetch: Create correct commit timestamp when using --localtime
2017-09-10Merge branch 'pw/am-signoff' into maintLibravatar Junio C Hamano2-45/+64
"git am -s" has been taught that some input may end with a trailer block that is not Signed-off-by: and it should refrain from adding an extra blank line before adding a new sign-off in such a case. * pw/am-signoff: am: fix signoff when other trailers are present
2017-09-10Merge branch 'rs/in-obsd-basename-dirname-take-const' into maintLibravatar Junio C Hamano1-2/+16
Portability fix. * rs/in-obsd-basename-dirname-take-const: test-path-utils: handle const parameter of basename and dirname
2017-09-10Merge branch 'rs/t4062-obsd' into maintLibravatar Junio C Hamano1-1/+3
Test portability fix. * rs/t4062-obsd: t4062: use less than 256 repetitions in regex
2017-09-10Merge branch 'rs/obsd-getcwd-workaround' into maintLibravatar Junio C Hamano1-2/+28
Test portability fix for BSDs. * rs/obsd-getcwd-workaround: t0001: skip test with restrictive permissions if getpwd(3) respects them
2017-09-10Merge branch 'bw/clone-recursive-quiet' into maintLibravatar Junio C Hamano2-0/+9
"git clone --recurse-submodules --quiet" did not pass the quiet option down to submodules. * bw/clone-recursive-quiet: clone: teach recursive clones to respect -q
2017-09-10Merge branch 'pw/sequence-rerere-autoupdate' into maintLibravatar Junio C Hamano7-50/+171
Commands like "git rebase" accepted the --rerere-autoupdate option from the command line, but did not always use it. This has been fixed. * pw/sequence-rerere-autoupdate: cherry-pick/revert: reject --rerere-autoupdate when continuing cherry-pick/revert: remember --rerere-autoupdate t3504: use test_commit rebase -i: honor --rerere-autoupdate rebase: honor --rerere-autoupdate am: remember --rerere-autoupdate setting
2017-09-10Merge branch 'bw/push-options-recursively-to-submodules' into maintLibravatar Junio C Hamano3-13/+79
"git push --recurse-submodules $there HEAD:$target" was not propagated down to the submodules, but now it is. * bw/push-options-recursively-to-submodules: submodule--helper: teach push-check to handle HEAD
2017-09-10Merge branch 'ma/pager-per-subcommand-action' into maintLibravatar Junio C Hamano6-76/+201
The "tag.pager" configuration variable was useless for those who actually create tag objects, as it interfered with the use of an editor. A new mechanism has been introduced for commands to enable pager depending on what operation is being carried out to fix this, and then "git tag -l" is made to run pager by default. If this works out OK, I think there are low-hanging fruits in other commands like "git branch" that outputs long list in one mode while taking input in another. * ma/pager-per-subcommand-action: git.c: ignore pager.* when launching builtin as dashed external tag: change default of `pager.tag` to "on" tag: respect `pager.tag` in list-mode only t7006: add tests for how git tag paginates git.c: provide setup_auto_pager() git.c: let builtins opt for handling `pager.foo` themselves builtin.h: take over documentation from api-builtin.txt
2017-09-10Merge branch 'jk/rev-list-empty-input' into maintLibravatar Junio C Hamano5-13/+26
"git log --tag=no-such-tag" showed log starting from HEAD, which has been fixed---it now shows nothing. * jk/rev-list-empty-input: revision: do not fallback to default when rev_input_given is set rev-list: don't show usage when we see empty ref patterns revision: add rev_input_given flag t6018: flesh out empty input/output rev-list tests
2017-09-10Merge branch 'st/lib-gpg-kill-stray-agent' into maintLibravatar Junio C Hamano1-0/+1
Some versions of GnuPG fails to kill gpg-agent it auto-spawned and such a left-over agent can interfere with a test. Work it around by attempting to kill one before starting a new test. * st/lib-gpg-kill-stray-agent: t: lib-gpg: flush gpg agent on startup
2017-08-23Prepare for 2.14.2Libravatar Junio C Hamano3-2/+37
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-08-23Merge branch 'jt/t1450-fsck-corrupt-packfile' into maintLibravatar Junio C Hamano1-0/+16
A test update. * jt/t1450-fsck-corrupt-packfile: tests: ensure fsck fails on corrupt packfiles
2017-08-23Merge branch 'jb/t8008-cleanup' into maintLibravatar Junio C Hamano1-14/+16
Code clean-up. * jb/t8008-cleanup: t8008: rely on rev-parse'd HEAD instead of sha1 value
2017-08-23Merge branch 'jt/subprocess-handshake' into maintLibravatar Junio C Hamano14-285/+802
Code cleanup. * jt/subprocess-handshake: sub-process: refactor handshake to common function Documentation: migrate sub-process docs to header convert: add "status=delayed" to filter process protocol convert: refactor capabilities negotiation convert: move multiple file filter error handling to separate function convert: put the flags field before the flag itself for consistent style t0021: write "OUT <size>" only on success t0021: make debug log file name configurable t0021: keep filter log files on comparison