alpine 3.6
buffer weakness #210

5

Weakness Breakdown


Definition:

Buffer overflows are one of the most well-known software vulnerabilities. Even though most developers know what buffer overflows are, attacks against the vulnerabilities are common in both legacy and newer applications. A classic buffer overflow exploit begins with the attacker sending data to a program, which it then stores in an undersized stack buffer. Besides stack buffer overflows, other kinds of buffer overflows include heap overflows, off-by-one errors and many others. Learn more about buffer overflows on OWASP attack index.

Warning code(s):

Easily used incorrectly.

File Name:

sg3_utils/src/sg3_utils-1.42/src/sg_map26.c

Context:

The highlighted line of code below is the trigger point of this particular Alpine 3.6 buffer weakness.

         case DT_BLK:
                if (FT_BLOCK != nd_match.file_type)
                        return 0;
                break;
        case DT_CHR:
                if (FT_CHAR != nd_match.file_type)
                        return 0;
                break;
        case DT_DIR:
                return (FT_DIR == nd_match.file_type) ? 1 : 0;
        case DT_REG:
                return (FT_REGULAR == nd_match.file_type) ? 1 : 0;
        case DT_LNK:    /* follow symlinks */
                if (! nd_match.follow_symlink)
                        return 0;
                symlnk = 1;
                break;
        default:
                return 0;
        }
        if ((! symlnk) && (-1 == nd_match.majj) && (-1 == nd_match.minn))
                return 1;
        strncpy(name, nd_match.dir_name, NAME_LEN_MAX);
        strcat(name, "/");
        strncat(name, s->d_name, NAME_LEN_MAX);
        memset(&st, 0, sizeof(st));
        if (stat(name, &st) < 0)
                return 0;
        if (symlnk) {
                if (S_ISCHR(st.st_mode)) {
                        if (FT_CHAR != nd_match.file_type)
                                return 0;
                } else if (S_ISBLK(st.st_mode)) {
                        if (FT_BLOCK != nd_match.file_type)
                                return 0;
                } else
                        return 0;
        }
        return (((-1 == nd_match.majj) ||
                 ((unsigned)major(st.st_rdev) == (unsigned)nd_match.majj)) &&
                ((-1 == nd_match.minn) ||
                 ((unsigned)minor(st.st_rdev) == (unsigned)nd_match.minn)))
               ? 1 : 0;
}

static int
list_matching_nodes(const char * dir_name, int file_type, int majj, int minn,
                    int follow_symlink, int verbose)
{
        struct dirent ** namelist; 

The registered trademark Linux® is used pursuant to a sublicense from the Linux Foundation, the exclusive licensee of Linus Torvalds, owner of the mark on a world­wide basis.