SHA256
1
0
forked from pool/vsftpd

- Work on the filter patch and split out the normalisation of the

path to separate str function, currently commented out so I
  avoid huge diffing.
  * vsftpd-2.1.0-filter.patch

OBS-URL: https://build.opensuse.org/package/show/network/vsftpd?expand=0&rev=74
This commit is contained in:
Tomáš Chvátal 2015-03-23 19:57:06 +00:00 committed by Git OBS Bridge
parent de2ebfe3ec
commit c67fd3688c
2 changed files with 97 additions and 41 deletions

View File

@ -2,73 +2,75 @@ Index: vsftpd-3.0.2/ls.c
===================================================================
--- vsftpd-3.0.2.orig/ls.c
+++ vsftpd-3.0.2/ls.c
@@ -7,6 +7,7 @@
* Would you believe, code to handle directory listing.
*/
+#include <stdlib.h>
#include "ls.h"
#include "access.h"
#include "defs.h"
@@ -243,11 +244,42 @@ vsf_filename_passes_filter(const struct
struct mystr temp_str = INIT_MYSTR;
struct mystr brace_list_str = INIT_MYSTR;
struct mystr new_filter_str = INIT_MYSTR;
+ struct mystr normalize_filename_str = INIT_MYSTR;
+ const char *normname;
+ const char *path;
@@ -121,7 +121,10 @@ vsf_ls_populate_dir_list(struct mystr_li
if (!str_isempty(p_filter_str))
{
unsigned int iters = 0;
- if (!vsf_filename_passes_filter(&s_next_filename_str, p_filter_str,
+ static struct mystr normalize_filename_str;
+ str_copy(&normalize_filename_str, &s_next_filename_str);
+ //str_normalize_filepath(&normalize_filename_str);
+ if (!vsf_filename_passes_filter(&normalize_filename_str, p_filter_str,
&iters))
{
continue;
@@ -246,8 +249,30 @@ vsf_filename_passes_filter(const struct
int ret = 0;
char last_token = 0;
int must_match_at_current_pos = 1;
+
+
str_copy(&filter_remain_str, p_filter_str);
- str_copy(&name_remain_str, p_filename_str);
+
+ /* normalize filepath */
+ path = str_strdup(p_filename_str);
+ normname = realpath(path, NULL);
+ if (normname == NULL)
+ goto out;
+ str_alloc_text(&normalize_filename_str, normname);
+
+ if (!str_isempty (&filter_remain_str) && !str_isempty(&normalize_filename_str)) {
+ if (!str_isempty (&filter_remain_str) && !str_isempty(p_filename_str)) {
+ if (str_get_char_at(p_filter_str, 0) == '/') {
+ if (str_get_char_at(&normalize_filename_str, 0) != '/') {
+ if (str_get_char_at(p_filename_str, 0) != '/') {
+ str_getcwd (&name_remain_str);
+
+ if (str_getlen(&name_remain_str) > 1) /* cwd != root dir */
+ str_append_char (&name_remain_str, '/');
+
+ str_append_str (&name_remain_str, &normalize_filename_str);
+ str_append_str (&name_remain_str, p_filename_str);
+ }
+ else
+ str_copy (&name_remain_str, &normalize_filename_str);
+ str_copy (&name_remain_str, p_filename_str);
+ } else {
+ if (str_get_char_at(p_filter_str, 0) != '{')
+ str_basename (&name_remain_str, &normalize_filename_str);
+ str_basename (&name_remain_str, p_filename_str);
+ else
+ str_copy (&name_remain_str, &normalize_filename_str);
+ str_copy (&name_remain_str, p_filename_str);
+ }
+ } else
+ str_copy(&name_remain_str, &normalize_filename_str);
+ str_copy(&name_remain_str, p_filename_str);
while (!str_isempty(&filter_remain_str) && *iters < VSFTP_MATCHITERS_MAX)
{
@@ -360,6 +392,9 @@ vsf_filename_passes_filter(const struct
ret = 0;
}
out:
+ free(normname);
+ free(path);
+ str_free(&normalize_filename_str);
str_free(&filter_remain_str);
str_free(&name_remain_str);
str_free(&temp_str);
Index: vsftpd-3.0.2/str.c
===================================================================
--- vsftpd-3.0.2.orig/str.c
+++ vsftpd-3.0.2/str.c
@@ -770,3 +770,14 @@ str_replace_unprintable(struct mystr* p_
@@ -15,6 +15,10 @@
#define PRIVATE_HANDS_OFF_len len
#define PRIVATE_HANDS_OFF_alloc_bytes alloc_bytes
#include "str.h"
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <libgen.h>
/* Ick. Its for die() */
#include "utility.h"
@@ -479,7 +483,7 @@ str_split_text_common(struct mystr* p_sr
if (indexx + search_len > p_src->len)
{
bug("indexx invalid in str_split_text");
- }
+ }
/* Build rhs */
private_str_alloc_memchunk(p_rhs, p_src->p_buf + indexx + search_len,
p_src->len - indexx - search_len);
@@ -770,3 +774,59 @@ str_replace_unprintable(struct mystr* p_
}
}
@ -83,15 +85,61 @@ Index: vsftpd-3.0.2/str.c
+ if (str_isempty(d_str))
+ str_copy (d_str, path);
+}
+
+void
+str_normalize_filepath(struct mystr* filepath)
+{
+ char *path;
+ char *normdir;
+ char *dir;
+ char *filename;
+ static struct mystr tmp;
+
+ /* normalize filepath */
+ path = str_strdup(filepath);
+ char *ch1 = strdup(path);
+ char *ch2 = strdup(path);
+ /* we split dir/file as realpath /home/REGEXP is NULL so we need dir
+ * dir only to function correctly, later on we need to glue back the
+ * file if there is some
+ */
+ dir = dirname(ch1);
+ filename = basename(ch2);
+ normdir = realpath(dir, NULL);
+ if (normdir == NULL)
+ {
+ goto out;
+ }
+ str_alloc_text(&tmp, normdir);
+ /* / is special it ends in both dirname and basename so ignore it here */
+ unsigned int len = str_getlen(&tmp);
+ if (str_get_char_at(&tmp, len - 1) != '/')
+ {
+ str_append_char(&tmp, '/');
+ }
+ /* / is special it ends in both dirname and basename so ignore it here */
+ if (strcmp(filename, "/") != 0)
+ {
+ str_append_text(&tmp, filename);
+ }
+ str_copy(filepath, &tmp);
+out:
+ free(normdir);
+ free(path);
+ free(ch1);
+ free(ch2);
+ str_free(&tmp);
+}
Index: vsftpd-3.0.2/str.h
===================================================================
--- vsftpd-3.0.2.orig/str.h
+++ vsftpd-3.0.2/str.h
@@ -101,6 +101,7 @@ void str_replace_unprintable(struct myst
@@ -101,6 +101,8 @@ void str_replace_unprintable(struct myst
int str_atoi(const struct mystr* p_str);
filesize_t str_a_to_filesize_t(const struct mystr* p_str);
unsigned int str_octal_to_uint(const struct mystr* p_str);
+void str_basename (struct mystr* d_str, const struct mystr* path);
+void str_normalize_filepath(struct mystr* filepath);
/* PURPOSE: Extract a line of text (delimited by \n or EOF) from a string
* buffer, starting at character position 'p_pos'. The extracted line will

View File

@ -1,3 +1,11 @@
-------------------------------------------------------------------
Mon Mar 23 19:56:11 UTC 2015 - tchvatal@suse.com
- Work on the filter patch and split out the normalisation of the
path to separate str function, currently commented out so I
avoid huge diffing.
* vsftpd-2.1.0-filter.patch
-------------------------------------------------------------------
Fri Feb 20 12:13:42 UTC 2015 - tchvatal@suse.com