diff --git a/core/utils.c b/core/utils.c index 26178757..20ce9202 100644 --- a/core/utils.c +++ b/core/utils.c @@ -1814,18 +1814,21 @@ void init_magic_table(char *magic_table[]) { } char *uwsgi_get_last_char(char *what, char c) { - int i; - char *ptr = NULL; - - for (i = 0; i < (int) strlen(what); i++) { - if (what[i] == c) { - ptr = what + i; - } + size_t len = strlen(what); + while(len--) { + if (what[len] == c) return what + len; } - - return ptr; + return NULL; } +char *uwsgi_get_last_charn(char *what, size_t len, char c) { + while(len--) { + if (what[len] == c) return what + len; + } + return NULL; +} + + char *uwsgi_num2str(int num) { char *str = uwsgi_malloc(11); diff --git a/plugins/webdav/webdav.c b/plugins/webdav/webdav.c index a4d9b031..cb7843cd 100644 --- a/plugins/webdav/webdav.c +++ b/plugins/webdav/webdav.c @@ -229,7 +229,7 @@ static size_t uwsgi_webdav_expand_path(struct wsgi_request *wsgi_req, char *item } static size_t uwsgi_webdav_expand_fake_path(struct wsgi_request *wsgi_req, char *item, uint16_t item_len, char *filename) { - char *last_slash = memrchr(item, '/', item_len); + char *last_slash = uwsgi_get_last_charn(item, item_len, '/'); if (!last_slash) return 0; size_t filename_len = uwsgi_webdav_expand_path(wsgi_req, item, last_slash - item, filename); if (!filename_len) return 0; @@ -704,7 +704,7 @@ next: if (de_r == NULL) break; // skip items startign with a dot if (de.d_name[0] == '.') continue; - if (uwsgi_webdav_dirlist_add_item(ub, de.d_name[0], strlen(de.d_name[0]), de.d_type == DT_DIR ? 1 : 0) goto end; + if (uwsgi_webdav_dirlist_add_item(ub, de.d_name, strlen(de.d_name), de.d_type == DT_DIR ? 1 : 0)) goto end; } closedir(d); diff --git a/uwsgi.h b/uwsgi.h index 29975c2b..abcd83f5 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -2808,6 +2808,7 @@ void uwsgi_gateway_go_cheap(char *, int, int *); char *uwsgi_open_and_read(char *, size_t *, int, char *[]); char *uwsgi_get_last_char(char *, char); +char *uwsgi_get_last_charn(char *, size_t, char); void uwsgi_spawn_daemon(struct uwsgi_daemon *); void uwsgi_detach_daemons();