diff --git a/bisect.c b/bisect.c index 94c7028d2a746a..c2ef5da462f161 100644 --- a/bisect.c +++ b/bisect.c @@ -1019,10 +1019,12 @@ void read_bisect_terms(char **read_bad, char **read_good) die_errno(_("could not read file '%s'"), filename); } } else { - strbuf_getline_lf(&str, fp); + if (strbuf_getline_lf(&str, fp) == EOF) + die(_("could not read bad term from file '%s'"), filename); free(*read_bad); *read_bad = strbuf_detach(&str, NULL); - strbuf_getline_lf(&str, fp); + if (strbuf_getline_lf(&str, fp) == EOF) + die(_("could not read good term from file '%s'"), filename); free(*read_good); *read_good = strbuf_detach(&str, NULL); } diff --git a/builtin/bisect.c b/builtin/bisect.c index 798e28f5012d31..801daf8c78560c 100644 --- a/builtin/bisect.c +++ b/builtin/bisect.c @@ -498,9 +498,15 @@ static int get_terms(struct bisect_terms *terms) } free_terms(terms); - strbuf_getline_lf(&str, fp); + if (strbuf_getline_lf(&str, fp) == EOF) { + res = -1; + goto finish; + } terms->term_bad = strbuf_detach(&str, NULL); - strbuf_getline_lf(&str, fp); + if (strbuf_getline_lf(&str, fp) == EOF) { + res = -1; + goto finish; + } terms->term_good = strbuf_detach(&str, NULL); finish: @@ -1051,6 +1057,8 @@ static int process_replay_line(struct bisect_terms *terms, struct strbuf *line) *word_end = '\0'; /* NUL-terminate the word */ get_terms(terms); + if (!terms->term_bad || !terms->term_good) + return error(_("no terms defined")); if (check_and_set_terms(terms, p)) return -1; @@ -1300,6 +1308,11 @@ static int bisect_run(struct bisect_terms *terms, int argc, const char **argv) fflush(stdout); saved_stdout = dup(1); + if (saved_stdout < 0) { + res = error_errno(_("could not duplicate stdout")); + close(temporary_stdout_fd); + break; + } dup2(temporary_stdout_fd, 1); res = bisect_state(terms, 1, &new_state); @@ -1377,6 +1390,8 @@ static int cmd_bisect__next(int argc, const char **argv UNUSED, const char *pref return error(_("'%s' requires 0 arguments"), "git bisect next"); get_terms(&terms); + if (!terms.term_bad || !terms.term_good) + return error(_("no terms defined")); res = bisect_next(&terms, prefix); free_terms(&terms); return res; @@ -1411,6 +1426,8 @@ static int cmd_bisect__skip(int argc, const char **argv, const char *prefix UNUS set_terms(&terms, "bad", "good"); get_terms(&terms); + if (!terms.term_bad || !terms.term_good) + return error(_("no terms defined")); res = bisect_skip(&terms, argc, argv); free_terms(&terms); return res; @@ -1423,6 +1440,8 @@ static int cmd_bisect__visualize(int argc, const char **argv, const char *prefix struct bisect_terms terms = { 0 }; get_terms(&terms); + if (!terms.term_bad || !terms.term_good) + return error(_("no terms defined")); res = bisect_visualize(&terms, argc, argv); free_terms(&terms); return res; @@ -1437,6 +1456,8 @@ static int cmd_bisect__run(int argc, const char **argv, const char *prefix UNUSE if (!argc) return error(_("'%s' failed: no command provided."), "git bisect run"); get_terms(&terms); + if (!terms.term_bad || !terms.term_good) + return error(_("no terms defined")); res = bisect_run(&terms, argc, argv); free_terms(&terms); return res; @@ -1476,6 +1497,8 @@ int cmd_bisect(int argc, set_terms(&terms, "bad", "good"); get_terms(&terms); + if (!terms.term_bad || !terms.term_good) + return error(_("no terms defined")); if (check_and_set_terms(&terms, argv[0]) || !one_of(argv[0], terms.term_good, terms.term_bad, NULL)) usage_msg_optf(_("unknown command: '%s'"), git_bisect_usage, diff --git a/builtin/config.c b/builtin/config.c index 8d8ec0beead220..1307fdb0d61afa 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -1313,7 +1313,10 @@ static int show_editor(struct config_location_options *opts) else if (errno != EEXIST) die_errno(_("cannot create configuration file %s"), config_file); } - launch_editor(config_file, NULL, NULL); + if (launch_editor(config_file, NULL, NULL)) { + free(config_file); + return -1; + } free(config_file); return 0; diff --git a/builtin/last-modified.c b/builtin/last-modified.c index 5478182f2e95c2..fe012b0c2ecb32 100644 --- a/builtin/last-modified.c +++ b/builtin/last-modified.c @@ -290,7 +290,8 @@ static void process_parent(struct last_modified *lm, { struct bitmap *active_p; - repo_parse_commit(lm->rev.repo, parent); + if (repo_parse_commit(lm->rev.repo, parent)) + return; active_p = active_paths_for(lm, parent); /* @@ -414,12 +415,14 @@ static int last_modified_run(struct last_modified *lm) * Otherwise, make sure that 'c' isn't reachable from anything * in the '--not' queue. */ - repo_parse_commit(lm->rev.repo, c); + if (repo_parse_commit(lm->rev.repo, c)) + continue; while ((n = prio_queue_get(¬_queue))) { struct commit_list *np; - repo_parse_commit(lm->rev.repo, n); + if (repo_parse_commit(lm->rev.repo, n)) + continue; for (np = n->parents; np; np = np->next) { if (!(np->item->object.flags & PARENT2)) { diff --git a/compat/pread.c b/compat/pread.c index 484e6d4c716ef6..ac7d058cb895db 100644 --- a/compat/pread.c +++ b/compat/pread.c @@ -7,6 +7,8 @@ ssize_t git_pread(int fd, void *buf, size_t count, off_t offset) ssize_t rc; current_offset = lseek(fd, 0, SEEK_CUR); + if (current_offset < 0) + return -1; if (lseek(fd, offset, SEEK_SET) < 0) return -1; diff --git a/http.c b/http.c index b4e7b8d00b3cdc..8f1d6d1f56eb38 100644 --- a/http.c +++ b/http.c @@ -1608,6 +1608,8 @@ struct active_request_slot *get_active_slot(void) if (!slot->curl) { slot->curl = curl_easy_duphandle(curl_default); + if (!slot->curl) + die("curl_easy_duphandle failed"); curl_session_count++; } diff --git a/reftable/block.c b/reftable/block.c index 920b3f448674f1..ec81fd04938336 100644 --- a/reftable/block.c +++ b/reftable/block.c @@ -87,7 +87,8 @@ int block_writer_init(struct block_writer *bw, uint8_t typ, uint8_t *block, REFTABLE_CALLOC_ARRAY(bw->zstream, 1); if (!bw->zstream) return REFTABLE_OUT_OF_MEMORY_ERROR; - deflateInit(bw->zstream, 9); + if (deflateInit(bw->zstream, 9) != Z_OK) + return REFTABLE_ZLIB_ERROR; } return 0; diff --git a/t/unit-tests/u-reftable-table.c b/t/unit-tests/u-reftable-table.c index fae478ee044c48..6f444f8cf94fb0 100644 --- a/t/unit-tests/u-reftable-table.c +++ b/t/unit-tests/u-reftable-table.c @@ -29,7 +29,8 @@ void test_reftable_table__seek_once(void) ret = reftable_table_new(&table, &source, "name"); cl_assert(!ret); - reftable_table_init_ref_iterator(table, &it); + ret = reftable_table_init_ref_iterator(table, &it); + cl_assert_equal_i(ret, 0); ret = reftable_iterator_seek_ref(&it, ""); cl_assert(!ret); ret = reftable_iterator_next_ref(&it, &ref); @@ -71,7 +72,8 @@ void test_reftable_table__reseek(void) ret = reftable_table_new(&table, &source, "name"); cl_assert(!ret); - reftable_table_init_ref_iterator(table, &it); + ret = reftable_table_init_ref_iterator(table, &it); + cl_assert_equal_i(ret, 0); for (size_t i = 0; i < 5; i++) { ret = reftable_iterator_seek_ref(&it, ""); diff --git a/transport-helper.c b/transport-helper.c index 80f90eb7bace6f..ed0543f1ad84c4 100644 --- a/transport-helper.c +++ b/transport-helper.c @@ -487,6 +487,8 @@ static int get_exporter(struct transport *transport, /* we need to duplicate helper->in because we want to use it after * fastexport is done with it. */ fastexport->out = dup(helper->in); + if (fastexport->out < 0) + return error_errno(_("could not dup helper output fd")); strvec_push(&fastexport->args, "fast-export"); strvec_push(&fastexport->args, "--use-done-feature"); strvec_push(&fastexport->args, data->signed_tags ? @@ -1182,7 +1184,9 @@ static int push_refs_with_export(struct transport *transport, if (data->export_marks) { strbuf_addf(&buf, "%s.tmp", data->export_marks); - rename(buf.buf, data->export_marks); + if (rename(buf.buf, data->export_marks)) + warning_errno(_("could not rename '%s' to '%s'"), + buf.buf, data->export_marks); strbuf_release(&buf); }