Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

strcpy buffer overflow #1083

Closed
setharnold opened this issue Feb 21, 2018 · 0 comments
Closed

strcpy buffer overflow #1083

setharnold opened this issue Feb 21, 2018 · 0 comments
Labels
removed_components Issues that affect MJ2, JPWL or JP3D wontfix

Comments

@setharnold
Copy link
Contributor

strcpy(pgxfiles[0], relpath);

    char tmpdirpath[MAX_PATH];
    char dirpath[MAX_PATH];
    char pattern[MAX_PATH];
    char pgxfiles[MAX_SLICES][MAX_PATH];
    int pgxslicepos[MAX_SLICES];
    char tmpno[3];

    numcomps = 1;
    color_space = CLRSPC_GRAY;
    sliceno = 0;
    maxvalue = 0;
    memset(pgxfiles, 0, MAX_SLICES * MAX_PATH * sizeof(char));
    memset(&cmptparm, 0, sizeof(opj_volume_cmptparm_t));

    /* Separación del caso de un único slice frente al de muchos */
    if ((tmp = strrchr(relpath, '-')) == NULL) {
        /*fprintf(stdout,"[INFO] A volume of only one slice....\n");*/
        sliceno = 1;
        maxslice = 1;
        strcpy(pgxfiles[0], relpath);   /* XXX possible overflow */

    } else {
        /*Fetch only the path */
        strcpy(tmpdirpath, relpath);    /* XXX possible overflow */
        if ((tmp = strrchr(tmpdirpath, '/')) != NULL) {
            tmp++;
            *tmp = '\0';
            strcpy(dirpath, tmpdirpath);  /* XXX possible overflow */
        } else {
            strcpy(dirpath, "./");           /* XXX possible overflow */
}

Hello, note that the values I found for MAX_PATH (260) and OPJ_PATH_LEN (4096) allow overwriting the smaller buffer with data from the larger buffer. strncpy(3) is difficult enough to use correctly that I suspect a rewrite using sprintf(3) to be the safer approach. Rewriting to avoid the string manipulations might be safer still.

Consider breaking apart the filename and directory entry handling from the image handling in this function. That would make it easier to apply a fuzzer to just the image handling portion, and perhaps also to design test cases that work with the file and directory handling.

Thanks

@rouault rouault closed this as completed May 6, 2021
@rouault rouault added wontfix removed_components Issues that affect MJ2, JPWL or JP3D labels May 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
removed_components Issues that affect MJ2, JPWL or JP3D wontfix
Projects
None yet
Development

No branches or pull requests

2 participants