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/kpty-5.74.0/autotests/kptyprocesstest.h Examining data/kpty-5.74.0/autotests/kptyprocesstest.cpp Examining data/kpty-5.74.0/src/kptyprocess.cpp Examining data/kpty-5.74.0/src/kptydevice.cpp Examining data/kpty-5.74.0/src/kptydevice.h Examining data/kpty-5.74.0/src/kpty.h Examining data/kpty-5.74.0/src/kptyprocess.h Examining data/kpty-5.74.0/src/kpty_p.h Examining data/kpty-5.74.0/src/kpty.cpp Examining data/kpty-5.74.0/src/kgrantpty.c FINAL RESULTS: data/kpty-5.74.0/src/kgrantpty.c:173:9: [5] (race) chown: This accepts filename arguments; if an attacker can move those files, a race condition results. (CWE-362). Use fchown( ) instead. if (chown(tty, uid, gid) < 0) { data/kpty-5.74.0/src/kgrantpty.c:178:9: [5] (race) chmod: This accepts filename arguments; if an attacker can move those files, a race condition results. (CWE-362). Use fchmod( ) instead. if (chmod(tty, mod) < 0) { data/kpty-5.74.0/src/kpty.cpp:299:25: [5] (race) chown: This accepts filename arguments; if an attacker can move those files, a race condition results. (CWE-362). Use fchown( ) instead. chown(d->ttyName.data(), getuid(), gid); data/kpty-5.74.0/src/kpty.cpp:300:25: [5] (race) chmod: This accepts filename arguments; if an attacker can move those files, a race condition results. (CWE-362). Use fchmod( ) instead. chmod(d->ttyName.data(), S_IRUSR | S_IWUSR | S_IWGRP); data/kpty-5.74.0/src/kpty.cpp:461:21: [5] (race) chown: This accepts filename arguments; if an attacker can move those files, a race condition results. (CWE-362). Use fchown( ) instead. chown(d->ttyName.data(), 0, st.st_gid == getgid() ? 0 : -1); data/kpty-5.74.0/src/kpty.cpp:462:21: [5] (race) chmod: This accepts filename arguments; if an attacker can move those files, a race condition results. (CWE-362). Use fchmod( ) instead. chmod(d->ttyName.data(), S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); data/kpty-5.74.0/src/kgrantpty.c:121:29: [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(pty, _PATH_DEV); data/kpty-5.74.0/src/kgrantpty.c:122:29: [4] (buffer) strcat: Does not check for buffer overflows when concatenating to destination [MS-banned] (CWE-120). Consider using strcat_s, strncat, strlcat, or snprintf (warning: strncat is easily misused). strcat(pty, dirp->d_name); data/kpty-5.74.0/src/kgrantpty.c:146:9: [4] (buffer) strcat: Does not check for buffer overflows when concatenating to destination [MS-banned] (CWE-120). Consider using strcat_s, strncat, strlcat, or snprintf (warning: strncat is easily misused). strcat(tty, pty + 8); data/kpty-5.74.0/src/kpty.cpp:274:33: [4] (format) sprintf: Potential format string problem (CWE-134). Make format string constant. ptyName = QString().sprintf("/dev/pty%c%c", *s3, *s4).toLatin1(); data/kpty-5.74.0/src/kpty.cpp:275:36: [4] (format) sprintf: Potential format string problem (CWE-134). Make format string constant. d->ttyName = QString().sprintf("/dev/tty%c%c", *s3, *s4).toLatin1(); data/kpty-5.74.0/src/kpty.cpp:291:22: [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(d->ttyName.data(), R_OK | W_OK)) { // checks availability based on permission bits data/kpty-5.74.0/src/kgrantpty.c:63: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 ttyb[32]; data/kpty-5.74.0/src/kgrantpty.c:81:10: [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). fd = atoi(argv[2]); data/kpty-5.74.0/src/kgrantpty.c:89: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(ttyb, "/dev/pts/%d", ptyno); data/kpty-5.74.0/src/kgrantpty.c:145:9: [2] (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). Risk is low because the source is a constant string. strcpy(tty, "/dev/tty"); data/kpty-5.74.0/src/kpty.cpp:195:12: [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). bool KPty::open() data/kpty-5.74.0/src/kpty.cpp:216: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 ptsn[PATH_MAX]; data/kpty-5.74.0/src/kpty.cpp:244: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). # error No method to open a PTY master detected. data/kpty-5.74.0/src/kpty.cpp:254:13: [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[32]; data/kpty-5.74.0/src/kpty.cpp:255:13: [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(buf, "/dev/pts/%d", ptyno); data/kpty-5.74.0/src/kpty.cpp:374:12: [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). bool KPty::open(int fd) data/kpty-5.74.0/src/kpty.cpp:396: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 buf[32]; data/kpty-5.74.0/src/kpty.cpp:397: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(buf, "/dev/pts/%d", ptyno); data/kpty-5.74.0/src/kpty.h:49: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). bool open(); data/kpty-5.74.0/src/kpty.h:59: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). bool open(int fd); data/kpty-5.74.0/src/kptydevice.cpp:150:9: [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(reserve(len), data, len); data/kpty-5.74.0/src/kptydevice.cpp:199:13: [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 + readSoFar, ptr, bs); data/kpty-5.74.0/src/kptydevice.cpp:460: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). q->QIODevice::open(mode); data/kpty-5.74.0/src/kptydevice.cpp:485:18: [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). bool KPtyDevice::open(OpenMode mode) data/kpty-5.74.0/src/kptydevice.cpp:493:16: [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 (!KPty::open()) { data/kpty-5.74.0/src/kptydevice.cpp:503:18: [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). bool KPtyDevice::open(int fd, OpenMode mode) data/kpty-5.74.0/src/kptydevice.cpp:507:16: [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 (!KPty::open(fd)) { data/kpty-5.74.0/src/kptydevice.h:50: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). bool open(OpenMode mode = ReadWrite | Unbuffered) override; data/kpty-5.74.0/src/kptydevice.h:65: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). bool open(int fd, OpenMode mode = ReadWrite | Unbuffered); data/kpty-5.74.0/src/kptyprocess.cpp:46:13: [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). d->pty->open(); data/kpty-5.74.0/src/kptyprocess.cpp:57:13: [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). d->pty->open(ptyMasterFd); data/kpty-5.74.0/src/kgrantpty.c:119:58: [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). pty = malloc(sizeof(_PATH_DEV) + strlen(dirp->d_name)); data/kpty-5.74.0/src/kgrantpty.c:144: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). tty = malloc(strlen(pty) + 1); data/kpty-5.74.0/src/kpty.cpp:530:9: [1] (buffer) strncpy: Easily used incorrectly; doesn't always \0-terminate or check for invalid pointers [MS-banned] (CWE-120). strncpy(l_struct.ut_name, user, sizeof(l_struct.ut_name)); data/kpty-5.74.0/src/kpty.cpp:534:9: [1] (buffer) strncpy: Easily used incorrectly; doesn't always \0-terminate or check for invalid pointers [MS-banned] (CWE-120). strncpy(l_struct.ut_host, remotehost, sizeof(l_struct.ut_host)); data/kpty-5.74.0/src/kpty.cpp:536:35: [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). l_struct.ut_syslen = qMin(strlen(remotehost), sizeof(l_struct.ut_host)); data/kpty-5.74.0/src/kpty.cpp:546:5: [1] (buffer) strncpy: Easily used incorrectly; doesn't always \0-terminate or check for invalid pointers [MS-banned] (CWE-120). strncpy(l_struct.ut_line, str_ptr, sizeof(l_struct.ut_line)); data/kpty-5.74.0/src/kpty.cpp:548:5: [1] (buffer) strncpy: Easily used incorrectly; doesn't always \0-terminate or check for invalid pointers [MS-banned] (CWE-120). strncpy(l_struct.ut_id, data/kpty-5.74.0/src/kpty.cpp:549:23: [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_ptr + strlen(str_ptr) - sizeof(l_struct.ut_id), data/kpty-5.74.0/src/kpty.cpp:638:5: [1] (buffer) strncpy: Easily used incorrectly; doesn't always \0-terminate or check for invalid pointers [MS-banned] (CWE-120). strncpy(l_struct.ut_line, str_ptr, sizeof(l_struct.ut_line)); data/kpty-5.74.0/src/kptydevice.cpp:192:9: [1] (buffer) read: Check buffer boundaries if used in a loop including recursive loops (CWE-120, CWE-20). int read(char *data, int maxLength) data/kpty-5.74.0/src/kptydevice.cpp:208:16: [1] (buffer) read: Check buffer boundaries if used in a loop including recursive loops (CWE-120, CWE-20). return read(data, lineSize(qMin(maxLength, size()))); data/kpty-5.74.0/src/kptydevice.cpp:281:32: [1] (buffer) read: Check buffer boundaries if used in a loop including recursive loops (CWE-120, CWE-20). NO_INTR(readBytes, read(q->masterFd(), &c, 0)); data/kpty-5.74.0/src/kptydevice.cpp:306:32: [1] (buffer) read: Check buffer boundaries if used in a loop including recursive loops (CWE-120, CWE-20). NO_INTR(readBytes, read(q->masterFd(), ptr, available)); data/kpty-5.74.0/src/kptydevice.cpp:590:26: [1] (buffer) read: Check buffer boundaries if used in a loop including recursive loops (CWE-120, CWE-20). return d->readBuffer.read(data, (int)qMin<qint64>(maxlen, KMAXINT)); ANALYSIS SUMMARY: Hits = 51 Lines analyzed = 2438 in approximately 0.15 seconds (16422 lines/second) Physical Source Lines of Code (SLOC) = 1603 Hits@level = [0] 7 [1] 14 [2] 25 [3] 0 [4] 6 [5] 6 Hits@level+ = [0+] 58 [1+] 51 [2+] 37 [3+] 12 [4+] 12 [5+] 6 Hits/KSLOC@level+ = [0+] 36.1822 [1+] 31.8153 [2+] 23.0817 [3+] 7.48596 [4+] 7.48596 [5+] 3.74298 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.