1
0
mirror of https://github.com/systemd/systemd synced 2026-03-12 08:04:46 +01:00

Compare commits

..

No commits in common. "46cfe8f50db6d15a00384cc422f1f9d068207238" and "a81c7ac8d408a2618d488e708b40530bcdad6bd1" have entirely different histories.

6 changed files with 24 additions and 34 deletions

View File

@ -857,13 +857,10 @@ conf.set_quoted('SYSTEMD_DEFAULT_LOCALE', default_locale)
localegen_path = get_option('localegen-path') localegen_path = get_option('localegen-path')
have = false have = false
writable = ''
if localegen_path != '' if localegen_path != ''
conf.set_quoted('LOCALEGEN_PATH', localegen_path) conf.set_quoted('LOCALEGEN_PATH', localegen_path)
have = true have = true
writable = ' /usr/lib/locale'
endif endif
substs.set('SERVICE_LOCALEGEN_WRITABLE', writable)
conf.set10('HAVE_LOCALEGEN', have) conf.set10('HAVE_LOCALEGEN', have)
conf.set_quoted('GETTEXT_PACKAGE', meson.project_name()) conf.set_quoted('GETTEXT_PACKAGE', meson.project_name())

View File

@ -27,8 +27,7 @@
#include "string-util.h" #include "string-util.h"
#include "tmpfile-util.h" #include "tmpfile-util.h"
/* The maximum size of the file we'll read in one go. */ #define READ_FULL_BYTES_MAX (4U*1024U*1024U)
#define READ_FULL_BYTES_MAX (4U*1024U*1024U - 1)
int fopen_unlocked(const char *path, const char *options, FILE **ret) { int fopen_unlocked(const char *path, const char *options, FILE **ret) {
assert(ret); assert(ret);
@ -387,10 +386,8 @@ int read_full_virtual_file(const char *filename, char **ret_contents, size_t *re
/* Start size for files in /proc/ which usually report a file size of 0. (Files in /sys/ report a /* Start size for files in /proc/ which usually report a file size of 0. (Files in /sys/ report a
* file size of 4K, which is probably OK for sizing our initial buffer, and sysfs attributes can't be * file size of 4K, which is probably OK for sizing our initial buffer, and sysfs attributes can't be
* larger anyway.) * larger anyway.) */
* size = LINE_MAX / 2;
* It's one less than 4k, so that the malloc() below allocates exactly 4k. */
size = 4095;
/* Limit the number of attempts to read the number of bytes returned by fstat(). */ /* Limit the number of attempts to read the number of bytes returned by fstat(). */
n_retries = 3; n_retries = 3;
@ -406,27 +403,22 @@ int read_full_virtual_file(const char *filename, char **ret_contents, size_t *re
return -EBADF; return -EBADF;
/* Be prepared for files from /proc which generally report a file size of 0. */ /* Be prepared for files from /proc which generally report a file size of 0. */
assert_cc(READ_FULL_BYTES_MAX < SSIZE_MAX);
if (st.st_size > 0) { if (st.st_size > 0) {
if (st.st_size > READ_FULL_BYTES_MAX) if (st.st_size > SSIZE_MAX) /* safety check in case off_t is 64bit and size_t 32bit */
return -E2BIG; return -E2BIG;
size = st.st_size; size = st.st_size;
n_retries--; n_retries--;
} else { } else
/* Double the buffer size */ /* Double the buffer size (saturate in case of overflow) */
if (size >= READ_FULL_BYTES_MAX) size = size > SSIZE_MAX / 2 ? SSIZE_MAX : size * 2;
if (size > READ_FULL_BYTES_MAX)
return -E2BIG; return -E2BIG;
if (size > READ_FULL_BYTES_MAX / 2 - 1)
size = READ_FULL_BYTES_MAX; /* clamp to max */
else
size = size * 2 + 1; /* Stay always one less than page size, so we malloc evenly */
}
buf = malloc(size + 1); buf = malloc(size + 1);
if (!buf) if (!buf)
return -ENOMEM; return -ENOMEM;
size = malloc_usable_size(buf) - 1; /* Use a bigger allocation if we got it anyway */
for (;;) { for (;;) {
ssize_t k; ssize_t k;
@ -470,13 +462,16 @@ int read_full_virtual_file(const char *filename, char **ret_contents, size_t *re
buf = TAKE_PTR(p); buf = TAKE_PTR(p);
} }
if (ret_size) if (!ret_size) {
*ret_size = n; /* Safety check: if the caller doesn't want to know the size of what we
else if (memchr(buf, 0, n)) * just read it will rely on the trailing NUL byte. But if there's an
/* Safety check: if the caller doesn't want to know the size of what we just read it will * embedded NUL byte, then we should refuse operation as otherwise
* rely on the trailing NUL byte. But if there's an embedded NUL byte, then we should refuse * there'd be ambiguity about what we just read. */
* operation as otherwise there'd be ambiguity about what we just read. */
if (memchr(buf, 0, n))
return -EBADMSG; return -EBADMSG;
} else
*ret_size = n;
buf[n] = 0; buf[n] = 0;
*ret_contents = TAKE_PTR(buf); *ret_contents = TAKE_PTR(buf);

View File

@ -28,17 +28,11 @@ int bus_error_set_errnofv(sd_bus_error *e, int error, const char *format, va_lis
* the bus error table, and BUS_ERROR_MAP_ELF_USE has to be used at * the bus error table, and BUS_ERROR_MAP_ELF_USE has to be used at
* least once per compilation unit (i.e. per library), to ensure that * least once per compilation unit (i.e. per library), to ensure that
* the error map is really added to the final binary. * the error map is really added to the final binary.
*
* In addition, set the retain attribute so that the section cannot be
* discarded by ld --gc-sections -z start-stop-gc. Older compilers would
* warn for the unknown attribute, so just disable -Wattributes.
*/ */
#define BUS_ERROR_MAP_ELF_REGISTER \ #define BUS_ERROR_MAP_ELF_REGISTER \
_Pragma("GCC diagnostic ignored \"-Wattributes\"") \
_section_("SYSTEMD_BUS_ERROR_MAP") \ _section_("SYSTEMD_BUS_ERROR_MAP") \
_used_ \ _used_ \
__attribute__((retain)) \
_alignptr_ \ _alignptr_ \
_variable_no_sanitize_address_ _variable_no_sanitize_address_

View File

@ -30,6 +30,8 @@ int main(int argc, char *argv[]) {
const char *key, *value; const char *key, *value;
int r; int r;
unsetenv("SYSTEMD_MEMPOOL");
r = sd_device_new_from_syspath(&loopback, "/sys/class/net/lo"); r = sd_device_new_from_syspath(&loopback, "/sys/class/net/lo");
if (r < 0) if (r < 0)
return handle_error_errno(r, "Failed to create loopback device object"); return handle_error_errno(r, "Failed to create loopback device object");

View File

@ -28,6 +28,8 @@ int main(int argc, char *argv[]) {
pthread_t t; pthread_t t;
int r; int r;
unsetenv("SYSTEMD_MEMPOOL");
loopback = udev_device_new_from_syspath(NULL, "/sys/class/net/lo"); loopback = udev_device_new_from_syspath(NULL, "/sys/class/net/lo");
if (!loopback) if (!loopback)
return handle_error_errno(errno, "Failed to create loopback device object"); return handle_error_errno(errno, "Failed to create loopback device object");

View File

@ -33,7 +33,7 @@ ProtectKernelLogs=yes
ProtectKernelModules=yes ProtectKernelModules=yes
ProtectKernelTunables=yes ProtectKernelTunables=yes
ProtectSystem=strict ProtectSystem=strict
ReadWritePaths=/etc@SERVICE_LOCALEGEN_WRITABLE@ ReadWritePaths=/etc
RestrictAddressFamilies=AF_UNIX RestrictAddressFamilies=AF_UNIX
RestrictNamespaces=yes RestrictNamespaces=yes
RestrictRealtime=yes RestrictRealtime=yes