summaryrefslogtreecommitdiffstats
path: root/src/systemctl/systemctl-edit.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2021-03-17 18:44:51 +0100
committerLennart Poettering <lennart@poettering.net>2021-03-17 18:44:51 +0100
commitbe81e45c748b9cd3a3ebe6995d84932d7ec139b1 (patch)
treeffca7db8bbd926ac939819acf60d0d5fa6911a51 /src/systemctl/systemctl-edit.c
parenttree-wide: use read_full_virtual_file() where appropriate (diff)
downloadsystemd-be81e45c748b9cd3a3ebe6995d84932d7ec139b1.tar.xz
systemd-be81e45c748b9cd3a3ebe6995d84932d7ec139b1.zip
systemctl: pecify read_full_file() size argument as NULL
If it is specified as NULL read_full_file() assumes the caller wants a C string, and it looks for embedded NUL bytes to ensure that works. Given we don#t actually use the size argument here, let's drop it. (in one case the size argument is used, but not for actually processing the full returned data, but just as a shortcut to compare things with the original string. Let's drop use of that there, too given the risk of embedded NUL bytes in the data read.)
Diffstat (limited to '')
-rw-r--r--src/systemctl/systemctl-edit.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/systemctl/systemctl-edit.c b/src/systemctl/systemctl-edit.c
index 4186ec3aea..7cb58c5208 100644
--- a/src/systemctl/systemctl-edit.c
+++ b/src/systemctl/systemctl-edit.c
@@ -146,7 +146,6 @@ static int create_edit_temp_file(const char *new_path, const char *original_path
_cleanup_free_ char *new_contents = NULL;
_cleanup_fclose_ FILE *f = NULL;
char **path;
- size_t size;
r = mac_selinux_create_file_prepare(new_path, S_IFREG);
if (r < 0)
@@ -161,7 +160,7 @@ static int create_edit_temp_file(const char *new_path, const char *original_path
if (r < 0)
return log_error_errno(errno, "Failed to change mode of \"%s\": %m", t);
- r = read_full_file(new_path, &new_contents, &size);
+ r = read_full_file(new_path, &new_contents, NULL);
if (r < 0 && r != -ENOENT)
return log_error_errno(r, "Failed to read \"%s\": %m", new_path);
@@ -182,7 +181,7 @@ static int create_edit_temp_file(const char *new_path, const char *original_path
if (path_equal(*path, new_path))
continue;
- r = read_full_file(*path, &contents, &size);
+ r = read_full_file(*path, &contents, NULL);
if (r < 0)
return log_error_errno(r, "Failed to read \"%s\": %m", *path);
@@ -468,10 +467,12 @@ static int trim_edit_markers(const char *path) {
int r;
/* Trim out the lines between the two markers */
- r = read_full_file(path, &contents, &size);
+ r = read_full_file(path, &contents, NULL);
if (r < 0)
return log_error_errno(r, "Failed to read temporary file \"%s\": %m", path);
+ size = strlen(contents);
+
contents_start = strstr(contents, EDIT_MARKER_START);
if (contents_start)
contents_start += strlen(EDIT_MARKER_START);