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/procdump-1.1.1/include/CoreDumpWriter.h Examining data/procdump-1.1.1/include/Events.h Examining data/procdump-1.1.1/include/Handle.h Examining data/procdump-1.1.1/include/Logging.h Examining data/procdump-1.1.1/include/ProcDumpConfiguration.h Examining data/procdump-1.1.1/include/Procdump.h Examining data/procdump-1.1.1/include/Process.h Examining data/procdump-1.1.1/include/TriggerThreadProcs.h Examining data/procdump-1.1.1/src/Handle.c Examining data/procdump-1.1.1/src/Logging.c Examining data/procdump-1.1.1/src/Procdump.c Examining data/procdump-1.1.1/src/Process.c Examining data/procdump-1.1.1/src/CoreDumpWriter.c Examining data/procdump-1.1.1/src/Events.c Examining data/procdump-1.1.1/src/ProcDumpConfiguration.c Examining data/procdump-1.1.1/src/TriggerThreadProcs.c Examining data/procdump-1.1.1/tests/integration/ProcDumpTestApplication.c FINAL RESULTS: data/procdump-1.1.1/src/CoreDumpWriter.c:441:8: [4] (buffer) sprintf: Does not check for buffer overflows (CWE-120). Use sprintf_s, snprintf, or vsnprintf. if(sprintf(command, "gcore -o %s_%s_%s %d 2>&1", name, desc, date, pid) < 0){ data/procdump-1.1.1/src/CoreDumpWriter.c:448:8: [4] (buffer) sprintf: Does not check for buffer overflows (CWE-120). Use sprintf_s, snprintf, or vsnprintf. if(sprintf(coreDumpFileName, "%s_%s_%s.%d", name, desc, date, pid) < 0){ data/procdump-1.1.1/src/CoreDumpWriter.c:531:12: [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. if(access(coreDumpFileName, F_OK) != -1) { data/procdump-1.1.1/src/CoreDumpWriter.c:600:9: [4] (shell) execl: This causes a new program to execute and is difficult to use safely (CWE-78). try using a library call that implements the same functionality if available. execl("/bin/bash", "bash", "-c", command, (char *)NULL); // won't return data/procdump-1.1.1/src/Events.c:89:9: [4] (buffer) strcpy: Does not check for buffer overflows when copying to destination [MS-banned] (CWE-120). Consider using snprintf, strcpy_s, or strlcpy (warning: strncpy easily misused). strcpy(Event->Name, Name); data/procdump-1.1.1/src/Logging.c:32:19: [4] (format) vsnprintf: If format strings can be influenced by an attacker, they can be exploited, and note that sprintf variations do not always \0-terminate (CWE-134). Use a constant for the format specification. int argsLen = vsnprintf(NULL, 0, message, copy); data/procdump-1.1.1/src/Logging.c:40:5: [4] (buffer) sprintf: Does not check for buffer overflows (CWE-120). Use sprintf_s, snprintf, or vsnprintf. sprintf(trace, "[%s - %s]: ", timeBuff, LogLevelStrings[logLevel]); data/procdump-1.1.1/src/Logging.c:41:5: [4] (format) vsprintf: Potential format string problem (CWE-134). Make format string constant. vsprintf(trace+traceLen, message, args); data/procdump-1.1.1/src/CoreDumpWriter.c:107:23: [3] (buffer) getenv: Environment variables are untrustable input if they can be set by an attacker. They 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. prefixTmpFolder = getenv("TMPDIR"); data/procdump-1.1.1/src/ProcDumpConfiguration.c:201:27: [3] (buffer) getopt_long: Some older implementations do not protect against internal buffer overflows (CWE-120, CWE-20). Check implementation on installation, or limit the size of all string inputs. while ((next_option = getopt_long(argc, argv, short_options, long_options, &option_index)) != -1) { data/procdump-1.1.1/include/Events.h:38:5: [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 Name[MAX_EVENT_NAME]; data/procdump-1.1.1/src/CoreDumpWriter.c:101:5: [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 lineBuf[4096]; data/procdump-1.1.1/src/CoreDumpWriter.c:102:5: [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 tmpFolder[4096]; data/procdump-1.1.1/src/CoreDumpWriter.c:121:16: [2] (misc) fopen: Check when opening files - can an attacker redirect it (via symlinks), force the opening of special file type (e.g., device files), move things around to create a race condition, control its ancestors, or change its contents? (CWE-362). procFile = fopen("/proc/net/unix", "r"); data/procdump-1.1.1/src/CoreDumpWriter.c:317:21: [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(temp_buffer_cur, &dumpHeader, sizeof(struct IpcHeader)); data/procdump-1.1.1/src/CoreDumpWriter.c:321:21: [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(temp_buffer_cur, &dumpFileNameLen, sizeof(dumpFileNameLen)); data/procdump-1.1.1/src/CoreDumpWriter.c:324:21: [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(temp_buffer_cur, dumpFileNameW, dumpFileNameLen*sizeof(uint16_t)); data/procdump-1.1.1/src/CoreDumpWriter.c:328:21: [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(temp_buffer_cur, &dumpType, sizeof(unsigned int)); data/procdump-1.1.1/src/CoreDumpWriter.c:332:21: [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(temp_buffer_cur, &diagnostics, sizeof(unsigned int)); data/procdump-1.1.1/src/CoreDumpWriter.c:405:5: [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 date[DATE_LENGTH]; data/procdump-1.1.1/src/CoreDumpWriter.c:406:5: [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 command[BUFFER_LENGTH]; data/procdump-1.1.1/src/CoreDumpWriter.c:408:5: [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 lineBuffer[BUFFER_LENGTH]; data/procdump-1.1.1/src/CoreDumpWriter.c:409:5: [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 coreDumpFileName[BUFFER_LENGTH]; data/procdump-1.1.1/src/Events.c:84:9: [2] (buffer) sprintf: Does not check for buffer overflows (CWE-120). Use sprintf_s, snprintf, or vsnprintf. Risk is low because the source has a constant maximum length. sprintf(Event->Name, "Unnamed Event %d", ++unamedEventId); data/procdump-1.1.1/src/Logging.c:17:5: [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 timeBuff[64]; data/procdump-1.1.1/src/ProcDumpConfiguration.c:204:42: [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). self->ProcessId = (pid_t)atoi(optarg); data/procdump-1.1.1/src/ProcDumpConfiguration.c:213:43: [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). (self->CpuThreshold = atoi(optarg)) < 0 || self->CpuThreshold > MAXIMUM_CPU) { data/procdump-1.1.1/src/ProcDumpConfiguration.c:220:75: [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). if (!IsValidNumberArg(optarg) || (self->PollingInterval = atoi(optarg)) < 0 || self->PollingInterval < MIN_POLLING_INTERVAL) { data/procdump-1.1.1/src/ProcDumpConfiguration.c:228:46: [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). (self->ThreadThreshold = atoi(optarg)) < 0 ) { data/procdump-1.1.1/src/ProcDumpConfiguration.c:236:54: [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). (self->FileDescriptorThreshold = atoi(optarg)) < 0 ) { data/procdump-1.1.1/src/ProcDumpConfiguration.c:244:43: [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). (self->CpuThreshold = atoi(optarg)) < 0 || self->CpuThreshold > MAXIMUM_CPU) { data/procdump-1.1.1/src/ProcDumpConfiguration.c:254:46: [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). (self->MemoryThreshold = atoi(optarg)) < 0) { data/procdump-1.1.1/src/ProcDumpConfiguration.c:263:46: [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). (self->MemoryThreshold = atoi(optarg)) < 0) { data/procdump-1.1.1/src/ProcDumpConfiguration.c:272:53: [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). (self->NumberOfDumpsToCollect = atoi(optarg)) < 0) { data/procdump-1.1.1/src/ProcDumpConfiguration.c:280:47: [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). (self->ThresholdSeconds = atoi(optarg)) == 0) { data/procdump-1.1.1/src/ProcDumpConfiguration.c:342:5: [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 statFilePath[32]; data/procdump-1.1.1/src/ProcDumpConfiguration.c:345:5: [2] (buffer) sprintf: Does not check for buffer overflows (CWE-120). Use sprintf_s, snprintf, or vsnprintf. Risk is low because the source has a constant maximum length. sprintf(statFilePath, "/proc/%d/stat", self->ProcessId); data/procdump-1.1.1/src/ProcDumpConfiguration.c:346:16: [2] (misc) fopen: Check when opening files - can an attacker redirect it (via symlinks), force the opening of special file type (e.g., device files), move things around to create a race condition, control its ancestors, or change its contents? (CWE-362). FILE *fd = fopen(statFilePath, "r"); data/procdump-1.1.1/src/ProcDumpConfiguration.c:383:29: [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). pid_t procPid = atoi(nameList[i]->d_name); data/procdump-1.1.1/src/ProcDumpConfiguration.c:425:2: [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 procFilePath[32]; data/procdump-1.1.1/src/ProcDumpConfiguration.c:426:2: [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 fileBuffer[MAX_CMDLINE_LEN]; data/procdump-1.1.1/src/ProcDumpConfiguration.c:434:12: [2] (buffer) sprintf: Does not check for buffer overflows (CWE-120). Use sprintf_s, snprintf, or vsnprintf. Risk is low because the source has a constant maximum length. if(sprintf(procFilePath, "/proc/%d/cmdline", pid) < 0){ data/procdump-1.1.1/src/ProcDumpConfiguration.c:438:13: [2] (misc) fopen: Check when opening files - can an attacker redirect it (via symlinks), force the opening of special file type (e.g., device files), move things around to create a race condition, control its ancestors, or change its contents? (CWE-362). procFile = fopen(procFilePath, "r"); data/procdump-1.1.1/src/Process.c:16:5: [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 procFilePath[32]; data/procdump-1.1.1/src/Process.c:17:5: [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 fileBuffer[1024]; data/procdump-1.1.1/src/Process.c:26:8: [2] (buffer) sprintf: Does not check for buffer overflows (CWE-120). Use sprintf_s, snprintf, or vsnprintf. Risk is low because the source has a constant maximum length. if(sprintf(procFilePath, "/proc/%d/fdinfo", pid) < 0){ data/procdump-1.1.1/src/Process.c:52:8: [2] (buffer) sprintf: Does not check for buffer overflows (CWE-120). Use sprintf_s, snprintf, or vsnprintf. Risk is low because the source has a constant maximum length. if(sprintf(procFilePath, "/proc/%d/stat", pid) < 0){ data/procdump-1.1.1/src/Process.c:55:16: [2] (misc) fopen: Check when opening files - can an attacker redirect it (via symlinks), force the opening of special file type (e.g., device files), move things around to create a race condition, control its ancestors, or change its contents? (CWE-362). procFile = fopen(procFilePath, "r"); data/procdump-1.1.1/src/Process.c:73:24: [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). proc->pid = (pid_t)atoi(fileBuffer); data/procdump-1.1.1/src/CoreDumpWriter.c:76: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). ptr[strlen(ptr)-1]='\0'; data/procdump-1.1.1/src/CoreDumpWriter.c:114:9: [1] (buffer) strncpy: Easily used incorrectly; doesn't always \0-terminate or check for invalid pointers [MS-banned] (CWE-120). strncpy(tmpFolder, prefixTmpFolder, 4096); data/procdump-1.1.1/src/CoreDumpWriter.c:131:44: [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(strncmp(ptr, tmpFolder, strlen(tmpFolder)) == 0) data/procdump-1.1.1/src/CoreDumpWriter.c:134: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). *socketName = malloc(sizeof(char)*strlen(ptr)+1); data/procdump-1.1.1/src/CoreDumpWriter.c:137:61: [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). memset(*socketName, 0, sizeof(char)*strlen(ptr)+1); data/procdump-1.1.1/src/CoreDumpWriter.c:138:28: [1] (buffer) strncpy: Easily used incorrectly; doesn't always \0-terminate or check for invalid pointers [MS-banned] (CWE-120). if(strncpy(*socketName, ptr, sizeof(char)*strlen(ptr)+1)!=NULL) data/procdump-1.1.1/src/CoreDumpWriter.c:138:67: [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(strncpy(*socketName, ptr, sizeof(char)*strlen(ptr)+1)!=NULL) data/procdump-1.1.1/src/CoreDumpWriter.c:245:33: [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). dumpFileNameW = malloc((strlen(buffer)+1)*sizeof(uint16_t)); data/procdump-1.1.1/src/CoreDumpWriter.c:246:25: [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(int i=0; i<(strlen(buffer)+1); i++) data/procdump-1.1.1/src/CoreDumpWriter.c:283:13: [1] (buffer) strncpy: Easily used incorrectly; doesn't always \0-terminate or check for invalid pointers [MS-banned] (CWE-120). strncpy(addr.sun_path, socketName, sizeof(addr.sun_path)-1); data/procdump-1.1.1/src/CoreDumpWriter.c:291:50: [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). unsigned int dumpFileNameLen = ((strlen(dumpFileName)+1)); data/procdump-1.1.1/src/CoreDumpWriter.c:490:26: [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). lineLength = strlen(lineBuffer); // get # of characters read data/procdump-1.1.1/src/CoreDumpWriter.c:494:17: [1] (buffer) strncpy: Easily used incorrectly; doesn't always \0-terminate or check for invalid pointers [MS-banned] (CWE-120). strncpy(outputBuffer[i], lineBuffer, lineLength - 1); // trim newline off data/procdump-1.1.1/src/CoreDumpWriter.c:634:25: [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 (int i = 0; i < strlen(sanitizedProcessName); i++) data/procdump-1.1.1/src/Events.c:85: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). } else if (strlen(Name) >= MAX_EVENT_NAME) { data/procdump-1.1.1/src/Events.c:86:9: [1] (buffer) strncpy: Easily used incorrectly; doesn't always \0-terminate or check for invalid pointers [MS-banned] (CWE-120). strncpy(Event->Name, Name, MAX_EVENT_NAME); data/procdump-1.1.1/src/ProcDumpConfiguration.c:443: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(fileBuffer) == 0){ data/procdump-1.1.1/src/ProcDumpConfiguration.c:461:20: [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). charactersRead = strlen(fileBuffer); data/procdump-1.1.1/src/ProcDumpConfiguration.c:787: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). int strLen = strlen(arg); ANALYSIS SUMMARY: Hits = 68 Lines analyzed = 3554 in approximately 0.11 seconds (31243 lines/second) Physical Source Lines of Code (SLOC) = 2292 Hits@level = [0] 47 [1] 19 [2] 39 [3] 2 [4] 8 [5] 0 Hits@level+ = [0+] 115 [1+] 68 [2+] 49 [3+] 10 [4+] 8 [5+] 0 Hits/KSLOC@level+ = [0+] 50.1745 [1+] 29.6684 [2+] 21.3787 [3+] 4.363 [4+] 3.4904 [5+] 0 Dot directories skipped = 2 (--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.