Skip to content

Commit

Permalink
Merge pull request #38 from beetlebugorg/bugfix/url
Browse files Browse the repository at this point in the history
Bugfix image url issue
  • Loading branch information
JC authored Sep 3, 2021
2 parents 4e32a5e + 6c451cd commit 71c76d6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
AC_PREREQ(2.60)
AC_INIT(mod_dims, 3.3.25, [[email protected]])
AC_INIT(mod_dims, 3.3.26, [[email protected]])
AM_INIT_AUTOMAKE([no-define])
AC_CONFIG_SRCDIR([src/mod_dims.c])

Expand Down
23 changes: 17 additions & 6 deletions src/mod_dims.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
*/

#define MODULE_RELEASE "$Revision: $"
#define MODULE_VERSION "3.3.25"
#define MODULE_VERSION "3.3.26"

#include "mod_dims.h"
#include "util_md5.h"
Expand Down Expand Up @@ -1371,15 +1371,19 @@ dims_handle_request(dims_request_rec *d)
int found = 0, done = 0;

/* Check to make sure the URLs hostname is in the whitelist. Wildcards
* are handled by repeatedly checking the hash for a match after removing
* each part of the hostname until a match is found. If a match is found
* and it's value is set to "glob" the match will be accepted.
*/
* are handled by repeatedly checking the hash for a match after removing
* each part of the hostname until a match is found. If a match is found
* and it's value is set to "glob" the match will be accepted.
*/
if(apr_uri_parse(d->pool, d->image_url, &uri) != APR_SUCCESS) {
return dims_cleanup(d, "Invalid URL in request.", DIMS_BAD_URL);
}

char *filename = strrchr(uri.path, '/');
if (!filename || !uri.hostname) {
return dims_cleanup(d, "Invalid URL in request.", DIMS_BAD_URL);
}

if (*filename == '/') {
d->filename = ++filename;
}
Expand Down Expand Up @@ -1687,6 +1691,9 @@ dims_handler(request_rec *r)
fixed_url = apr_pstrdup(r->pool, token + 4);
ap_unescape_url(fixed_url);

if (strcmp(fixed_url, "") == 0) {
return dims_cleanup(d, NULL, DIMS_BAD_URL);
}
} else if (strncmp(token, "download=1", 10) == 0) {
d->send_content_disposition = 1;

Expand All @@ -1704,7 +1711,7 @@ dims_handler(request_rec *r)
// Convert to hex.
char hex[SHA_DIGEST_LENGTH * 2 + 1];
if (apr_escape_hex(hex, hash, SHA_DIGEST_LENGTH, 0, NULL) != APR_SUCCESS) {
return DIMS_FAILURE;
return dims_cleanup(d, NULL, DIMS_BAD_ARGUMENTS);
}

// Use first 16 bytes.
Expand Down Expand Up @@ -1769,6 +1776,10 @@ dims_handler(request_rec *r)
/* Calculate image filename for use with content disposition. */
apr_uri_t uri;
if (apr_uri_parse(r->pool, d->image_url, &uri) == APR_SUCCESS) {
if (!uri.path) {
return dims_cleanup(d, NULL, DIMS_BAD_URL);
}

const char *path = apr_filepath_name_get(uri.path);
d->content_disposition_filename = apr_pstrdup(d->r->pool, path);
}
Expand Down

0 comments on commit 71c76d6

Please sign in to comment.