Fix potential null dereference

This commit is contained in:
Dylan G
2020-12-24 22:53:46 +00:00
parent 1e5d09e85a
commit 7871225999

View File

@@ -975,8 +975,8 @@ redirect: // goto here if we need to redirect
if (*redirect_url == '/') // if relative URL
{
strcpy(new_url, url);
// this is good code, i promise
*(strchr(strchr(strchr(new_url, '/') + 1, '/') + 1, '/')) = '\0';
char * last_slash = strchr(strchr(strchr(new_url, '/') + 1, '/') + 1, '/');
if (last_slash) *last_slash = '\0'; // prevents a NULL deref in case the original domain was not /-delimited
strncat(new_url, redirect_url, 0x824 - strlen(new_url));
url = new_url;
}