[SCM] Samba Shared Repository - branch master updated

Günther Deschner gd at samba.org
Fri Nov 13 17:48:04 UTC 2020


The branch, master has been updated
       via  a8ec8304917 s4-torture: test file_line_parse as well
       via  ae4dd2ab82e lib: Fix file_lines_parse() to do what people expect. Much safer to use.
       via  61f6672d8bb lib: create a wrapper for file_lines_parse().
      from  2ba6d596ff0 tests python krb5: add arcfour salt tests

https://git.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit a8ec83049176fdebe086be8c03c7d058c58f48d8
Author: Günther Deschner <gd at samba.org>
Date:   Tue Nov 10 17:10:27 2020 +0100

    s4-torture: test file_line_parse as well
    
    Guenther
    
    Signed-off-by: Guenther Deschner <gd at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>
    
    Autobuild-User(master): Günther Deschner <gd at samba.org>
    Autobuild-Date(master): Fri Nov 13 17:47:33 UTC 2020 on sn-devel-184

commit ae4dd2ab82eae1ddffbb00e7a753521a0879341b
Author: Jeremy Allison <jra at samba.org>
Date:   Tue Nov 10 13:52:01 2020 -0800

    lib: Fix file_lines_parse() to do what people expect. Much safer to use.
    
    Take an incoming const char * pointer and return an allocated
    array that must be freed. Don't expose the internal optimization
    of file_lines_parse_internal() breaking the passed in string
    into lines.
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Guenther Deschner <gd at samba.org>

commit 61f6672d8bbdbb6889be94591a7dbaeb55ab3d30
Author: Jeremy Allison <jra at samba.org>
Date:   Tue Nov 10 13:43:24 2020 -0800

    lib: create a wrapper for file_lines_parse().
    
    Make the internal function file_lines_parse_internal().
    
    Currently file_lines_parse() just wraps file_lines_parse_internal(),
    but this allows me to change file_lines_parse() to take
    a const char * to make it safe for callers (no talloc tricks).
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Guenther Deschner <gd at samba.org>

-----------------------------------------------------------------------

Summary of changes:
 lib/util/samba_util.h |  2 +-
 lib/util/tests/file.c | 31 +++++++++++++++++++++++++++++++
 lib/util/util_file.c  | 23 ++++++++++++++++++++---
 3 files changed, 52 insertions(+), 4 deletions(-)


Changeset truncated at 500 lines:

diff --git a/lib/util/samba_util.h b/lib/util/samba_util.h
index 5a81baa80b6..3a60b618083 100644
--- a/lib/util/samba_util.h
+++ b/lib/util/samba_util.h
@@ -394,7 +394,7 @@ load a file into memory from a fd.
 _PUBLIC_ char *fd_load(int fd, size_t *size, size_t maxsize, TALLOC_CTX *mem_ctx);
 
 
-char **file_lines_parse(char *p, size_t size, int *numlines, TALLOC_CTX *mem_ctx);
+char **file_lines_parse(const char *p, size_t size, int *numlines, TALLOC_CTX *mem_ctx);
 
 /**
 load a file into memory
diff --git a/lib/util/tests/file.c b/lib/util/tests/file.c
index 55c9d4cec9a..3501c7e135f 100644
--- a/lib/util/tests/file.c
+++ b/lib/util/tests/file.c
@@ -243,6 +243,34 @@ done:
 	return ret;
 }
 
+static bool test_file_lines_parse(struct torture_context *tctx)
+{
+	char **lines;
+	int numlines;
+	TALLOC_CTX *mem_ctx = tctx;
+	char *buf;
+	size_t size;
+
+	torture_assert(tctx, file_save(TEST_FILENAME,
+				       (const void *)TEST_DATA,
+				       strlen(TEST_DATA)),
+			"saving file");
+
+	buf = file_load(TEST_FILENAME, &size, 0, mem_ctx);
+	torture_assert(tctx, buf, "failed to load file");
+	unlink(TEST_FILENAME);
+
+	lines = file_lines_parse(buf,
+				 size,
+				 &numlines,
+				 mem_ctx);
+	torture_assert(tctx, lines, "failed to parse lines");
+
+	TALLOC_FREE(lines);
+	TALLOC_FREE(buf);
+	return true;
+}
+
 struct torture_suite *torture_local_util_file(TALLOC_CTX *mem_ctx)
 {
 	struct torture_suite *suite = torture_suite_create(mem_ctx, "file");
@@ -256,5 +284,8 @@ struct torture_suite *torture_local_util_file(TALLOC_CTX *mem_ctx)
 
 	torture_suite_add_simple_test(suite, "afdgets", test_afdgets);
 
+	torture_suite_add_simple_test(suite, "file_lines_parse",
+			test_file_lines_parse);
+
 	return suite;
 }
diff --git a/lib/util/util_file.c b/lib/util/util_file.c
index 0c890f9b5ea..af90e4a7621 100644
--- a/lib/util/util_file.c
+++ b/lib/util/util_file.c
@@ -253,7 +253,7 @@ _PUBLIC_ char *file_load(const char *fname, size_t *size, size_t maxsize, TALLOC
 parse a buffer into lines
 'p' will be freed on error, and otherwise will be made a child of the returned array
 **/
-char **file_lines_parse(char *p, size_t size, int *numlines, TALLOC_CTX *mem_ctx)
+static char **file_lines_parse_internal(char *p, size_t size, int *numlines, TALLOC_CTX *mem_ctx)
 {
 	unsigned int i;
 	char *s, **ret;
@@ -305,7 +305,7 @@ _PUBLIC_ char **file_lines_load(const char *fname, int *numlines, size_t maxsize
 	p = file_load(fname, &size, maxsize, mem_ctx);
 	if (!p) return NULL;
 
-	return file_lines_parse(p, size, numlines, mem_ctx);
+	return file_lines_parse_internal(p, size, numlines, mem_ctx);
 }
 
 /**
@@ -321,7 +321,24 @@ _PUBLIC_ char **fd_lines_load(int fd, int *numlines, size_t maxsize, TALLOC_CTX
 	p = fd_load(fd, &size, maxsize, mem_ctx);
 	if (!p) return NULL;
 
-	return file_lines_parse(p, size, numlines, mem_ctx);
+	return file_lines_parse_internal(p, size, numlines, mem_ctx);
+}
+
+_PUBLIC_ char **file_lines_parse(const char *p_in,
+			size_t size,
+			int *numlines,
+			TALLOC_CTX *mem_ctx)
+{
+	/*
+	 * Copy the incoming string so it can end up
+	 * being owned by the returned pointer and
+	 * freed when that is.
+	 */
+	char *p = talloc_strdup(mem_ctx, p_in);
+	if (p == NULL) {
+		return NULL;
+	}
+	return file_lines_parse_internal(p, size, numlines, mem_ctx);
 }
 
 _PUBLIC_ bool file_save_mode(const char *fname, const void *packet,


-- 
Samba Shared Repository



More information about the samba-cvs mailing list