Skip to main content
added 116 characters in body
Source Link
char* indexes(const char* path)
{
    // ensure path is readable and executable
    if (access(path, R_OK | X_OK) == -1)
    {
        error(403);
        return NULL;
 }
char *new_path = }
malloc(strlen(path) + 2);
strcpy (new_path, path);
char* path1 = malloc(6051);
    if (path1 == NULL)
    {
        return NULL;
    }
    strcpy(path1, pathnew_path);
    char* path2 = malloc(5052);
    if (path2 == NULL)
    {
        return NULL;
    }
    strcpy(path2, pathnew_path);
    strcat(path1, "index"/index.php");
    strcat(path2, "index"/index.html");
path1[strlen(new_path) + strlen("/index.php")] = '\0';
path2[strlen(new_path) + strlen("/index.html")] = '\0';
// check if index.htmlphp or index.phphtml exists and returns. elseElse returnsreturn NULL
    if (access(path1, R_OK) != -1)
    {
    free(path2);
    return path1;
    }
    else if (access(path2, R_OK) != -1)
    {
    free(path1);
    return path2;
    }
    else
{
    {free(path1);
    free(path2);
    return NULL;   
    }    
}
char* indexes(const char* path)
{
    // ensure path is readable and executable
    if (access(path, R_OK | X_OK) == -1)
    {
        error(403);
        return NULL;
    }
    char* path1 = malloc(60);
    if (path1 == NULL)
    {
        return NULL;
    }
    strcpy(path1, path);
    char* path2 = malloc(50);
    if (path2 == NULL)
    {
        return NULL;
    }
    strcpy(path2, path);
    strcat(path1, "index.php");
    strcat(path2, "index.html");
    // check if index.html or index.php exists and returns else returns NULL
    if (access(path1, R_OK) != -1)
    {
        return path1;
    }
    else if (access(path2, R_OK) != -1)
    {
        return path2;
    }
    else
    {
        return NULL;   
    }    
}
// ensure path is readable and executable
if (access(path, R_OK | X_OK) == -1)
{
    error(403);
    return NULL;
}
char *new_path = malloc(strlen(path) + 2);
strcpy (new_path, path);
char* path1 = malloc(51);
if (path1 == NULL)
{
    return NULL;
}
strcpy(path1, new_path);
char* path2 = malloc(52);
if (path2 == NULL)
{
    return NULL;
}
strcpy(path2, new_path);
strcat(path1, "/index.php");
strcat(path2, "/index.html");
path1[strlen(new_path) + strlen("/index.php")] = '\0';
path2[strlen(new_path) + strlen("/index.html")] = '\0';
// check if index.php or index.html exists and returns. Else return NULL
if (access(path1, R_OK) != -1)
{
    free(path2);
    return path1;
}
else if (access(path2, R_OK) != -1)
{
    free(path1);
    return path2;
}
else
{
    free(path1);
    free(path2);
    return NULL;   
}    
code formatting
Source Link
ChrisG
  • 7.4k
  • 2
  • 17
  • 26

I'm almost done with server.c but can't seem to find the last error which doesn't allow me to pass check50. I

I tried to analyse the existing responses to similar questions but couldn't use them to find my bug. Any help would be very much appreciated!

The errors I recievereceive are:

  1. :( Requesting cat.jpg returns 200, image/jpeg, and correct image
  2. :( Requesting /test/ outputs /test/index.html
  3. :( Requesting directory containing index.php outputs index.php
  4. :( Requesting two files in a row (cat.html then cat.jpg) succeeds
:( Requesting cat.jpg returns 200, image/jpeg, and correct image
:( Requesting /test/ outputs /test/index.html
:( Requesting directory containing index.php outputs index.php
:( Requesting two files in a row (cat.html then cat.jpg) succeeds

Load Function:load()

bool load(FILE* file, BYTE** content, size_t* length)
{
    *content = NULL;
    *length = 0;
    *content = malloc(512 * sizeof(BYTE));
    if (*content == NULL)
        {
            return false;
        }
    size_t size = fread(*content, sizeof(BYTE), 512, file);
    while (size > 0)
    {   
        *length += size;
        *content = realloc(*content, *length * sizeof(BYTE));
        if (*content == NULL)
        {
            return false;
        }
        size = fread(*content + *length, sizeof(BYTE), 512, file);
    }
    return true;
}
bool load(FILE* file, BYTE** content, size_t* length)
{
    *content = NULL;
    *length = 0;
    *content = malloc(512 * sizeof(BYTE));
    if (*content == NULL)
        {
            return false;
        }
    size_t size = fread(*content, sizeof(BYTE), 512, file);
    while (size > 0)
    {   
        *length += size;
        *content = realloc(*content, *length * sizeof(BYTE));
        if (*content == NULL)
        {
            return false;
        }
        size = fread(*content + *length, sizeof(BYTE), 512, file);
    }
    return true;
}
else if (strcasecmp(final, ".jpg") == 0)
    {
        mime = "image/jpeg";
    }
else if (strcasecmp(final, ".jpg") == 0)
{
    mime = "image/jpeg";
}

The error in Check50 is: \ expected an exit code of 0, not standard error of "======= Backtrace: =========\n======= M..." except

expected an exit code of 0, not standard error of "======= Backtrace: =========\n======= M..."

except for index.php where the error is: \ expected output, not standard error of "======= Backtrace: =========\n======= M..."

expected output, not standard error of "======= Backtrace: =========\n======= M..."
char* indexes(const char* path)
{
    // ensure path is readable and executable
    if (access(path, R_OK | X_OK) == -1)
    {
        error(403);
        return NULL;
    }
    char* path1 = malloc(60);
    if (path1 == NULL)
    {
        return NULL;
    }
    strcpy(path1, path);
    char* path2 = malloc(50);
    if (path2 == NULL)
    {
        return NULL;
    }
    strcpy(path2, path);
    strcat(path1, "index.php");
    strcat(path2, "index.html");
    // check if index.html or index.php exists and returns else returns NULL
    if (access(path1, R_OK) != -1)
    {
        return path1;
    }
    else if (access(path2, R_OK) != -1)
    {
        return path2;
    }
    else
    {
        return NULL;   
    }    
}
char* indexes(const char* path)
{
    // ensure path is readable and executable
    if (access(path, R_OK | X_OK) == -1)
    {
        error(403);
        return NULL;
    }
    char* path1 = malloc(60);
    if (path1 == NULL)
    {
        return NULL;
    }
    strcpy(path1, path);
    char* path2 = malloc(50);
    if (path2 == NULL)
    {
        return NULL;
    }
    strcpy(path2, path);
    strcat(path1, "index.php");
    strcat(path2, "index.html");
    // check if index.html or index.php exists and returns else returns NULL
    if (access(path1, R_OK) != -1)
    {
        return path1;
    }
    else if (access(path2, R_OK) != -1)
    {
        return path2;
    }
    else
    {
        return NULL;   
    }    
}

I'm almost done with server.c but can't seem to find the last error which doesn't allow me to pass check50. I tried to analyse the existing responses to similar questions but couldn't use them to find my bug. Any help would be very much appreciated!

The errors I recieve are:

  1. :( Requesting cat.jpg returns 200, image/jpeg, and correct image
  2. :( Requesting /test/ outputs /test/index.html
  3. :( Requesting directory containing index.php outputs index.php
  4. :( Requesting two files in a row (cat.html then cat.jpg) succeeds

Load Function:

bool load(FILE* file, BYTE** content, size_t* length)
{
    *content = NULL;
    *length = 0;
    *content = malloc(512 * sizeof(BYTE));
    if (*content == NULL)
        {
            return false;
        }
    size_t size = fread(*content, sizeof(BYTE), 512, file);
    while (size > 0)
    {   
        *length += size;
        *content = realloc(*content, *length * sizeof(BYTE));
        if (*content == NULL)
        {
            return false;
        }
        size = fread(*content + *length, sizeof(BYTE), 512, file);
    }
    return true;
}
else if (strcasecmp(final, ".jpg") == 0)
    {
        mime = "image/jpeg";
    }

The error in Check50 is: \ expected an exit code of 0, not standard error of "======= Backtrace: =========\n======= M..." except for index.php where the error is: \ expected output, not standard error of "======= Backtrace: =========\n======= M..."

char* indexes(const char* path)
{
    // ensure path is readable and executable
    if (access(path, R_OK | X_OK) == -1)
    {
        error(403);
        return NULL;
    }
    char* path1 = malloc(60);
    if (path1 == NULL)
    {
        return NULL;
    }
    strcpy(path1, path);
    char* path2 = malloc(50);
    if (path2 == NULL)
    {
        return NULL;
    }
    strcpy(path2, path);
    strcat(path1, "index.php");
    strcat(path2, "index.html");
    // check if index.html or index.php exists and returns else returns NULL
    if (access(path1, R_OK) != -1)
    {
        return path1;
    }
    else if (access(path2, R_OK) != -1)
    {
        return path2;
    }
    else
    {
        return NULL;   
    }    
}

I'm almost done with server.c but can't seem to find the last error which doesn't allow me to pass check50.

I tried to analyse the existing responses to similar questions but couldn't use them to find my bug. Any help would be very much appreciated!

The errors I receive are:

:( Requesting cat.jpg returns 200, image/jpeg, and correct image
:( Requesting /test/ outputs /test/index.html
:( Requesting directory containing index.php outputs index.php
:( Requesting two files in a row (cat.html then cat.jpg) succeeds

load()

bool load(FILE* file, BYTE** content, size_t* length)
{
    *content = NULL;
    *length = 0;
    *content = malloc(512 * sizeof(BYTE));
    if (*content == NULL)
        {
            return false;
        }
    size_t size = fread(*content, sizeof(BYTE), 512, file);
    while (size > 0)
    {   
        *length += size;
        *content = realloc(*content, *length * sizeof(BYTE));
        if (*content == NULL)
        {
            return false;
        }
        size = fread(*content + *length, sizeof(BYTE), 512, file);
    }
    return true;
}
else if (strcasecmp(final, ".jpg") == 0)
{
    mime = "image/jpeg";
}

The error in Check50 is:

expected an exit code of 0, not standard error of "======= Backtrace: =========\n======= M..."

except for index.php where the error is:

expected output, not standard error of "======= Backtrace: =========\n======= M..."
char* indexes(const char* path)
{
    // ensure path is readable and executable
    if (access(path, R_OK | X_OK) == -1)
    {
        error(403);
        return NULL;
    }
    char* path1 = malloc(60);
    if (path1 == NULL)
    {
        return NULL;
    }
    strcpy(path1, path);
    char* path2 = malloc(50);
    if (path2 == NULL)
    {
        return NULL;
    }
    strcpy(path2, path);
    strcat(path1, "index.php");
    strcat(path2, "index.html");
    // check if index.html or index.php exists and returns else returns NULL
    if (access(path1, R_OK) != -1)
    {
        return path1;
    }
    else if (access(path2, R_OK) != -1)
    {
        return path2;
    }
    else
    {
        return NULL;   
    }    
}
added 2 characters in body
Source Link

EDIT #1 My jpg convertion in the indexeslookup function: else if (strcasecmp(final, ".jpg") == 0) { mime = "image/jpeg"; }

else if (strcasecmp(final, ".jpg") == 0)
    {
        mime = "image/jpeg";
    }

EDIT #1 My jpg convertion in the indexes function: else if (strcasecmp(final, ".jpg") == 0) { mime = "image/jpeg"; }

EDIT #1 My jpg convertion in the lookup function:

else if (strcasecmp(final, ".jpg") == 0)
    {
        mime = "image/jpeg";
    }
added 1373 characters in body
Source Link
Loading
Source Link
Loading