The following issues were found
gettext.c
12 issues
Line: 69
Column: 24
CWE codes:
134
Suggestion:
Use a constant for the format specification
}
#ifndef NO_GETTEXT
__attribute__((format (printf, 1, 2)))
static int test_vsnprintf(const char *fmt, ...)
{
char buf[26];
int ret;
va_list ap;
Reported by FlawFinder.
Line: 76
Column: 8
CWE codes:
134
Suggestion:
Use a constant for the format specification
int ret;
va_list ap;
va_start(ap, fmt);
ret = vsnprintf(buf, sizeof(buf), fmt, ap);
va_end(ap);
return ret;
}
static void init_gettext_charset(const char *domain)
Reported by FlawFinder.
Line: 19
Column: 20
CWE codes:
807
20
Suggestion:
Check environment variables carefully before using them
static const char *locale_charset(void)
{
const char *env = getenv("LC_ALL"), *dot;
if (!env || !*env)
env = getenv("LC_CTYPE");
if (!env || !*env)
env = getenv("LANG");
Reported by FlawFinder.
Line: 22
Column: 9
CWE codes:
807
20
Suggestion:
Check environment variables carefully before using them
const char *env = getenv("LC_ALL"), *dot;
if (!env || !*env)
env = getenv("LC_CTYPE");
if (!env || !*env)
env = getenv("LANG");
if (!env)
return "UTF-8";
Reported by FlawFinder.
Line: 24
Column: 9
CWE codes:
807
20
Suggestion:
Check environment variables carefully before using them
if (!env || !*env)
env = getenv("LC_CTYPE");
if (!env || !*env)
env = getenv("LANG");
if (!env)
return "UTF-8";
dot = strchr(env, '.');
Reported by FlawFinder.
Line: 53
Column: 11
CWE codes:
807
20
Suggestion:
Check environment variables carefully before using them
{
const char *retval;
retval = getenv("LANGUAGE");
if (retval && *retval)
return retval;
#ifndef NO_GETTEXT
retval = setlocale(LC_MESSAGES, NULL);
Reported by FlawFinder.
Line: 107
Column: 22
CWE codes:
807
20
Suggestion:
Check environment variables carefully before using them
void git_setup_gettext(void)
{
const char *podir = getenv(GIT_TEXT_DOMAIN_DIR_ENVIRONMENT);
char *p = NULL;
if (!podir)
podir = p = system_path(GIT_LOCALE_PATH);
Reported by FlawFinder.
Line: 142
Column: 21
CWE codes:
807
20
Suggestion:
Check environment variables carefully before using them
{
#ifdef NO_GETTEXT
if (!charset) {
const char *env = getenv("LC_ALL");
if (!env || !*env)
env = getenv("LC_CTYPE");
if (!env || !*env)
env = getenv("LANG");
if (!env)
Reported by FlawFinder.
Line: 144
Column: 10
CWE codes:
807
20
Suggestion:
Check environment variables carefully before using them
if (!charset) {
const char *env = getenv("LC_ALL");
if (!env || !*env)
env = getenv("LC_CTYPE");
if (!env || !*env)
env = getenv("LANG");
if (!env)
env = "";
if (strchr(env, '.'))
Reported by FlawFinder.
Line: 146
Column: 10
CWE codes:
807
20
Suggestion:
Check environment variables carefully before using them
if (!env || !*env)
env = getenv("LC_CTYPE");
if (!env || !*env)
env = getenv("LANG");
if (!env)
env = "";
if (strchr(env, '.'))
env = strchr(env, '.') + 1;
charset = xstrdup(env);
Reported by FlawFinder.
streaming.c
12 issues
Line: 23
Column: 2
CWE codes:
119
120
Suggestion:
Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length
struct filtered_istream {
struct git_istream *upstream;
struct stream_filter *filter;
char ibuf[FILTER_BUFFER];
char obuf[FILTER_BUFFER];
int i_end, i_ptr;
int o_end, o_ptr;
int input_finished;
};
Reported by FlawFinder.
Line: 24
Column: 2
CWE codes:
119
120
Suggestion:
Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length
struct git_istream *upstream;
struct stream_filter *filter;
char ibuf[FILTER_BUFFER];
char obuf[FILTER_BUFFER];
int i_end, i_ptr;
int o_end, o_ptr;
int input_finished;
};
Reported by FlawFinder.
Line: 31
Column: 18
CWE codes:
362
};
struct git_istream {
open_istream_fn open;
close_istream_fn close;
read_istream_fn read;
unsigned long size; /* inflated size of full object */
git_zstream z;
Reported by FlawFinder.
Line: 48
Column: 4
CWE codes:
119
120
Suggestion:
Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length
struct {
void *mapped;
unsigned long mapsize;
char hdr[32];
int hdr_avail;
int hdr_used;
} loose;
struct {
Reported by FlawFinder.
Line: 99
Column: 4
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
size_t to_move = fs->o_end - fs->o_ptr;
if (sz < to_move)
to_move = sz;
memcpy(buf + filled, fs->obuf + fs->o_ptr, to_move);
fs->o_ptr += to_move;
sz -= to_move;
filled += to_move;
continue;
}
Reported by FlawFinder.
Line: 187
Column: 3
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
size_t to_copy = st->u.loose.hdr_avail - st->u.loose.hdr_used;
if (sz < to_copy)
to_copy = sz;
memcpy(buf, st->u.loose.hdr + st->u.loose.hdr_used, to_copy);
st->u.loose.hdr_used += to_copy;
total_read += to_copy;
}
while (total_read < sz) {
Reported by FlawFinder.
Line: 373
Column: 3
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
if (remainder <= read_size)
read_size = remainder;
if (read_size) {
memcpy(buf, st->u.incore.buf + st->u.incore.read_ptr, read_size);
st->u.incore.read_ptr += read_size;
}
return read_size;
}
Reported by FlawFinder.
Line: 458
Column: 10
CWE codes:
362
return NULL;
}
if (st->open(st, r, real, type)) {
if (open_istream_incore(st, r, real, type)) {
free(st);
return NULL;
}
}
Reported by FlawFinder.
Line: 496
Column: 3
CWE codes:
119
120
Suggestion:
Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length
if (type != OBJ_BLOB)
goto close_and_exit;
for (;;) {
char buf[1024 * 16];
ssize_t wrote, holeto;
ssize_t readlen = read_istream(st, buf, sizeof(buf));
if (readlen < 0)
goto close_and_exit;
Reported by FlawFinder.
Line: 33
Column: 18
CWE codes:
120
20
struct git_istream {
open_istream_fn open;
close_istream_fn close;
read_istream_fn read;
unsigned long size; /* inflated size of full object */
git_zstream z;
enum { z_unused, z_used, z_done, z_error } z_state;
Reported by FlawFinder.
builtin/ls-files.c
11 issues
Line: 89
Column: 9
CWE codes:
119
120
Suggestion:
Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length
static const char *get_tag(const struct cache_entry *ce, const char *tag)
{
static char alttag[4];
if (tag && *tag && ((show_valid_bit && (ce->ce_flags & CE_VALID)) ||
(show_fsmonitor_bit && (ce->ce_flags & CE_FSMONITOR_VALID)))) {
memcpy(alttag, tag, 3);
Reported by FlawFinder.
Line: 93
Column: 3
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
if (tag && *tag && ((show_valid_bit && (ce->ce_flags & CE_VALID)) ||
(show_fsmonitor_bit && (ce->ce_flags & CE_FSMONITOR_VALID)))) {
memcpy(alttag, tag, 3);
if (isalpha(tag[0])) {
alttag[0] = tolower(tag[0]);
} else if (tag[0] == '?') {
alttag[0] = '!';
Reported by FlawFinder.
Line: 444
Column: 2
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
ce->ce_mode = create_ce_mode(mode);
ce->ce_flags = create_ce_flags(1);
ce->ce_namelen = base->len + len;
memcpy(ce->name, base->buf, base->len);
memcpy(ce->name + base->len, pathname, len+1);
oidcpy(&ce->oid, oid);
return add_index_entry(istate, ce, opt);
}
Reported by FlawFinder.
Line: 445
Column: 2
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
ce->ce_flags = create_ce_flags(1);
ce->ce_namelen = base->len + len;
memcpy(ce->name, base->buf, base->len);
memcpy(ce->name + base->len, pathname, len+1);
oidcpy(&ce->oid, oid);
return add_index_entry(istate, ce, opt);
}
static int read_one_entry(const struct object_id *oid, struct strbuf *base,
Reported by FlawFinder.
Line: 509
Column: 16
CWE codes:
119
120
Suggestion:
Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length
}
if (prefix) {
static const char *(matchbuf[1]);
matchbuf[0] = NULL;
parse_pathspec(&pathspec, PATHSPEC_ALL_MAGIC,
PATHSPEC_PREFER_CWD, prefix, matchbuf);
} else
memset(&pathspec, 0, sizeof(pathspec));
Reported by FlawFinder.
Line: 230
Column: 23
CWE codes:
126
const struct cache_entry *ce, const char *fullname,
const char *tag)
{
if (max_prefix_len > strlen(fullname))
die("git ls-files: internal error - cache entry not superset of prefix");
if (recurse_submodules && S_ISGITLINK(ce->ce_mode) &&
is_submodule_active(repo, ce->name)) {
show_submodule(repo, dir, ce->name);
Reported by FlawFinder.
Line: 236
Column: 62
CWE codes:
126
if (recurse_submodules && S_ISGITLINK(ce->ce_mode) &&
is_submodule_active(repo, ce->name)) {
show_submodule(repo, dir, ce->name);
} else if (match_pathspec(repo->index, &pathspec, fullname, strlen(fullname),
max_prefix_len, ps_matched,
S_ISDIR(ce->ce_mode) ||
S_ISGITLINK(ce->ce_mode))) {
tag = get_tag(ce, tag);
Reported by FlawFinder.
Line: 269
Column: 9
CWE codes:
126
struct resolve_undo_info *ui = item->util;
int i, len;
len = strlen(path);
if (len < max_prefix_len)
continue; /* outside of the prefix */
if (!match_pathspec(istate, &pathspec, path, len,
max_prefix_len, ps_matched, 0))
continue; /* uninterested */
Reported by FlawFinder.
Line: 414
Column: 22
CWE codes:
126
if (!common_prefix)
return 0;
common_prefix_len = strlen(common_prefix);
/*
* If the prefix has a trailing slash, strip it so that submodules wont
* be pruned from the index.
*/
Reported by FlawFinder.
Line: 438
Column: 8
CWE codes:
126
if (S_ISDIR(mode))
return READ_TREE_RECURSIVE;
len = strlen(pathname);
ce = make_empty_cache_entry(istate, base->len + len);
ce->ce_mode = create_ce_mode(mode);
ce->ce_flags = create_ce_flags(1);
ce->ce_namelen = base->len + len;
Reported by FlawFinder.
builtin/log.c
11 issues
Line: 981
Column: 27
CWE codes:
362
if (!quiet)
printf("%s\n", filename.buf + outdir_offset);
if ((rev->diffopt.file = fopen(filename.buf, "w")) == NULL) {
error_errno(_("cannot open patch file %s"), filename.buf);
strbuf_release(&filename);
return -1;
}
Reported by FlawFinder.
Line: 1841
Column: 2
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
git_config(git_format_config, NULL);
repo_init_revisions(the_repository, &rev, prefix);
rev.show_notes = show_notes;
memcpy(&rev.notes_opt, ¬es_opt, sizeof(notes_opt));
rev.commit_format = CMIT_FMT_EMAIL;
rev.encode_email_headers = default_encode_email_headers;
rev.expand_tabs_in_log_default = 0;
rev.verbose_header = 1;
rev.diff = 1;
Reported by FlawFinder.
Line: 778
Column: 12
CWE codes:
126
static void add_header(const char *value)
{
struct string_list_item *item;
int len = strlen(value);
while (len && value[len - 1] == '\n')
len--;
if (!strncasecmp(value, "to: ", 4)) {
item = string_list_append(&extra_to, value + 4);
Reported by FlawFinder.
Line: 1049
Column: 16
CWE codes:
126
return;
fprintf(file, "-- \n%s", signature);
if (signature[strlen(signature)-1] != '\n')
putc('\n', file);
putc('\n', file);
}
static char *find_branch_name(struct rev_info *rev)
Reported by FlawFinder.
Line: 1074
Column: 20
CWE codes:
126
return NULL;
ref = rev->cmdline.rev[positive].name;
tip_oid = &rev->cmdline.rev[positive].item->oid;
if (dwim_ref(ref, strlen(ref), &branch_oid, &full_ref, 0) &&
skip_prefix(full_ref, "refs/heads/", &v) &&
oideq(tip_oid, &branch_oid))
branch = xstrdup(v);
free(full_ref);
return branch;
Reported by FlawFinder.
Line: 1285
Column: 18
CWE codes:
126
return "./";
}
outdir_offset = strlen(prefix);
if (!output_directory)
return prefix;
return prefix_filename(prefix, output_directory);
}
Reported by FlawFinder.
Line: 1870
Column: 46
CWE codes:
126
PARSE_OPT_KEEP_DASHDASH);
/* Make sure "0000-$sub.patch" gives non-negative length for $sub */
if (fmt_patch_name_max <= strlen("0000-") + strlen(fmt_patch_suffix))
fmt_patch_name_max = strlen("0000-") + strlen(fmt_patch_suffix);
if (cover_from_description_arg)
cover_from_description_mode = parse_cover_from_description(cover_from_description_arg);
Reported by FlawFinder.
Line: 1870
Column: 28
CWE codes:
126
PARSE_OPT_KEEP_DASHDASH);
/* Make sure "0000-$sub.patch" gives non-negative length for $sub */
if (fmt_patch_name_max <= strlen("0000-") + strlen(fmt_patch_suffix))
fmt_patch_name_max = strlen("0000-") + strlen(fmt_patch_suffix);
if (cover_from_description_arg)
cover_from_description_mode = parse_cover_from_description(cover_from_description_arg);
Reported by FlawFinder.
Line: 1871
Column: 24
CWE codes:
126
/* Make sure "0000-$sub.patch" gives non-negative length for $sub */
if (fmt_patch_name_max <= strlen("0000-") + strlen(fmt_patch_suffix))
fmt_patch_name_max = strlen("0000-") + strlen(fmt_patch_suffix);
if (cover_from_description_arg)
cover_from_description_mode = parse_cover_from_description(cover_from_description_arg);
if (reroll_count) {
Reported by FlawFinder.
Line: 1871
Column: 42
CWE codes:
126
/* Make sure "0000-$sub.patch" gives non-negative length for $sub */
if (fmt_patch_name_max <= strlen("0000-") + strlen(fmt_patch_suffix))
fmt_patch_name_max = strlen("0000-") + strlen(fmt_patch_suffix);
if (cover_from_description_arg)
cover_from_description_mode = parse_cover_from_description(cover_from_description_arg);
if (reroll_count) {
Reported by FlawFinder.
builtin/bisect--helper.c
11 issues
Line: 525
CWE codes:
775
git_path_bisect_log());
if (fprintf(fp, "# only skipped commits left to test\n") < 0)
return error_errno(_("failed to write to '%s'"), git_path_bisect_log());
while ((commit = get_revision(&revs)) != NULL) {
strbuf_reset(&commit_name);
format_commit_message(commit, "%s",
&commit_name, &pp);
Reported by Cppcheck.
Line: 108
Column: 8
CWE codes:
134
Suggestion:
Use a constant for the format specification
fp = fopen(path, mode);
if (!fp)
return error_errno(_("cannot open file '%s' in mode '%s'"), path, mode);
res = vfprintf(fp, format, args);
if (res < 0) {
int saved_errno = errno;
fclose(fp);
errno = saved_errno;
Reported by FlawFinder.
Line: 120
Column: 24
CWE codes:
134
Suggestion:
Use a constant for the format specification
return fclose(fp);
}
__attribute__((format (printf, 2, 3)))
static int write_to_file(const char *path, const char *format, ...)
{
int res;
va_list args;
Reported by FlawFinder.
Line: 133
Column: 24
CWE codes:
134
Suggestion:
Use a constant for the format specification
return res;
}
__attribute__((format (printf, 2, 3)))
static int append_to_file(const char *path, const char *format, ...)
{
int res;
va_list args;
Reported by FlawFinder.
Line: 105
Column: 7
CWE codes:
362
if (strcmp(mode, "w") && strcmp(mode, "a"))
BUG("write-in-file does not support '%s' mode", mode);
fp = fopen(path, mode);
if (!fp)
return error_errno(_("cannot open file '%s' in mode '%s'"), path, mode);
res = vfprintf(fp, format, args);
if (res < 0) {
Reported by FlawFinder.
Line: 271
Column: 7
CWE codes:
362
goto finish;
}
fp = fopen(git_path_bisect_log(), "a");
if (!fp) {
res = error_errno(_("couldn't open the file '%s'"), git_path_bisect_log());
goto finish;
}
Reported by FlawFinder.
Line: 397
Column: 7
CWE codes:
362
FILE *fp = NULL;
int res = 0;
fp = fopen(git_path_bisect_terms(), "r");
if (!fp) {
res = -1;
goto finish;
}
Reported by FlawFinder.
Line: 443
Column: 13
CWE codes:
362
static int bisect_append_log_quoted(const char **argv)
{
int res = 0;
FILE *fp = fopen(git_path_bisect_log(), "a");
struct strbuf orig_args = STRBUF_INIT;
if (!fp)
return -1;
Reported by FlawFinder.
Line: 519
Column: 7
CWE codes:
362
if (res)
return res;
fp = fopen(git_path_bisect_log(), "a");
if (!fp)
return error_errno(_("could not open '%s' for appending"),
git_path_bisect_log());
if (fprintf(fp, "# only skipped commits left to test\n") < 0)
Reported by FlawFinder.
Line: 923
Column: 7
CWE codes:
362
if (is_empty_or_missing_file(filename))
return error(_("We are not bisecting."));
fd = open(filename, O_RDONLY);
if (fd < 0)
return BISECT_FAILED;
status = copy_fd(fd, STDOUT_FILENO);
close(fd);
Reported by FlawFinder.
builtin/am.c
11 issues
Line: 213
Column: 24
CWE codes:
134
Suggestion:
Use a constant for the format specification
* If state->quiet is false, calls fprintf(fp, fmt, ...), and appends a newline
* at the end.
*/
__attribute__((format (printf, 3, 4)))
static void say(const struct am_state *state, FILE *fp, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
Reported by FlawFinder.
Line: 220
Column: 3
CWE codes:
134
Suggestion:
Use a constant for the format specification
va_start(ap, fmt);
if (!state->quiet) {
vfprintf(fp, fmt, ap);
putc('\n', fp);
}
va_end(ap);
}
Reported by FlawFinder.
Line: 1632
Column: 25
CWE codes:
807
20
Suggestion:
Check environment variables carefully before using them
IDENT_STRICT);
if (state->committer_date_is_author_date)
committer = fmt_ident(getenv("GIT_COMMITTER_NAME"),
getenv("GIT_COMMITTER_EMAIL"),
WANT_COMMITTER_IDENT,
state->ignore_date ? NULL
: state->author_date,
IDENT_STRICT);
Reported by FlawFinder.
Line: 1633
Column: 11
CWE codes:
807
20
Suggestion:
Check environment variables carefully before using them
if (state->committer_date_is_author_date)
committer = fmt_ident(getenv("GIT_COMMITTER_NAME"),
getenv("GIT_COMMITTER_EMAIL"),
WANT_COMMITTER_IDENT,
state->ignore_date ? NULL
: state->author_date,
IDENT_STRICT);
Reported by FlawFinder.
Line: 1644
Column: 15
CWE codes:
807
20
Suggestion:
Check environment variables carefully before using them
NULL))
die(_("failed to write commit object"));
reflog_msg = getenv("GIT_REFLOG_ACTION");
if (!reflog_msg)
reflog_msg = "am";
strbuf_addf(&sb, "%s: %.*s", reflog_msg, linelen(state->msg),
state->msg);
Reported by FlawFinder.
Line: 726
Column: 9
CWE codes:
362
if (!strcmp(*paths, "-"))
in = stdin;
else
in = fopen(*paths, "r");
if (!in)
return error_errno(_("could not open '%s' for reading"),
*paths);
Reported by FlawFinder.
Line: 734
Column: 9
CWE codes:
362
mail = mkpath("%s/%0*d", state->dir, state->prec, i + 1);
out = fopen(mail, "w");
if (!out) {
if (in != stdin)
fclose(in);
return error_errno(_("could not open '%s' for writing"),
mail);
Reported by FlawFinder.
Line: 819
Column: 7
CWE codes:
362
series_dir_buf = xstrdup(*paths);
series_dir = dirname(series_dir_buf);
fp = fopen(*paths, "r");
if (!fp)
return error_errno(_("could not open '%s' for reading"), *paths);
while (!strbuf_getline_lf(&sb, fp)) {
if (*sb.buf == '#')
Reported by FlawFinder.
Line: 1695
Column: 3
CWE codes:
119
120
Suggestion:
Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length
assert(state->msg);
for (;;) {
char reply[64];
puts(_("Commit Body is:"));
puts("--------------------------");
printf("%s", state->msg);
puts("--------------------------");
Reported by FlawFinder.
Line: 2129
Column: 9
CWE codes:
119
120
Suggestion:
Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length
int len;
if (!is_null_oid(&state->orig_commit)) {
const char *av[4] = { "show", NULL, "--", NULL };
char *new_oid_str;
int ret;
av[1] = new_oid_str = xstrdup(oid_to_hex(&state->orig_commit));
ret = run_command_v_opt(av, RUN_GIT_CMD);
Reported by FlawFinder.
builtin/clone.c
11 issues
Line: 955
Column: 7
CWE codes:
362/367!
Suggestion:
Set up the correct permissions (e.g., using setuid()) and try to open the file directly
static const char* argv[] = { "repack", "-a", "-d", NULL };
char *alternates = git_pathdup("objects/info/alternates");
if (!access(alternates, F_OK)) {
if (run_command_v_opt(argv, RUN_GIT_CMD|RUN_COMMAND_NO_STDIN))
die(_("cannot repack to clean up"));
if (unlink(alternates) && errno != ENOENT)
die_errno(_("cannot unlink temporary alternates file"));
}
Reported by FlawFinder.
Line: 1236
Column: 8
CWE codes:
362/367!
Suggestion:
Set up the correct permissions (e.g., using setuid()) and try to open the file directly
warning(_("--shallow-exclude is ignored in local clones; use file:// instead."));
if (filter_options.choice)
warning(_("--filter is ignored in local clones; use file:// instead."));
if (!access(mkpath("%s/shallow", path), F_OK)) {
if (reject_shallow)
die(_("source repository is shallow, reject to clone."));
if (option_local > 0)
warning(_("source repository is shallow, ignoring --local"));
is_local = 0;
Reported by FlawFinder.
Line: 463
Column: 21
CWE codes:
120/785!
Suggestion:
Ensure that the destination buffer is at least of size MAXPATHLEN, andto protect against implementation problems, the input argument should also be checked to ensure it is no larger than MAXPATHLEN
if (unlink(dest->buf) && errno != ENOENT)
die_errno(_("failed to unlink '%s'"), dest->buf);
if (!option_no_hardlinks) {
strbuf_realpath(&realpath, src->buf, 1);
if (!link(realpath.buf, dest->buf))
continue;
if (option_local > 0)
die_errno(_("failed to create link '%s'"), dest->buf);
option_no_hardlinks = 1;
Reported by FlawFinder.
Line: 464
Column: 14
CWE codes:
120/785!
Suggestion:
Ensure that the destination buffer is at least of size MAXPATHLEN, andto protect against implementation problems, the input argument should also be checked to ensure it is no larger than MAXPATHLEN
die_errno(_("failed to unlink '%s'"), dest->buf);
if (!option_no_hardlinks) {
strbuf_realpath(&realpath, src->buf, 1);
if (!link(realpath.buf, dest->buf))
continue;
if (option_local > 0)
die_errno(_("failed to create link '%s'"), dest->buf);
option_no_hardlinks = 1;
}
Reported by FlawFinder.
Line: 479
Column: 18
CWE codes:
120/785!
Suggestion:
Ensure that the destination buffer is at least of size MAXPATHLEN, andto protect against implementation problems, the input argument should also be checked to ensure it is no larger than MAXPATHLEN
die(_("failed to iterate over '%s'"), src->buf);
}
strbuf_release(&realpath);
}
static void clone_local(const char *src_repo, const char *dest_repo)
{
if (option_shared) {
Reported by FlawFinder.
Line: 1067
Column: 15
CWE codes:
807
20
Suggestion:
Check environment variables carefully before using them
if (option_bare)
work_tree = NULL;
else {
work_tree = getenv("GIT_WORK_TREE");
if (work_tree && path_exists(work_tree))
die(_("working tree '%s' already exists."), work_tree);
}
if (option_bare || work_tree)
Reported by FlawFinder.
Line: 178
Column: 4
CWE codes:
119
120
Suggestion:
Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length
return path->buf;
} else if (S_ISREG(st.st_mode) && st.st_size > 8) {
/* Is it a "gitfile"? */
char signature[8];
const char *dst;
int len, fd = open(path->buf, O_RDONLY);
if (fd < 0)
continue;
len = read_in_full(fd, signature, 8);
Reported by FlawFinder.
Line: 180
Column: 18
CWE codes:
362
/* Is it a "gitfile"? */
char signature[8];
const char *dst;
int len, fd = open(path->buf, O_RDONLY);
if (fd < 0)
continue;
len = read_in_full(fd, signature, 8);
close(fd);
if (len != 8 || strncmp(signature, "gitdir: ", 8))
Reported by FlawFinder.
Line: 1038
Column: 22
CWE codes:
190
Suggestion:
If source untrusted, check both minimum and maximum, even if the input had no minus sign (large numbers can roll over into negative number; consider saving to an unsigned value if that is intended)
die(_("repository '%s' does not exist"), repo_name);
/* no need to be strict, transport_set_option() will validate it again */
if (option_depth && atoi(option_depth) < 1)
die(_("depth %s is not a positive number"), option_depth);
if (argc == 2)
dir = xstrdup(argv[1]);
else
Reported by FlawFinder.
Line: 222
Column: 27
CWE codes:
126
static char *guess_dir_name(const char *repo, int is_bundle, int is_bare)
{
const char *end = repo + strlen(repo), *start, *ptr;
size_t len;
char *dir;
/*
* Skip scheme.
Reported by FlawFinder.
rerere.c
11 issues
Line: 32
Column: 2
CWE codes:
119
120
Suggestion:
Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length
struct rerere_dir {
int status_alloc, status_nr;
unsigned char *status;
char name[FLEX_ARRAY];
};
static struct strmap rerere_dirs = STRMAP_INIT;
static void free_rerere_dirs(void)
Reported by FlawFinder.
Line: 194
Column: 12
CWE codes:
119
120
Suggestion:
Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length
return;
while (!strbuf_getwholeline(&buf, in, '\0')) {
char *path;
unsigned char hash[GIT_MAX_RAWSZ];
struct rerere_id *id;
int variant;
const unsigned hexsz = the_hash_algo->hexsz;
/* There has to be the hash, tab, path and then NUL */
Reported by FlawFinder.
Line: 461
Column: 13
CWE codes:
362
memset(&io, 0, sizeof(io));
io.io.getline = rerere_file_getline;
io.input = fopen(path, "r");
io.io.wrerror = 0;
if (!io.input)
return error_errno(_("could not open '%s'"), path);
if (output) {
Reported by FlawFinder.
Line: 467
Column: 18
CWE codes:
362
return error_errno(_("could not open '%s'"), path);
if (output) {
io.io.output = fopen(output, "w");
if (!io.io.output) {
error_errno(_("could not write '%s'"), output);
fclose(io.input);
return -1;
}
Reported by FlawFinder.
Line: 672
Column: 6
CWE codes:
362
rerere_path(id, "postimage"));
/* Update "path" with the resolution */
f = fopen(path, "w");
if (!f)
return error_errno(_("could not open '%s'"), path);
if (fwrite(result.ptr, result.size, 1, f) != 1)
error_errno(_("could not write '%s'"), path);
if (fclose(f))
Reported by FlawFinder.
Line: 811
Column: 12
CWE codes:
119
120
Suggestion:
Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length
*/
for (i = 0; i < conflict.nr; i++) {
struct rerere_id *id;
unsigned char hash[GIT_MAX_RAWSZ];
const char *path = conflict.items[i].string;
int ret;
/*
* Ask handle_file() to scan and assign a
Reported by FlawFinder.
Line: 990
Column: 18
CWE codes:
362
memset(&io, 0, sizeof(io));
io.io.getline = rerere_mem_getline;
if (output)
io.io.output = fopen(output, "w");
else
io.io.output = NULL;
strbuf_init(&io.input, 0);
strbuf_attach(&io.input, result.ptr, result.size, result.size);
Reported by FlawFinder.
Line: 1013
Column: 11
CWE codes:
119
120
Suggestion:
Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length
{
const char *filename;
struct rerere_id *id;
unsigned char hash[GIT_MAX_RAWSZ];
int ret;
struct string_list_item *item;
/*
* Recreate the original conflict from the stages in the
Reported by FlawFinder.
Line: 282
Column: 16
CWE codes:
126
static inline void ferr_puts(const char *s, FILE *fp, int *err)
{
ferr_write(s, strlen(s), fp, err);
}
static void rerere_io_putstr(const char *str, struct rerere_io *io)
{
if (io->output)
Reported by FlawFinder.
Line: 952
Column: 8
CWE codes:
126
/*
* Reproduce the conflicted merge in-core
*/
len = strlen(path);
pos = index_name_pos(istate, path, len);
if (0 <= pos)
return -1;
pos = -pos - 1;
Reported by FlawFinder.
compat/terminal.c
11 issues
Line: 366
Column: 9
CWE codes:
676
120
20
Suggestion:
Make the specific calls to do exactly what you want. If you continue to use it, or write your own, be sure to zero the password as soon as possible to avoid leaving the cleartext password visible in the process' address space
char *git_terminal_prompt(const char *prompt, int echo)
{
return getpass(prompt);
}
int read_key_without_echo(struct strbuf *buf)
{
static int warning_displayed;
Reported by FlawFinder.
Line: 380
Column: 8
CWE codes:
676
120
20
Suggestion:
Make the specific calls to do exactly what you want. If you continue to use it, or write your own, be sure to zero the password as soon as possible to avoid leaving the cleartext password visible in the process' address space
warning_displayed = 1;
}
res = getpass("");
strbuf_reset(buf);
if (!res)
return EOF;
strbuf_addstr(buf, res);
return 0;
Reported by FlawFinder.
Line: 42
Column: 12
CWE codes:
362
{
struct termios t;
term_fd = open("/dev/tty", O_RDWR);
if (tcgetattr(term_fd, &t) < 0)
goto error;
old_term = t;
sigchain_push_common(restore_term_on_signal);
Reported by FlawFinder.
Line: 208
Column: 13
CWE codes:
362
int r;
FILE *input_fh, *output_fh;
input_fh = fopen(INPUT_PATH, "r" FORCE_TEXT);
if (!input_fh)
return NULL;
output_fh = fopen(OUTPUT_PATH, "w" FORCE_TEXT);
if (!output_fh) {
Reported by FlawFinder.
Line: 212
Column: 14
CWE codes:
362
if (!input_fh)
return NULL;
output_fh = fopen(OUTPUT_PATH, "w" FORCE_TEXT);
if (!output_fh) {
fclose(input_fh);
return NULL;
}
Reported by FlawFinder.
Line: 252
Column: 2
CWE codes:
119
120
Suggestion:
Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length
*/
struct escape_sequence_entry {
struct hashmap_entry entry;
char sequence[FLEX_ARRAY];
};
static int sequence_entry_cmp(const void *hashmap_cmp_fn_data,
const struct escape_sequence_entry *e1,
const struct escape_sequence_entry *e2,
Reported by FlawFinder.
Line: 184
Column: 57
CWE codes:
120
20
DWORD read = 0;
unsigned char ch;
if (!ReadFile(GetStdHandle(STD_INPUT_HANDLE), &ch, 1, &read, NULL))
return EOF;
if (!read) {
error("Unexpected 0 read");
return EOF;
Reported by FlawFinder.
strbuf.h
11 issues
Line: 266
Column: 24
CWE codes:
134
Suggestion:
Use a constant for the format specification
void strbuf_vinsertf(struct strbuf *sb, size_t pos, const char *fmt,
va_list ap);
__attribute__((format (printf, 3, 4)))
void strbuf_insertf(struct strbuf *sb, size_t pos, const char *fmt, ...);
/**
* Remove given amount of data from a given position of the buffer.
*/
Reported by FlawFinder.
Line: 408
Column: 24
CWE codes:
134
Suggestion:
Use a constant for the format specification
/**
* Add a formatted string to the buffer.
*/
__attribute__((format (printf,2,3)))
void strbuf_addf(struct strbuf *sb, const char *fmt, ...);
/**
* Add a formatted string prepended by a comment character and a
* blank to the buffer.
Reported by FlawFinder.
Line: 415
Column: 24
CWE codes:
134
Suggestion:
Use a constant for the format specification
* Add a formatted string prepended by a comment character and a
* blank to the buffer.
*/
__attribute__((format (printf, 2, 3)))
void strbuf_commented_addf(struct strbuf *sb, const char *fmt, ...);
__attribute__((format (printf,2,0)))
void strbuf_vaddf(struct strbuf *sb, const char *fmt, va_list ap);
Reported by FlawFinder.
Line: 418
Column: 24
CWE codes:
134
Suggestion:
Use a constant for the format specification
__attribute__((format (printf, 2, 3)))
void strbuf_commented_addf(struct strbuf *sb, const char *fmt, ...);
__attribute__((format (printf,2,0)))
void strbuf_vaddf(struct strbuf *sb, const char *fmt, va_list ap);
/**
* Add the time specified by `tm`, as formatted by `strftime`.
* `tz_offset` is in decimal hhmm format, e.g. -600 means six hours west
Reported by FlawFinder.
Line: 724
Column: 24
CWE codes:
134
Suggestion:
Use a constant for the format specification
void strbuf_addstr_urlencode(struct strbuf *sb, const char *name,
char_predicate allow_unencoded_fn);
__attribute__((format (printf,1,2)))
int printf_ln(const char *fmt, ...);
__attribute__((format (printf,2,3)))
int fprintf_ln(FILE *fp, const char *fmt, ...);
char *xstrdup_tolower(const char *);
Reported by FlawFinder.
Line: 726
Column: 24
CWE codes:
134
Suggestion:
Use a constant for the format specification
__attribute__((format (printf,1,2)))
int printf_ln(const char *fmt, ...);
__attribute__((format (printf,2,3)))
int fprintf_ln(FILE *fp, const char *fmt, ...);
char *xstrdup_tolower(const char *);
char *xstrdup_toupper(const char *);
Reported by FlawFinder.
Line: 736
Column: 24
CWE codes:
134
Suggestion:
Use a constant for the format specification
* Create a newly allocated string using printf format. You can do this easily
* with a strbuf, but this provides a shortcut to save a few lines.
*/
__attribute__((format (printf, 1, 0)))
char *xstrvfmt(const char *fmt, va_list ap);
__attribute__((format (printf, 1, 2)))
char *xstrfmt(const char *fmt, ...);
#endif /* STRBUF_H */
Reported by FlawFinder.
Line: 738
Column: 24
CWE codes:
134
Suggestion:
Use a constant for the format specification
*/
__attribute__((format (printf, 1, 0)))
char *xstrvfmt(const char *fmt, va_list ap);
__attribute__((format (printf, 1, 2)))
char *xstrfmt(const char *fmt, ...);
#endif /* STRBUF_H */
Reported by FlawFinder.
Line: 256
Column: 28
CWE codes:
126
static inline void strbuf_insertstr(struct strbuf *sb, size_t pos,
const char *s)
{
strbuf_insert(sb, pos, s, strlen(s));
}
/**
* Insert data to the given position of the buffer giving a printf format
* string. The contents will be shifted, not overwritten.
Reported by FlawFinder.
Line: 305
Column: 20
CWE codes:
126
*/
static inline void strbuf_addstr(struct strbuf *sb, const char *s)
{
strbuf_add(sb, s, strlen(s));
}
/**
* Copy the contents of another buffer at the end of the current one.
*/
Reported by FlawFinder.