Flawfinder version 2.0.10, (C) 2001-2019 David A. Wheeler. Number of rules (primarily dangerous function names) in C/C++ ruleset: 223 Examining data/megatools-1.11.0~git20200404/lib/alloc.h Examining data/megatools-1.11.0~git20200404/lib/http.c Examining data/megatools-1.11.0~git20200404/lib/http.h Examining data/megatools-1.11.0~git20200404/lib/mega.c Examining data/megatools-1.11.0~git20200404/lib/mega.h Examining data/megatools-1.11.0~git20200404/lib/sjson.c Examining data/megatools-1.11.0~git20200404/lib/sjson.gen.c Examining data/megatools-1.11.0~git20200404/lib/sjson.h Examining data/megatools-1.11.0~git20200404/lib/tools.c Examining data/megatools-1.11.0~git20200404/lib/tools.h Examining data/megatools-1.11.0~git20200404/tools/copy.c Examining data/megatools-1.11.0~git20200404/tools/df.c Examining data/megatools-1.11.0~git20200404/tools/dl.c Examining data/megatools-1.11.0~git20200404/tools/export.c Examining data/megatools-1.11.0~git20200404/tools/get.c Examining data/megatools-1.11.0~git20200404/tools/ls.c Examining data/megatools-1.11.0~git20200404/tools/mkdir.c Examining data/megatools-1.11.0~git20200404/tools/put.c Examining data/megatools-1.11.0~git20200404/tools/reg.c Examining data/megatools-1.11.0~git20200404/tools/rm.c Examining data/megatools-1.11.0~git20200404/tools/shell.c Examining data/megatools-1.11.0~git20200404/tools/shell.h Examining data/megatools-1.11.0~git20200404/tools/test.c FINAL RESULTS: data/megatools-1.11.0~git20200404/lib/http.c:43:78: [4] (race) access: This usually indicates a security flaw. If an attacker can change anything along the path between the call to access() and the file's actual use (e.g., by moving files), the attacker can exploit the race condition (CWE-362/CWE-367!). Set up the correct permissions (e.g., using setuid()) and try to open the file directly. static void http_lock_cb(CURL *handle, curl_lock_data data, curl_lock_access access, void *userptr) data/megatools-1.11.0~git20200404/lib/sjson.c:526:3: [4] (buffer) sscanf: The scanf() family's %s operation, without a limit specification, permits buffer overflows (CWE-120, CWE-20). Specify a limit to %s, or use a different input function. If the scanf format is influenceable by an attacker, it's exploitable. sscanf(str, "%" G_GINT64_FORMAT, &v); data/megatools-1.11.0~git20200404/lib/sjson.gen.c:962:3: [4] (buffer) sscanf: The scanf() family's %s operation, without a limit specification, permits buffer overflows (CWE-120, CWE-20). Specify a limit to %s, or use a different input function. If the scanf format is influenceable by an attacker, it's exploitable. sscanf(str, "%" G_GINT64_FORMAT, &v); data/megatools-1.11.0~git20200404/lib/mega.c:3761:47: [3] (random) g_random_int_range: This function is not sufficiently random for security-related functions such as key and nonce creation (CWE-327). Use a more secure technique for acquiring random values. c->start_at = now + 1000 * (5*60*1000 + g_random_int_range(0, 2000)); data/megatools-1.11.0~git20200404/lib/mega.c:4869:41: [3] (buffer) g_get_tmp_dir: This function is synonymous with 'getenv("TMP")';it returns untrustable input if the environment can beset by an attacker. It can have any content and length, and the same variable can be set more than once (CWE-807, CWE-20). Check environment variables carefully before using them. gc_free gchar *path = g_build_filename(g_get_tmp_dir(), filename, NULL); data/megatools-1.11.0~git20200404/lib/mega.c:4947:41: [3] (buffer) g_get_tmp_dir: This function is synonymous with 'getenv("TMP")';it returns untrustable input if the environment can beset by an attacker. It can have any content and length, and the same variable can be set more than once (CWE-807, CWE-20). Check environment variables carefully before using them. gc_free gchar *path = g_build_filename(g_get_tmp_dir(), filename, NULL); data/megatools-1.11.0~git20200404/lib/tools.c:513:43: [3] (buffer) g_get_home_dir: This function is synonymous with 'getenv("HOME")';it returns untrustable input if the environment can beset by an attacker. It can have any content and length, and the same variable can be set more than once (CWE-807, CWE-20). Check environment variables carefully before using them. gc_free gchar *tmp = g_build_filename(g_get_home_dir(), MEGA_RC_FILENAME, NULL); data/megatools-1.11.0~git20200404/lib/mega.c:504:2: [2] (buffer) memcpy: Does not check for buffer overflows when copying to destination (CWE-120). Make sure destination can always hold the source data. memcpy(data, str, str_len); data/megatools-1.11.0~git20200404/lib/mega.c:877:4: [2] (buffer) memcpy: Does not check for buffer overflows when copying to destination (CWE-120). Make sure destination can always hold the source data. memcpy(pkey, pkey_tmp, 16); data/megatools-1.11.0~git20200404/lib/mega.c:903:3: [2] (buffer) memcpy: Does not check for buffer overflows when copying to destination (CWE-120). Make sure destination can always hold the source data. memcpy(hash, hash_tmp, 16); data/megatools-1.11.0~git20200404/lib/mega.c:906:2: [2] (buffer) memcpy: Does not check for buffer overflows when copying to destination (CWE-120). Make sure destination can always hold the source data. memcpy(oh, hash, 4); data/megatools-1.11.0~git20200404/lib/mega.c:907:2: [2] (buffer) memcpy: Does not check for buffer overflows when copying to destination (CWE-120). Make sure destination can always hold the source data. memcpy(oh + 4, hash + 8, 4); data/megatools-1.11.0~git20200404/lib/mega.c:954:2: [2] (buffer) memcpy: Does not check for buffer overflows when copying to destination (CWE-120). Make sure destination can always hold the source data. memcpy(mac->chunk_mac_iv, iv, 16); data/megatools-1.11.0~git20200404/lib/mega.c:955:2: [2] (buffer) memcpy: Does not check for buffer overflows when copying to destination (CWE-120). Make sure destination can always hold the source data. memcpy(mac->chunk_mac, mac->chunk_mac_iv, 16); data/megatools-1.11.0~git20200404/lib/mega.c:977:2: [2] (buffer) memcpy: Does not check for buffer overflows when copying to destination (CWE-120). Make sure destination can always hold the source data. memcpy(mac_iv, iv, 8); data/megatools-1.11.0~git20200404/lib/mega.c:978:2: [2] (buffer) memcpy: Does not check for buffer overflows when copying to destination (CWE-120). Make sure destination can always hold the source data. memcpy(mac_iv + 8, iv, 8); data/megatools-1.11.0~git20200404/lib/mega.c:994:2: [2] (buffer) memcpy: Does not check for buffer overflows when copying to destination (CWE-120). Make sure destination can always hold the source data. memcpy(mac->chunk_mac, mac->chunk_mac_iv, 16); data/megatools-1.11.0~git20200404/lib/mega.c:1055:3: [2] (buffer) memcpy: Does not check for buffer overflows when copying to destination (CWE-120). Make sure destination can always hold the source data. memcpy(mac_out, mac->meta_mac, 16); data/megatools-1.11.0~git20200404/lib/mega.c:1107:2: [2] (buffer) memcpy: Does not check for buffer overflows when copying to destination (CWE-120). Make sure destination can always hold the source data. memcpy(mac, iv, 8); data/megatools-1.11.0~git20200404/lib/mega.c:1108:2: [2] (buffer) memcpy: Does not check for buffer overflows when copying to destination (CWE-120). Make sure destination can always hold the source data. memcpy(mac + 8, iv, 8); data/megatools-1.11.0~git20200404/lib/mega.c:1974:3: [2] (buffer) memcpy: Does not check for buffer overflows when copying to destination (CWE-120). Make sure destination can always hold the source data. memcpy(aes_key, node_key, 16); data/megatools-1.11.0~git20200404/lib/mega.c:3267:2: [2] (buffer) memcpy: Does not check for buffer overflows when copying to destination (CWE-120). Make sure destination can always hold the source data. memcpy(iv, t->nonce, 8); data/megatools-1.11.0~git20200404/lib/mega.c:3298:15: [2] (integer) atoi: Unless checked, the resulting number can exceed the expected range (CWE-190). 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). int code = atoi(response->str); data/megatools-1.11.0~git20200404/lib/mega.c:3864:2: [2] (buffer) memcpy: Does not check for buffer overflows when copying to destination (CWE-120). Make sure destination can always hold the source data. memcpy(t.file_key, file_key, 16); data/megatools-1.11.0~git20200404/lib/mega.c:3865:2: [2] (buffer) memcpy: Does not check for buffer overflows when copying to destination (CWE-120). Make sure destination can always hold the source data. memcpy(t.nonce, nonce, 8); data/megatools-1.11.0~git20200404/lib/mega.c:3895:4: [2] (buffer) memcpy: Does not check for buffer overflows when copying to destination (CWE-120). Make sure destination can always hold the source data. memcpy(meta_mac, msg->meta_mac, 16); data/megatools-1.11.0~git20200404/lib/mega.c:4241:2: [2] (buffer) memcpy: Does not check for buffer overflows when copying to destination (CWE-120). Make sure destination can always hold the source data. memcpy(iv.nonce, nonce, 8); data/megatools-1.11.0~git20200404/lib/mega.c:4601:2: [2] (buffer) memcpy: Does not check for buffer overflows when copying to destination (CWE-120). Make sure destination can always hold the source data. memcpy(p.node_key, node->key, node->key_len); data/megatools-1.11.0~git20200404/lib/mega.c:4689:2: [2] (buffer) memcpy: Does not check for buffer overflows when copying to destination (CWE-120). Make sure destination can always hold the source data. memcpy(params->node_key, node_key, sizeof params->node_key); data/megatools-1.11.0~git20200404/lib/mega.c:4806:3: [2] (buffer) memcpy: Does not check for buffer overflows when copying to destination (CWE-120). Make sure destination can always hold the source data. memcpy(p, it->name, name_len); data/megatools-1.11.0~git20200404/lib/mega.c:5109:2: [2] (buffer) memcpy: Does not check for buffer overflows when copying to destination (CWE-120). Make sure destination can always hold the source data. memcpy(ts_data, ssc, 16); data/megatools-1.11.0~git20200404/lib/mega.c:5151:2: [2] (buffer) memcpy: Does not check for buffer overflows when copying to destination (CWE-120). Make sure destination can always hold the source data. memcpy(c_data, master_key, 16); data/megatools-1.11.0~git20200404/lib/mega.c:5169:2: [2] (buffer) memcpy: Does not check for buffer overflows when copying to destination (CWE-120). Make sure destination can always hold the source data. memcpy(st->password_key, password_key, 16); data/megatools-1.11.0~git20200404/lib/mega.c:5170:2: [2] (buffer) memcpy: Does not check for buffer overflows when copying to destination (CWE-120). Make sure destination can always hold the source data. memcpy(st->challenge, c_data + 16, 16); data/megatools-1.11.0~git20200404/lib/sjson.c:522:3: [2] (buffer) memcpy: Does not check for buffer overflows when copying to destination (CWE-120). Make sure destination can always hold the source data. memcpy(str, start, end - start); data/megatools-1.11.0~git20200404/lib/sjson.c:541:3: [2] (buffer) memcpy: Does not check for buffer overflows when copying to destination (CWE-120). Make sure destination can always hold the source data. memcpy(str, start, end - start); data/megatools-1.11.0~git20200404/lib/sjson.gen.c:958:3: [2] (buffer) memcpy: Does not check for buffer overflows when copying to destination (CWE-120). Make sure destination can always hold the source data. memcpy(str, start, end - start); data/megatools-1.11.0~git20200404/lib/sjson.gen.c:977:3: [2] (buffer) memcpy: Does not check for buffer overflows when copying to destination (CWE-120). Make sure destination can always hold the source data. memcpy(str, start, end - start); data/megatools-1.11.0~git20200404/lib/sjson.gen.c:3614:7: [2] (buffer) memcpy: Does not check for buffer overflows when copying to destination (CWE-120). Make sure destination can always hold the source data. memcpy(name, s + 1, c - (s + 1)); data/megatools-1.11.0~git20200404/lib/tools.c:369:3: [2] (buffer) char: Statically-sized arrays can be improperly restricted, leading to potential overflows or other issues (CWE-119!/CWE-120). Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length. char buf[256]; data/megatools-1.11.0~git20200404/tools/dl.c:146:19: [2] (integer) atoi: Unless checked, the resulting number can exceed the expected range (CWE-190). 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). nums[*count] = atoi(tokens[i]); data/megatools-1.11.0~git20200404/tools/reg.c:76:2: [2] (buffer) memcpy: Does not check for buffer overflows when copying to destination (CWE-120). Make sure destination can always hold the source data. memcpy(state->password_key, decoded_pk, 16); data/megatools-1.11.0~git20200404/tools/reg.c:85:2: [2] (buffer) memcpy: Does not check for buffer overflows when copying to destination (CWE-120). Make sure destination can always hold the source data. memcpy(state->challenge, decoded_ch, 16); data/megatools-1.11.0~git20200404/lib/mega.c:289:8: [1] (buffer) strlen: Does not handle strings that are not \0-terminated; if given one it may perform an over-read (it could cause a crash if unprotected) (CWE-126). shl = strlen(sh); data/megatools-1.11.0~git20200404/lib/mega.c:498:12: [1] (buffer) strlen: Does not handle strings that are not \0-terminated; if given one it may perform an over-read (it could cause a crash if unprotected) (CWE-126). str_len = strlen(str); data/megatools-1.11.0~git20200404/lib/mega.c:867:8: [1] (buffer) strlen: Does not handle strings that are not \0-terminated; if given one it may perform an over-read (it could cause a crash if unprotected) (CWE-126). len = strlen(password); data/megatools-1.11.0~git20200404/lib/mega.c:874:4: [1] (buffer) strncpy: Easily used incorrectly; doesn't always \0-terminate or check for invalid pointers [MS-banned] (CWE-120). strncpy(key, password + i, 16); // this is fine, we don't need a NUL termination here, stfu gcc8! data/megatools-1.11.0~git20200404/lib/mega.c:898:18: [1] (buffer) strlen: Does not handle strings that are not \0-terminated; if given one it may perform an over-read (it could cause a crash if unprotected) (CWE-126). for (i = 0, l = strlen(un); i < l; i++) data/megatools-1.11.0~git20200404/lib/mega.c:1415:55: [1] (buffer) strlen: Does not handle strings that are not \0-terminated; if given one it may perform an over-read (it could cause a crash if unprotected) (CWE-126). GString *res_str = http_post(s->http, url, req_node, strlen(req_node), &local_err); data/megatools-1.11.0~git20200404/lib/mega.c:1730:29: [1] (buffer) strlen: Does not handle strings that are not \0-terminated; if given one it may perform an over-read (it could cause a crash if unprotected) (CWE-126). gchar *sanepath = g_malloc(strlen(path) + 1); data/megatools-1.11.0~git20200404/lib/mega.c:1846:17: [1] (buffer) strlen: Does not handle strings that are not \0-terminated; if given one it may perform an over-read (it could cause a crash if unprotected) (CWE-126). if (!node_h || strlen(node_h) == 0) { data/megatools-1.11.0~git20200404/lib/mega.c:1885:17: [1] (buffer) strlen: Does not handle strings that are not \0-terminated; if given one it may perform an over-read (it could cause a crash if unprotected) (CWE-126). if (!node_a || strlen(node_a) == 0) { data/megatools-1.11.0~git20200404/lib/mega.c:1891:17: [1] (buffer) strlen: Does not handle strings that are not \0-terminated; if given one it may perform an over-read (it could cause a crash if unprotected) (CWE-126). if (!node_k || strlen(node_k) == 0) { data/megatools-1.11.0~git20200404/lib/mega.c:1897:17: [1] (buffer) strlen: Does not handle strings that are not \0-terminated; if given one it may perform an over-read (it could cause a crash if unprotected) (CWE-126). if (node_sk && strlen(node_sk) > 0) { data/megatools-1.11.0~git20200404/lib/mega.c:1901:7: [1] (buffer) strlen: Does not handle strings that are not \0-terminated; if given one it may perform an over-read (it could cause a crash if unprotected) (CWE-126). if (strlen(node_sk) > 22) { data/megatools-1.11.0~git20200404/lib/mega.c:1945:6: [1] (buffer) strlen: Does not handle strings that are not \0-terminated; if given one it may perform an over-read (it could cause a crash if unprotected) (CWE-126). if (strlen(encrypted_node_key) >= 46) { data/megatools-1.11.0~git20200404/lib/mega.c:2032:17: [1] (buffer) strlen: Does not handle strings that are not \0-terminated; if given one it may perform an over-read (it could cause a crash if unprotected) (CWE-126). if (!node_u || strlen(node_u) == 0) data/megatools-1.11.0~git20200404/lib/mega.c:2035:17: [1] (buffer) strlen: Does not handle strings that are not \0-terminated; if given one it may perform an over-read (it could cause a crash if unprotected) (CWE-126). if (!node_m || strlen(node_m) == 0) data/megatools-1.11.0~git20200404/lib/mega.c:2708:80: [1] (buffer) strlen: Does not handle strings that are not \0-terminated; if given one it may perform an over-read (it could cause a crash if unprotected) (CWE-126). if (g_str_has_prefix(path, data->path) && (data->recursive || !strchr(path + strlen(data->path), '/'))) data/megatools-1.11.0~git20200404/lib/mega.c:4797:19: [1] (buffer) strlen: Does not handle strings that are not \0-terminated; if given one it may perform an over-read (it could cause a crash if unprotected) (CWE-126). gint name_len = strlen(it->name); data/megatools-1.11.0~git20200404/lib/mega.c:5158:72: [1] (buffer) strlen: Does not handle strings that are not \0-terminated; if given one it may perform an over-read (it could cause a crash if unprotected) (CWE-126). b64_aes128_encrypt(c_data, 32, password_key), base64urlencode(name, strlen(name)), data/megatools-1.11.0~git20200404/lib/mega.c:5159:27: [1] (buffer) strlen: Does not handle strings that are not \0-terminated; if given one it may perform an over-read (it could cause a crash if unprotected) (CWE-126). base64urlencode(email, strlen(email))); data/megatools-1.11.0~git20200404/lib/sjson.c:586:22: [1] (buffer) strlen: Does not handle strings that are not \0-terminated; if given one it may perform an over-read (it could cause a crash if unprotected) (CWE-126). return rs == 0 ? strlen(c_str) == json_len : FALSE; data/megatools-1.11.0~git20200404/lib/sjson.c:962:37: [1] (buffer) strlen: Does not handle strings that are not \0-terminated; if given one it may perform an over-read (it could cause a crash if unprotected) (CWE-126). GString* str = g_string_sized_new(strlen(format)); data/megatools-1.11.0~git20200404/lib/sjson.c:1078:28: [1] (buffer) strlen: Does not handle strings that are not \0-terminated; if given one it may perform an over-read (it could cause a crash if unprotected) (CWE-126). str = g_string_sized_new(strlen(json) * 2); data/megatools-1.11.0~git20200404/lib/sjson.c:1249:37: [1] (buffer) strlen: Does not handle strings that are not \0-terminated; if given one it may perform an over-read (it could cause a crash if unprotected) (CWE-126). GString* str = g_string_sized_new(strlen(json)); data/megatools-1.11.0~git20200404/lib/sjson.gen.c:1022:22: [1] (buffer) strlen: Does not handle strings that are not \0-terminated; if given one it may perform an over-read (it could cause a crash if unprotected) (CWE-126). return rs == 0 ? strlen(c_str) == json_len : FALSE; data/megatools-1.11.0~git20200404/lib/sjson.gen.c:1488:37: [1] (buffer) strlen: Does not handle strings that are not \0-terminated; if given one it may perform an over-read (it could cause a crash if unprotected) (CWE-126). GString* str = g_string_sized_new(strlen(format)); data/megatools-1.11.0~git20200404/lib/sjson.gen.c:3217:28: [1] (buffer) strlen: Does not handle strings that are not \0-terminated; if given one it may perform an over-read (it could cause a crash if unprotected) (CWE-126). str = g_string_sized_new(strlen(json) * 2); data/megatools-1.11.0~git20200404/lib/sjson.gen.c:3646:37: [1] (buffer) strlen: Does not handle strings that are not \0-terminated; if given one it may perform an over-read (it could cause a crash if unprotected) (CWE-126). GString* str = g_string_sized_new(strlen(json)); data/megatools-1.11.0~git20200404/lib/tools.c:374:13: [1] (buffer) strlen: Does not handle strings that are not \0-terminated; if given one it may perform an over-read (it could cause a crash if unprotected) (CWE-126). int len = strlen(buf); data/megatools-1.11.0~git20200404/lib/tools.c:410:7: [1] (buffer) strlen: Does not handle strings that are not \0-terminated; if given one it may perform an over-read (it could cause a crash if unprotected) (CWE-126). if (strlen(buf) > 1) { data/megatools-1.11.0~git20200404/tools/dl.c:197:14: [1] (buffer) strlen: Does not handle strings that are not \0-terminated; if given one it may perform an over-read (it could cause a crash if unprotected) (CWE-126). int pos = strlen(path1); data/megatools-1.11.0~git20200404/tools/dl.c:204:14: [1] (buffer) strlen: Does not handle strings that are not \0-terminated; if given one it may perform an over-read (it could cause a crash if unprotected) (CWE-126). int pos = strlen(path2); data/megatools-1.11.0~git20200404/tools/shell.c:57:16: [1] (buffer) strlen: Does not handle strings that are not \0-terminated; if given one it may perform an over-read (it could cause a crash if unprotected) (CWE-126). cmd_basename[strlen(cmd_basename) - 4] = '\0'; ANALYSIS SUMMARY: Hits = 75 Lines analyzed = 15031 in approximately 0.32 seconds (47714 lines/second) Physical Source Lines of Code (SLOC) = 11360 Hits@level = [0] 5 [1] 32 [2] 36 [3] 4 [4] 3 [5] 0 Hits@level+ = [0+] 80 [1+] 75 [2+] 43 [3+] 7 [4+] 3 [5+] 0 Hits/KSLOC@level+ = [0+] 7.04225 [1+] 6.60211 [2+] 3.78521 [3+] 0.616197 [4+] 0.264085 [5+] 0 Dot directories skipped = 1 (--followdotdir overrides) Minimum risk level = 1 Not every hit is necessarily a security vulnerability. There may be other security vulnerabilities; review your code! See 'Secure Programming HOWTO' (https://dwheeler.com/secure-programs) for more information.