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/olpc-powerd-23/olpc-switchd.c Examining data/olpc-powerd-23/pnmto565fb.c FINAL RESULTS: data/olpc-powerd-23/olpc-switchd.c:132:9: [4] (format) vfprintf: If format strings can be influenced by an attacker, they can be exploited (CWE-134). Use a constant for the format specification. vfprintf(stderr, fmt, ap); data/olpc-powerd-23/olpc-switchd.c:149:5: [4] (format) vfprintf: If format strings can be influenced by an attacker, they can be exploited (CWE-134). Use a constant for the format specification. vfprintf(stderr, fmt, ap); data/olpc-powerd-23/olpc-switchd.c:164:9: [4] (format) vfprintf: If format strings can be influenced by an attacker, they can be exploited (CWE-134). Use a constant for the format specification. vfprintf(stderr, fmt, ap); data/olpc-powerd-23/olpc-switchd.c:476: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(was_status, status); data/olpc-powerd-23/pnmto565fb.c:77:5: [4] (format) vfprintf: If format strings can be influenced by an attacker, they can be exploited (CWE-134). Use a constant for the format specification. vfprintf(stderr, fmt, ap); data/olpc-powerd-23/pnmto565fb.c:92:5: [4] (format) vfprintf: If format strings can be influenced by an attacker, they can be exploited (CWE-134). Use a constant for the format specification. vfprintf(stderr, fmt, ap); data/olpc-powerd-23/olpc-switchd.c:581:17: [3] (buffer) getopt: 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 ((c = getopt(argc, argv, "fldXp:t:F:A:")) != -1) { data/olpc-powerd-23/pnmto565fb.c:444:17: [3] (buffer) getopt: 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 ((c = getopt(argc, argv, "ds:f:")) != -1) { data/olpc-powerd-23/olpc-switchd.c:200: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 devname[128]; data/olpc-powerd-23/olpc-switchd.c:201: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[32]; data/olpc-powerd-23/olpc-switchd.c:206:20: [2] (misc) open: 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). if ((dfd = open(devname, O_RDONLY)) < 0) data/olpc-powerd-23/olpc-switchd.c:263:22: [2] (misc) open: 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). int fd = open(sysactive_path, O_RDWR | O_CREAT, data/olpc-powerd-23/olpc-switchd.c:283: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 evtbuf[128]; data/olpc-powerd-23/olpc-switchd.c:292:19: [2] (misc) open: 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). fifo_fd = open(output_fifo, O_WRONLY|O_NONBLOCK); data/olpc-powerd-23/olpc-switchd.c:397: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 buf[4]; data/olpc-powerd-23/olpc-switchd.c:398:10: [2] (misc) open: 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). fd = open("/sys/class/power_supply/olpc-ac/online", O_RDONLY); data/olpc-powerd-23/olpc-switchd.c:416: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 buf[4]; data/olpc-powerd-23/olpc-switchd.c:417:10: [2] (misc) open: 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). fd = open("/sys/class/power_supply/olpc-battery/capacity", O_RDONLY); data/olpc-powerd-23/olpc-switchd.c:429:12: [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). return atoi(buf); data/olpc-powerd-23/olpc-switchd.c:436:12: [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. static char buf[40]; data/olpc-powerd-23/olpc-switchd.c:437:10: [2] (misc) open: 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). fd = open("/sys/class/power_supply/olpc-battery/capacity", O_RDONLY); data/olpc-powerd-23/olpc-switchd.c:457:12: [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. static char was_status[20]; data/olpc-powerd-23/olpc-switchd.c:474:9: [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 evbuf[32]; data/olpc-powerd-23/olpc-switchd.c:524:17: [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 timeout[16]; data/olpc-powerd-23/pnmto565fb.c:118:14: [2] (misc) open: 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). fd = open("/sys/devices/platform/dcon/freeze", O_WRONLY); data/olpc-powerd-23/pnmto565fb.c:194: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 vtname[11]; data/olpc-powerd-23/pnmto565fb.c:197:15: [2] (misc) open: 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). if ((fd = open("/dev/tty0", O_WRONLY, 0)) < 0) data/olpc-powerd-23/pnmto565fb.c:205: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(vtname, "/dev/tty%d", vtno); /* /dev/tty1-64 */ data/olpc-powerd-23/pnmto565fb.c:206:22: [2] (misc) open: 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). if ((consolefd = open(vtname, O_RDWR | O_NDELAY, 0)) < 0) data/olpc-powerd-23/pnmto565fb.c:218:14: [2] (misc) open: 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). if ((i = open("/dev/tty", O_RDWR)) >= 0) { data/olpc-powerd-23/pnmto565fb.c:308:14: [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. unsigned char buf[256]; data/olpc-powerd-23/pnmto565fb.c:324:14: [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). fp = fopen(name, "r"); data/olpc-powerd-23/pnmto565fb.c:447:25: [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). sleeptime = atoi(optarg); data/olpc-powerd-23/pnmto565fb.c:479:10: [2] (misc) open: 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). fb = open(devfb, O_RDWR); data/olpc-powerd-23/olpc-switchd.c:319:9: [1] (buffer) read: Check buffer boundaries if used in a loop including recursive loops (CWE-120, CWE-20). if (read(pwr_fd, ev, sizeof(ev)) != sizeof(ev)) data/olpc-powerd-23/olpc-switchd.c:335:9: [1] (buffer) read: Check buffer boundaries if used in a loop including recursive loops (CWE-120, CWE-20). if (read(lid_fd, ev, sizeof(ev)) != sizeof(ev)) data/olpc-powerd-23/olpc-switchd.c:355:9: [1] (buffer) read: Check buffer boundaries if used in a loop including recursive loops (CWE-120, CWE-20). if (read(ebk_fd, ev, sizeof(ev)) != sizeof(ev)) data/olpc-powerd-23/olpc-switchd.c:375:9: [1] (buffer) read: Check buffer boundaries if used in a loop including recursive loops (CWE-120, CWE-20). if (read(acpwr_fd, ev, sizeof(ev)) != sizeof(ev)) data/olpc-powerd-23/olpc-switchd.c:402:9: [1] (buffer) read: Check buffer boundaries if used in a loop including recursive loops (CWE-120, CWE-20). r = read(fd, buf, 1); data/olpc-powerd-23/olpc-switchd.c:421:9: [1] (buffer) read: Check buffer boundaries if used in a loop including recursive loops (CWE-120, CWE-20). r = read(fd, buf, 2); data/olpc-powerd-23/olpc-switchd.c:441:9: [1] (buffer) read: Check buffer boundaries if used in a loop including recursive loops (CWE-120, CWE-20). r = read(fd, buf, sizeof(buf)); data/olpc-powerd-23/pnmto565fb.c:124:5: [1] (obsolete) usleep: This C routine is considered obsolete (as opposed to the shell command by the same name). The interaction of this function with SIGALRM and other timer functions such as sleep(), alarm(), setitimer(), and nanosleep() is unspecified (CWE-676). Use nanosleep(2) or setitimer(2) instead. usleep(50000); data/olpc-powerd-23/pnmto565fb.c:162:9: [1] (obsolete) usleep: This C routine is considered obsolete (as opposed to the shell command by the same name). The interaction of this function with SIGALRM and other timer functions such as sleep(), alarm(), setitimer(), and nanosleep() is unspecified (CWE-676). Use nanosleep(2) or setitimer(2) instead. usleep(100000); data/olpc-powerd-23/pnmto565fb.c:339:20: [1] (buffer) fgetc: Check buffer boundaries if used in a loop including recursive loops (CWE-120, CWE-20). while (c = fgetc(fp), c == '#') { ANALYSIS SUMMARY: Hits = 44 Lines analyzed = 1184 in approximately 0.06 seconds (20572 lines/second) Physical Source Lines of Code (SLOC) = 887 Hits@level = [0] 22 [1] 10 [2] 26 [3] 2 [4] 6 [5] 0 Hits@level+ = [0+] 66 [1+] 44 [2+] 34 [3+] 8 [4+] 6 [5+] 0 Hits/KSLOC@level+ = [0+] 74.4081 [1+] 49.6054 [2+] 38.3315 [3+] 9.01917 [4+] 6.76437 [5+] 0 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.