The following issues were found
merge-ort.c
34 issues
Line: 611
Column: 24
CWE codes:
134
Suggestion:
Use a constant for the format specification
renames->callback_data_nr = renames->callback_data_alloc = 0;
}
__attribute__((format (printf, 2, 3)))
static int err(struct merge_options *opt, const char *err, ...)
{
va_list params;
struct strbuf sb = STRBUF_INIT;
Reported by FlawFinder.
Line: 647
Column: 24
CWE codes:
134
Suggestion:
Use a constant for the format specification
strbuf_addch(sb, '\n');
}
__attribute__((format (printf, 4, 5)))
static void path_msg(struct merge_options *opt,
const char *path,
int omittable_hint, /* skippable under --remerge-diff */
const char *fmt, ...)
{
Reported by FlawFinder.
Line: 447
Column: 8
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 version_info stages[3];
/* pathnames for each stage; may differ due to rename detection */
const char *pathnames[3];
/* Whether this path is/was involved in a directory/file conflict */
unsigned df_conflict:1;
/*
Reported by FlawFinder.
Line: 1489
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 commit *commit;
int contains_another;
char merged_revision[GIT_MAX_HEXSZ + 2];
const char *rev_args[] = { "rev-list", "--merges", "--ancestry-path",
"--all", merged_revision, NULL };
struct rev_info revs;
struct setup_revision_opt rev_opts;
Reported by FlawFinder.
Line: 1686
Column: 3
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
ce->ce_flags = create_ce_flags(0);
ce->ce_namelen = len;
oidcpy(&ce->oid, &mi->result.oid);
memcpy(ce->name, GITATTRIBUTES_FILE, len);
add_index_entry(attr_index, ce,
ADD_CACHE_OK_TO_ADD | ADD_CACHE_OK_TO_REPLACE);
get_stream_filter(attr_index, GITATTRIBUTES_FILE, &ce->oid);
} else {
int stage, len;
Reported by FlawFinder.
Line: 1706
Column: 4
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
ce->ce_flags = create_ce_flags(stage);
ce->ce_namelen = len;
oidcpy(&ce->oid, &ci->stages[stage].oid);
memcpy(ce->name, GITATTRIBUTES_FILE, len);
add_index_entry(attr_index, ce,
ADD_CACHE_OK_TO_ADD | ADD_CACHE_OK_TO_REPLACE);
get_stream_filter(attr_index, GITATTRIBUTES_FILE,
&ce->oid);
}
Reported by FlawFinder.
Line: 1716
Column: 15
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 int merge_3way(struct merge_options *opt,
const char *path,
const struct object_id *o,
const struct object_id *a,
const struct object_id *b,
const char *pathnames[3],
const int extra_marker_size,
Reported by FlawFinder.
Line: 1720
Column: 15
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 struct object_id *o,
const struct object_id *a,
const struct object_id *b,
const char *pathnames[3],
const int extra_marker_size,
mmbuffer_t *result_buf)
{
mmfile_t orig, src1, src2;
struct ll_merge_options ll_opts = {0};
Reported by FlawFinder.
Line: 1782
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
}
static int handle_content_merge(struct merge_options *opt,
const char *path,
const struct version_info *o,
const struct version_info *a,
const struct version_info *b,
const char *pathnames[3],
const int extra_marker_size,
Reported by FlawFinder.
Line: 1786
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 struct version_info *o,
const struct version_info *a,
const struct version_info *b,
const char *pathnames[3],
const int extra_marker_size,
struct version_info *result)
{
/*
* path is the target location where we want to put the file, and
Reported by FlawFinder.
imap-send.c
33 issues
Line: 62
Column: 24
CWE codes:
134
Suggestion:
Use a constant for the format specification
#define DRV_BOX_BAD -2
#define DRV_STORE_BAD -3
__attribute__((format (printf, 1, 2)))
static void imap_info(const char *, ...);
__attribute__((format (printf, 1, 2)))
static void imap_warn(const char *, ...);
static char *next_arg(char **);
Reported by FlawFinder.
Line: 64
Column: 24
CWE codes:
134
Suggestion:
Use a constant for the format specification
__attribute__((format (printf, 1, 2)))
static void imap_info(const char *, ...);
__attribute__((format (printf, 1, 2)))
static void imap_warn(const char *, ...);
static char *next_arg(char **);
__attribute__((format (printf, 3, 4)))
Reported by FlawFinder.
Line: 69
Column: 24
CWE codes:
134
Suggestion:
Use a constant for the format specification
static char *next_arg(char **);
__attribute__((format (printf, 3, 4)))
static int nfsnprintf(char *buf, int blen, const char *fmt, ...);
static int nfvasprintf(char **strp, const char *fmt, va_list ap)
{
int len;
Reported by FlawFinder.
Line: 77
Column: 8
CWE codes:
134
Suggestion:
Use a constant for the format specification
int len;
char tmp[8192];
len = vsnprintf(tmp, sizeof(tmp), fmt, ap);
if (len < 0)
die("Fatal: Out of memory");
if (len >= sizeof(tmp))
die("imap command overflow!");
*strp = xmemdupz(tmp, len);
Reported by FlawFinder.
Line: 454
Column: 24
CWE codes:
134
Suggestion:
Use a constant for the format specification
/* not reached */
}
__attribute__((format (printf, 1, 2)))
static void imap_info(const char *msg, ...)
{
va_list va;
if (0 <= verbosity) {
Reported by FlawFinder.
Line: 461
Column: 3
CWE codes:
134
Suggestion:
Use a constant for the format specification
if (0 <= verbosity) {
va_start(va, msg);
vprintf(msg, va);
va_end(va);
fflush(stdout);
}
}
Reported by FlawFinder.
Line: 467
Column: 24
CWE codes:
134
Suggestion:
Use a constant for the format specification
}
}
__attribute__((format (printf, 1, 2)))
static void imap_warn(const char *msg, ...)
{
va_list va;
if (-2 < verbosity) {
Reported by FlawFinder.
Line: 474
Column: 3
CWE codes:
134
Suggestion:
Use a constant for the format specification
if (-2 < verbosity) {
va_start(va, msg);
vfprintf(stderr, msg, va);
va_end(va);
}
}
static char *next_arg(char **s)
Reported by FlawFinder.
Line: 509
Column: 24
CWE codes:
134
Suggestion:
Use a constant for the format specification
return ret;
}
__attribute__((format (printf, 3, 4)))
static int nfsnprintf(char *buf, int blen, const char *fmt, ...)
{
int ret;
va_list va;
Reported by FlawFinder.
Line: 516
Column: 36
CWE codes:
134
Suggestion:
Use a constant for the format specification
va_list va;
va_start(va, fmt);
if (blen <= 0 || (unsigned)(ret = vsnprintf(buf, blen, fmt, va)) >= (unsigned)blen)
BUG("buffer too small. Please report a bug.");
va_end(va);
return ret;
}
Reported by FlawFinder.
read-cache.c
33 issues
Line: 1522
Column: 2
CWE codes:
134
Suggestion:
Use a constant for the format specification
printf("%s\n", header_msg);
*first = 0;
}
printf(fmt, name);
}
int repo_refresh_and_write_index(struct repository *repo,
unsigned int refresh_flags,
unsigned int write_flags,
Reported by FlawFinder.
Line: 1695
Column: 21
CWE codes:
807
20
Suggestion:
Check environment variables carefully before using them
static unsigned int get_index_format_default(struct repository *r)
{
char *envversion = getenv("GIT_INDEX_VERSION");
char *endp;
unsigned int version = INDEX_FORMAT_DEFAULT;
if (!envversion) {
prepare_repo_settings(r);
Reported by FlawFinder.
Line: 3484
Column: 7
CWE codes:
807
20
Suggestion:
Check environment variables carefully before using them
static int validate_index_cache_entries = -1;
if (validate_index_cache_entries < 0) {
if (getenv("GIT_TEST_VALIDATE_INDEX_CACHE_ENTRIES"))
validate_index_cache_entries = 1;
else
validate_index_cache_entries = 0;
}
Reported by FlawFinder.
Line: 139
Column: 2
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
new_entry->ce_flags &= ~CE_HASHED;
new_entry->ce_namelen = namelen;
new_entry->index = 0;
memcpy(new_entry->name, new_name, namelen + 1);
cache_tree_invalidate_path(istate, old_entry->name);
untracked_cache_remove_from_index(istate, old_entry->name);
remove_index_entry_at(istate, nr);
add_index_entry(istate, new_entry, ADD_CACHE_OK_TO_ADD|ADD_CACHE_OK_TO_REPLACE);
Reported by FlawFinder.
Line: 716
Column: 2
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
/* Ok, create the new entry using the name of the existing alias */
len = ce_namelen(alias);
new_entry = make_empty_cache_entry(istate, len);
memcpy(new_entry->name, alias->name, len);
copy_cache_entry(new_entry, ce);
save_or_free_index_entry(istate, ce);
return new_entry;
}
Reported by FlawFinder.
Line: 758
Column: 2
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
namelen--;
}
ce = make_empty_cache_entry(istate, namelen);
memcpy(ce->name, path, namelen);
ce->ce_namelen = namelen;
if (!intent_only)
fill_stat_cache_info(istate, ce, st);
else
ce->ce_flags |= CE_INTENT_TO_ADD;
Reported by FlawFinder.
Line: 871
Column: 2
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
ce = make_empty_cache_entry(istate, len);
oidcpy(&ce->oid, oid);
memcpy(ce->name, path, len);
ce->ce_flags = create_ce_flags(stage);
ce->ce_namelen = len;
ce->ce_mode = create_ce_mode(mode);
ret = refresh_cache_entry(istate, ce, refresh_options);
Reported by FlawFinder.
Line: 900
Column: 2
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
ce = make_empty_transient_cache_entry(len, ce_mem_pool);
oidcpy(&ce->oid, oid);
memcpy(ce->name, path, len);
ce->ce_flags = create_ce_flags(stage);
ce->ce_namelen = len;
ce->ce_mode = create_ce_mode(mode);
return ce;
Reported by FlawFinder.
Line: 1499
Column: 2
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
updated = make_empty_cache_entry(istate, ce_namelen(ce));
copy_cache_entry(updated, ce);
memcpy(updated->name, ce->name, ce->ce_namelen + 1);
fill_stat_cache_info(istate, updated, &st);
/*
* If ignore_valid is not set, we should leave CE_VALID bit
* alone. Otherwise, paths marked with --no-assume-unchanged
* (i.e. things to be edited) will reacquire CE_VALID bit
Reported by FlawFinder.
Line: 1745
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
* if (flags & CE_EXTENDED)
* uint16_t flags2;
*/
unsigned char data[GIT_MAX_RAWSZ + 2 * sizeof(uint16_t)];
char name[FLEX_ARRAY];
};
/* These are only used for v3 or lower */
#define align_padding_size(size, len) ((size + (len) + 8) & ~7) - (size + len)
Reported by FlawFinder.
setup.c
31 issues
Line: 358
Column: 7
CWE codes:
362/367!
Suggestion:
Set up the correct permissions (e.g., using setuid()) and try to open the file directly
/* Check non-worktree-related signatures */
if (getenv(DB_ENVIRONMENT)) {
if (access(getenv(DB_ENVIRONMENT), X_OK))
goto done;
}
else {
strbuf_setlen(&path, len);
strbuf_addstr(&path, "/objects");
Reported by FlawFinder.
Line: 364
Column: 7
CWE codes:
362/367!
Suggestion:
Set up the correct permissions (e.g., using setuid()) and try to open the file directly
else {
strbuf_setlen(&path, len);
strbuf_addstr(&path, "/objects");
if (access(path.buf, X_OK))
goto done;
}
strbuf_setlen(&path, len);
strbuf_addstr(&path, "/refs");
Reported by FlawFinder.
Line: 370
Column: 6
CWE codes:
362/367!
Suggestion:
Set up the correct permissions (e.g., using setuid()) and try to open the file directly
strbuf_setlen(&path, len);
strbuf_addstr(&path, "/refs");
if (access(path.buf, X_OK))
goto done;
ret = 1;
done:
strbuf_release(&path);
Reported by FlawFinder.
Line: 64
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
path++;
if (*path == '/') {
*path = '\0';
strbuf_realpath(&realpath, path0, 1);
if (fspathcmp(realpath.buf, work_tree) == 0) {
memmove(path0, path + 1, len - (path - path0));
strbuf_release(&realpath);
return 0;
}
Reported by FlawFinder.
Line: 65
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
if (*path == '/') {
*path = '\0';
strbuf_realpath(&realpath, path0, 1);
if (fspathcmp(realpath.buf, work_tree) == 0) {
memmove(path0, path + 1, len - (path - path0));
strbuf_release(&realpath);
return 0;
}
*path = '/';
Reported by FlawFinder.
Line: 67
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
strbuf_realpath(&realpath, path0, 1);
if (fspathcmp(realpath.buf, work_tree) == 0) {
memmove(path0, path + 1, len - (path - path0));
strbuf_release(&realpath);
return 0;
}
*path = '/';
}
}
Reported by FlawFinder.
Line: 75
Column: 19
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
}
/* check whole path */
strbuf_realpath(&realpath, path0, 1);
if (fspathcmp(realpath.buf, work_tree) == 0) {
*path0 = '\0';
strbuf_release(&realpath);
return 0;
}
Reported by FlawFinder.
Line: 76
Column: 16
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
/* check whole path */
strbuf_realpath(&realpath, path0, 1);
if (fspathcmp(realpath.buf, work_tree) == 0) {
*path0 = '\0';
strbuf_release(&realpath);
return 0;
}
Reported by FlawFinder.
Line: 78
Column: 19
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
strbuf_realpath(&realpath, path0, 1);
if (fspathcmp(realpath.buf, work_tree) == 0) {
*path0 = '\0';
strbuf_release(&realpath);
return 0;
}
strbuf_release(&realpath);
return -1;
Reported by FlawFinder.
Line: 82
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
return 0;
}
strbuf_release(&realpath);
return -1;
}
/*
* Normalize "path", prepending the "prefix" for relative paths. If
Reported by FlawFinder.
object-file.c
31 issues
Line: 1475
CWE codes:
562
return -1;
if (!oi->sizep)
oi->sizep = &size_scratch;
if (oi->disk_sizep)
*oi->disk_sizep = mapsize;
if ((flags & OBJECT_INFO_ALLOW_UNKNOWN_TYPE)) {
if (unpack_loose_header_to_strbuf(&stream, map, mapsize, hdr, sizeof(hdr), &hdrbuf) < 0)
Reported by Cppcheck.
Line: 800
Column: 7
CWE codes:
362/367!
Suggestion:
Set up the correct permissions (e.g., using setuid()) and try to open the file directly
goto out;
}
if (!access(mkpath("%s/shallow", ref_git), F_OK)) {
strbuf_addf(err, _("reference repository '%s' is shallow"),
path);
seen_error = 1;
goto out;
}
Reported by FlawFinder.
Line: 807
Column: 7
CWE codes:
362/367!
Suggestion:
Set up the correct permissions (e.g., using setuid()) and try to open the file directly
goto out;
}
if (!access(mkpath("%s/info/grafts", ref_git), F_OK)) {
strbuf_addf(err,
_("reference repository '%s' is grafted"),
path);
seen_error = 1;
goto out;
Reported by FlawFinder.
Line: 961
Column: 6
CWE codes:
362/367!
Suggestion:
Set up the correct permissions (e.g., using setuid()) and try to open the file directly
*/
int check_and_freshen_file(const char *fn, int freshen)
{
if (access(fn, F_OK))
return 0;
if (freshen && !freshen_file(fn))
return 0;
return 1;
}
Reported by FlawFinder.
Line: 490
CWE codes:
476
int i;
for (i = 0; i < the_hash_algo->rawsz; i++) {
static char hex[] = "0123456789abcdef";
unsigned int val = oid->hash[i];
strbuf_addch(buf, hex[val >> 4]);
strbuf_addch(buf, hex[val & 0xf]);
if (!i)
strbuf_addch(buf, '/');
}
Reported by Cppcheck.
Line: 225
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
const char *empty_tree_oid_hex(void)
{
static char buf[GIT_MAX_HEXSZ + 1];
return oid_to_hex_r(buf, the_hash_algo->empty_tree);
}
const char *empty_blob_oid_hex(void)
{
Reported by FlawFinder.
Line: 231
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
const char *empty_blob_oid_hex(void)
{
static char buf[GIT_MAX_HEXSZ + 1];
return oid_to_hex_r(buf, the_hash_algo->empty_blob);
}
int hash_algo_by_name(const char *name)
{
Reported by FlawFinder.
Line: 710
Column: 7
CWE codes:
362
if (!out)
die_errno(_("unable to fdopen alternates lockfile"));
in = fopen(alts, "r");
if (in) {
struct strbuf line = STRBUF_INIT;
while (strbuf_getline(&line, in) != EOF) {
if (!strcmp(reference, line.buf)) {
Reported by FlawFinder.
Line: 1071
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
enum object_type obj_type;
struct git_istream *st;
git_hash_ctx c;
char hdr[MAX_HEADER_LEN];
int hdrlen;
if (map) {
hash_object_file(r->hash_algo, map, size, type, &real_oid);
return !oideq(oid, &real_oid) ? -1 : 0;
Reported by FlawFinder.
Line: 1090
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
r->hash_algo->init_fn(&c);
r->hash_algo->update_fn(&c, hdr, hdrlen);
for (;;) {
char buf[1024 * 16];
ssize_t readlen = read_istream(st, buf, sizeof(buf));
if (readlen < 0) {
close_istream(st);
return -1;
Reported by FlawFinder.
daemon.c
30 issues
Line: 86
Column: 3
CWE codes:
134
Suggestion:
Use a constant for the format specification
switch (log_destination) {
case LOG_DESTINATION_SYSLOG: {
char buf[1024];
vsnprintf(buf, sizeof(buf), err, params);
syslog(priority, "%s", buf);
break;
}
case LOG_DESTINATION_STDERR:
/*
Reported by FlawFinder.
Line: 97
Column: 3
CWE codes:
134
Suggestion:
Use a constant for the format specification
* unless they overflow the (rather big) buffers.
*/
fprintf(stderr, "[%"PRIuMAX"] ", (uintmax_t)getpid());
vfprintf(stderr, err, params);
fputc('\n', stderr);
fflush(stderr);
break;
case LOG_DESTINATION_NONE:
break;
Reported by FlawFinder.
Line: 108
Column: 24
CWE codes:
134
Suggestion:
Use a constant for the format specification
}
}
__attribute__((format (printf, 1, 2)))
static void logerror(const char *err, ...)
{
va_list params;
va_start(params, err);
logreport(LOG_ERR, err, params);
Reported by FlawFinder.
Line: 117
Column: 24
CWE codes:
134
Suggestion:
Use a constant for the format specification
va_end(params);
}
__attribute__((format (printf, 1, 2)))
static void loginfo(const char *err, ...)
{
va_list params;
if (!verbose)
return;
Reported by FlawFinder.
Line: 408
Column: 27
CWE codes:
362/367!
Suggestion:
Set up the correct permissions (e.g., using setuid()) and try to open the file directly
* We only need to make sure the repository is exported.
*/
if (!export_all_trees && access("git-daemon-export-ok", F_OK)) {
logerror("'%s': repository not exported.", path);
errno = EACCES;
return daemon_error(dir, "repository not exported");
}
Reported by FlawFinder.
Line: 762
Column: 46
CWE codes:
807
20
Suggestion:
Check environment variables carefully before using them
{
char *line = packet_buffer;
int pktlen, len, i;
char *addr = getenv("REMOTE_ADDR"), *port = getenv("REMOTE_PORT");
struct hostinfo hi;
struct strvec env = STRVEC_INIT;
hostinfo_init(&hi);
Reported by FlawFinder.
Line: 762
Column: 15
CWE codes:
807
20
Suggestion:
Check environment variables carefully before using them
{
char *line = packet_buffer;
int pktlen, len, i;
char *addr = getenv("REMOTE_ADDR"), *port = getenv("REMOTE_PORT");
struct hostinfo hi;
struct strvec env = STRVEC_INIT;
hostinfo_init(&hi);
Reported by FlawFinder.
Line: 85
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
{
switch (log_destination) {
case LOG_DESTINATION_SYSLOG: {
char buf[1024];
vsnprintf(buf, sizeof(buf), err, params);
syslog(priority, "%s", buf);
break;
}
case LOG_DESTINATION_STDERR:
Reported by FlawFinder.
Line: 172
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 *path_ok(const char *directory, struct hostinfo *hi)
{
static char rpath[PATH_MAX];
static char interp_path[PATH_MAX];
size_t rlen;
const char *path;
const char *dir;
Reported by FlawFinder.
Line: 173
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 *path_ok(const char *directory, struct hostinfo *hi)
{
static char rpath[PATH_MAX];
static char interp_path[PATH_MAX];
size_t rlen;
const char *path;
const char *dir;
dir = directory;
Reported by FlawFinder.
http-backend.c
28 issues
Line: 66
Column: 24
CWE codes:
134
Suggestion:
Use a constant for the format specification
return i ? i->util : NULL;
}
__attribute__((format (printf, 2, 3)))
static void format_write(int fd, const char *fmt, ...)
{
static char buffer[1024];
va_list args;
Reported by FlawFinder.
Line: 75
Column: 6
CWE codes:
134
Suggestion:
Use a constant for the format specification
unsigned n;
va_start(args, fmt);
n = vsnprintf(buffer, sizeof(buffer), fmt, args);
va_end(args);
if (n >= sizeof(buffer))
die("protocol error: impossibly long line");
write_or_die(fd, buffer, n);
Reported by FlawFinder.
Line: 126
Column: 24
CWE codes:
134
Suggestion:
Use a constant for the format specification
strbuf_release(hdr);
}
__attribute__((format (printf, 2, 3)))
static NORETURN void not_found(struct strbuf *hdr, const char *err, ...)
{
va_list params;
http_status(hdr, 404, "Not Found");
Reported by FlawFinder.
Line: 137
Column: 3
CWE codes:
134
Suggestion:
Use a constant for the format specification
va_start(params, err);
if (err && *err)
vfprintf(stderr, err, params);
va_end(params);
exit(0);
}
__attribute__((format (printf, 2, 3)))
Reported by FlawFinder.
Line: 142
Column: 24
CWE codes:
134
Suggestion:
Use a constant for the format specification
exit(0);
}
__attribute__((format (printf, 2, 3)))
static NORETURN void forbidden(struct strbuf *hdr, const char *err, ...)
{
va_list params;
http_status(hdr, 403, "Forbidden");
Reported by FlawFinder.
Line: 153
Column: 3
CWE codes:
134
Suggestion:
Use a constant for the format specification
va_start(params, err);
if (err && *err)
vfprintf(stderr, err, params);
va_end(params);
exit(0);
}
static void select_getanyfile(struct strbuf *hdr)
Reported by FlawFinder.
Line: 786
Column: 6
CWE codes:
362/367!
Suggestion:
Set up the correct permissions (e.g., using setuid()) and try to open the file directly
if (!enter_repo(dir, 0))
not_found(&hdr, "Not a git repository: '%s'", dir);
if (!getenv("GIT_HTTP_EXPORT_ALL") &&
access("git-daemon-export-ok", F_OK) )
not_found(&hdr, "Repository not exported: '%s'", dir);
http_config();
max_request_buffer = git_env_ulong("GIT_HTTP_MAX_REQUEST_BUFFER",
max_request_buffer);
Reported by FlawFinder.
Line: 40
Column: 23
CWE codes:
807
20
Suggestion:
Check environment variables carefully before using them
static struct string_list *get_parameters(void)
{
if (!query_params) {
const char *query = getenv("QUERY_STRING");
CALLOC_ARRAY(query_params, 1);
while (query && *query) {
char *name = url_decode_parameter_name(&query);
char *value = url_decode_parameter_value(&query);
Reported by FlawFinder.
Line: 274
Column: 22
CWE codes:
807
20
Suggestion:
Check environment variables carefully before using them
forbidden(hdr, "Unsupported service: '%s'", name);
if (svc->enabled < 0) {
const char *user = getenv("REMOTE_USER");
svc->enabled = (user && *user) ? 1 : 0;
}
if (!svc->enabled)
forbidden(hdr, "Service not enabled: '%s'", svc->name);
return svc;
Reported by FlawFinder.
Line: 354
Column: 20
CWE codes:
807
20
Suggestion:
Check environment variables carefully before using them
static ssize_t get_content_length(void)
{
ssize_t val = -1;
const char *str = getenv("CONTENT_LENGTH");
if (str && *str && !git_parse_ssize_t(str, &val))
die("failed to parse CONTENT_LENGTH: %s", str);
return val;
}
Reported by FlawFinder.
path.c
27 issues
Line: 674
Column: 9
CWE codes:
362
20
Suggestion:
Reconsider approach
/* Make sure it is a "refs/.." symlink */
if (S_ISLNK(st.st_mode)) {
len = readlink(path, buffer, sizeof(buffer)-1);
if (len >= 5 && !memcmp("refs/", buffer, 5))
return 0;
return -1;
}
Reported by FlawFinder.
Line: 901
Column: 4
CWE codes:
362
Suggestion:
Use fchmod( ) instead
}
if (((old_mode ^ new_mode) & ~S_IFMT) &&
chmod(path, (new_mode & ~S_IFMT)) < 0)
return -2;
return 0;
}
void safe_create_dir(const char *dir, int share)
Reported by FlawFinder.
Line: 62
Column: 8
CWE codes:
134
Suggestion:
Use a constant for the format specification
unsigned len;
va_start(args, fmt);
len = vsnprintf(buf, n, fmt, args);
va_end(args);
if (len >= n) {
strlcpy(buf, bad_path, n);
return buf;
}
Reported by FlawFinder.
Line: 740
Column: 23
CWE codes:
807
20
Suggestion:
Check environment variables carefully before using them
const char *username = path + 1;
size_t username_len = first_slash - username;
if (username_len == 0) {
const char *home = getenv("HOME");
if (!home)
goto return_null;
if (real_home)
strbuf_add_real_path(&user_path, home);
else
Reported by FlawFinder.
Line: 1511
Column: 16
CWE codes:
807
20
Suggestion:
Check environment variables carefully before using them
const char *home, *config_home;
assert(filename);
config_home = getenv("XDG_CONFIG_HOME");
if (config_home && *config_home)
return mkpathdup("%s/git/%s", config_home, filename);
home = getenv("HOME");
if (home)
Reported by FlawFinder.
Line: 1515
Column: 9
CWE codes:
807
20
Suggestion:
Check environment variables carefully before using them
if (config_home && *config_home)
return mkpathdup("%s/git/%s", config_home, filename);
home = getenv("HOME");
if (home)
return mkpathdup("%s/.config/git/%s", home, filename);
return NULL;
}
Reported by FlawFinder.
Line: 1526
Column: 15
CWE codes:
807
20
Suggestion:
Check environment variables carefully before using them
const char *home, *cache_home;
assert(filename);
cache_home = getenv("XDG_CACHE_HOME");
if (cache_home && *cache_home)
return mkpathdup("%s/git/%s", cache_home, filename);
home = getenv("HOME");
if (home)
Reported by FlawFinder.
Line: 1530
Column: 9
CWE codes:
807
20
Suggestion:
Check environment variables carefully before using them
if (cache_home && *cache_home)
return mkpathdup("%s/git/%s", cache_home, filename);
home = getenv("HOME");
if (home)
return mkpathdup("%s/.cache/git/%s", home, filename);
return NULL;
}
Reported by FlawFinder.
Line: 171
Column: 3
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
new_node->len = strlen(key);
if (new_node->len) {
new_node->contents = xmalloc(new_node->len);
memcpy(new_node->contents, key, new_node->len);
}
new_node->value = value;
return new_node;
}
Reported by FlawFinder.
Line: 203
Column: 3
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
* existing children.
*/
child = xmalloc(sizeof(*child));
memcpy(child->children, root->children, sizeof(root->children));
child->len = root->len - i - 1;
if (child->len) {
child->contents = xstrndup(root->contents + i + 1,
child->len);
Reported by FlawFinder.
compat/nedmalloc/malloc.c.h
27 issues
Line: 3405
CWE codes:
682
check_malloc_state(m);
if (is_initialized(m)) {
size_t nfree = SIZE_T_ONE; /* top always free */
size_t mfree = m->topsize + TOP_FOOT_SIZE;
size_t sum = mfree;
msegmentptr s = &m->seg;
while (s != 0) {
mchunkptr q = align_as_chunk(s->base);
while (segment_holds(s, q) &&
Reported by Cppcheck.
Line: 3449
CWE codes:
682
msegmentptr s = &m->seg;
maxfp = m->max_footprint;
fp = m->footprint;
used = fp - (m->topsize + TOP_FOOT_SIZE);
while (s != 0) {
mchunkptr q = align_as_chunk(s->base);
while (segment_holds(s, q) &&
q != m->top && q->head != FENCEPOST_HEAD) {
Reported by Cppcheck.
Line: 3807
CWE codes:
682
m->topsize = psize;
p->head = psize | PINUSE_BIT;
/* set size of fake trailing chunk holding overhead space only once */
chunk_plus_offset(p, psize)->head = TOP_FOOT_SIZE;
m->trim_check = mparams.trim_threshold; /* reset on each update */
}
/* Initialize bins for a new mstate that is otherwise zeroed out */
static void init_bins(mstate m) {
Reported by Cppcheck.
Line: 3900
CWE codes:
682
int nfences = 0;
/* reset top to new space */
init_top(m, (mchunkptr)tbase, tsize - TOP_FOOT_SIZE);
/* Set up segment record */
assert(is_aligned(ss));
set_size_and_pinuse_of_inuse_chunk(m, sp, ssize);
*ss = m->seg; /* Push current record */
Reported by Cppcheck.
Line: 3983
CWE codes:
682
if (ss == 0) { /* First time through or recovery */
char* base = (char*)CALL_MORECORE(0);
if (base != CMFAIL) {
asize = granularity_align(nb + SYS_ALLOC_PADDING);
/* Adjust to end on a page boundary */
if (!is_page_aligned(base))
asize += (page_align((size_t)base) - (size_t)base);
/* Can't call MORECORE if size is negative when treated as signed */
if (asize < HALF_MAX_SIZE_T &&
Reported by Cppcheck.
Line: 3997
CWE codes:
682
}
else {
/* Subtract out existing available top space from MORECORE request. */
asize = granularity_align(nb - m->topsize + SYS_ALLOC_PADDING);
/* Use mem here only if it did continuously extend old space */
if (asize < HALF_MAX_SIZE_T &&
(br = (char*)(CALL_MORECORE(asize))) == ss->base+ss->size) {
tbase = br;
tsize = asize;
Reported by Cppcheck.
Line: 4009
CWE codes:
682
if (tbase == CMFAIL) { /* Cope with partial failure */
if (br != CMFAIL) { /* Try to use/extend the space we did get */
if (asize < HALF_MAX_SIZE_T &&
asize < nb + SYS_ALLOC_PADDING) {
size_t esize = granularity_align(nb + SYS_ALLOC_PADDING - asize);
if (esize < HALF_MAX_SIZE_T) {
char* end = (char*)CALL_MORECORE(esize);
if (end != CMFAIL)
asize += esize;
Reported by Cppcheck.
Line: 4010
CWE codes:
682
if (br != CMFAIL) { /* Try to use/extend the space we did get */
if (asize < HALF_MAX_SIZE_T &&
asize < nb + SYS_ALLOC_PADDING) {
size_t esize = granularity_align(nb + SYS_ALLOC_PADDING - asize);
if (esize < HALF_MAX_SIZE_T) {
char* end = (char*)CALL_MORECORE(esize);
if (end != CMFAIL)
asize += esize;
else { /* Can't use; try to release */
Reported by Cppcheck.
Line: 4034
CWE codes:
682
}
if (HAVE_MMAP && tbase == CMFAIL) { /* Try MMAP */
size_t rsize = granularity_align(nb + SYS_ALLOC_PADDING);
if (rsize > nb) { /* Fail if wraps around zero */
char* mp = (char*)(CALL_MMAP(rsize));
if (mp != CMFAIL) {
tbase = mp;
tsize = rsize;
Reported by Cppcheck.
Line: 4046
CWE codes:
682
}
if (HAVE_MORECORE && tbase == CMFAIL) { /* Try noncontiguous MORECORE */
size_t asize = granularity_align(nb + SYS_ALLOC_PADDING);
if (asize < HALF_MAX_SIZE_T) {
char* br = CMFAIL;
char* end = CMFAIL;
ACQUIRE_MALLOC_GLOBAL_LOCK();
br = (char*)(CALL_MORECORE(asize));
Reported by Cppcheck.
contrib/hg-to-git/hg-to-git.py
26 issues
Line: 128
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b605_start_process_with_a_shell.html
hgbranch["0"] = "master"
for cset in range(1, int(tip) + 1):
hgchildren[str(cset)] = ()
prnts = os.popen('hg log -r %d --template "{parents}"' % cset).read().strip().split(' ')
prnts = map(lambda x: x[:x.find(':')], prnts)
if prnts[0] != '':
parent = prnts[0].strip()
else:
parent = str(cset - 1)
Reported by Bandit.
Line: 170
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b605_start_process_with_a_shell.html
hgnewcsets += 1
# get info
log_data = os.popen('hg log -r %d --template "{tags}\n{date|date}\n{author}\n"' % cset).readlines()
tag = log_data[0].strip()
date = log_data[1].strip()
user = log_data[2].strip()
parent = hgparents[str(cset)][0]
mparent = hgparents[str(cset)][1]
Reported by Bandit.
Line: 179
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b605_start_process_with_a_shell.html
#get comment
(fdcomment, filecomment) = tempfile.mkstemp()
csetcomment = os.popen('hg log -r %d --template "{desc}"' % cset).read().strip()
os.write(fdcomment, csetcomment)
os.close(fdcomment)
print('-----------------------------------------')
print('cset:', cset)
Reported by Bandit.
Line: 201
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b605_start_process_with_a_shell.html
if cset != 0:
if hgbranch[str(cset)] == "branch-" + str(cset):
print('creating new branch', hgbranch[str(cset)])
os.system('git checkout -b %s %s' % (hgbranch[str(cset)], hgvers[parent]))
else:
print('checking out branch', hgbranch[str(cset)])
os.system('git checkout %s' % hgbranch[str(cset)])
# merge
Reported by Bandit.
Line: 204
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b605_start_process_with_a_shell.html
os.system('git checkout -b %s %s' % (hgbranch[str(cset)], hgvers[parent]))
else:
print('checking out branch', hgbranch[str(cset)])
os.system('git checkout %s' % hgbranch[str(cset)])
# merge
if mparent:
if hgbranch[parent] == hgbranch[str(cset)]:
otherbranch = hgbranch[mparent]
Reported by Bandit.
Line: 213
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b605_start_process_with_a_shell.html
else:
otherbranch = hgbranch[parent]
print('merging', otherbranch, 'into', hgbranch[str(cset)])
os.system(getgitenv(user, date) + 'git merge --no-commit -s ours "" %s %s' % (hgbranch[str(cset)], otherbranch))
# remove everything except .git and .hg directories
os.system('find . \( -path "./.hg" -o -path "./.git" \) -prune -o ! -name "." -print | xargs rm -rf')
# repopulate with checkouted files
Reported by Bandit.
Line: 219
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b605_start_process_with_a_shell.html
os.system('find . \( -path "./.hg" -o -path "./.git" \) -prune -o ! -name "." -print | xargs rm -rf')
# repopulate with checkouted files
os.system('hg update -C %d' % cset)
# add new files
os.system('git ls-files -x .hg --others | git update-index --add --stdin')
# delete removed files
os.system('git ls-files -x .hg --deleted | git update-index --remove --stdin')
Reported by Bandit.
Line: 227
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b605_start_process_with_a_shell.html
os.system('git ls-files -x .hg --deleted | git update-index --remove --stdin')
# commit
os.system(getgitenv(user, date) + 'git commit --allow-empty --allow-empty-message -a -F %s' % filecomment)
os.unlink(filecomment)
# tag
if tag and tag != 'tip':
os.system(getgitenv(user, date) + 'git tag %s' % tag)
Reported by Bandit.
Line: 232
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b605_start_process_with_a_shell.html
# tag
if tag and tag != 'tip':
os.system(getgitenv(user, date) + 'git tag %s' % tag)
# delete branch if not used anymore...
if mparent and len(hgchildren[str(cset)]):
print("Deleting unused branch:", otherbranch)
os.system('git branch -d %s' % otherbranch)
Reported by Bandit.
Line: 237
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b605_start_process_with_a_shell.html
# delete branch if not used anymore...
if mparent and len(hgchildren[str(cset)]):
print("Deleting unused branch:", otherbranch)
os.system('git branch -d %s' % otherbranch)
# retrieve and record the version
vvv = os.popen('git show --quiet --pretty=format:%H').read()
print('record', cset, '->', vvv)
hgvers[str(cset)] = vvv
Reported by Bandit.