mirror of
https://github.com/systemd/systemd.git
synced 2024-10-27 01:55:22 +03:00
Merge pull request #33893 from yuwata/coverity
tree-wide: resolve several issues found by coverity
This commit is contained in:
commit
62bfb79b61
@ -409,6 +409,11 @@ static int raw_import_process(RawImport *i) {
|
||||
goto finish;
|
||||
}
|
||||
|
||||
if ((size_t) l > sizeof(i->buffer) - i->buffer_size) {
|
||||
r = log_error_errno(SYNTHETIC_ERRNO(EBADMSG), "Read input file exceeded maximum size.");
|
||||
goto finish;
|
||||
}
|
||||
|
||||
i->buffer_size += l;
|
||||
|
||||
if (i->compress.type == IMPORT_COMPRESS_UNKNOWN) {
|
||||
|
@ -276,6 +276,11 @@ static int tar_import_process(TarImport *i) {
|
||||
goto finish;
|
||||
}
|
||||
|
||||
if ((size_t) l > sizeof(i->buffer) - i->buffer_size) {
|
||||
r = log_error_errno(SYNTHETIC_ERRNO(EBADMSG), "Read input file exceeded maximum size.");
|
||||
goto finish;
|
||||
}
|
||||
|
||||
i->buffer_size += l;
|
||||
|
||||
if (i->compress.type == IMPORT_COMPRESS_UNKNOWN) {
|
||||
|
@ -120,7 +120,7 @@ TEST(dns_search_domain_unlink_link) {
|
||||
_cleanup_(dns_search_domain_unrefp) DnsSearchDomain *sd1 = NULL, *sd3 = NULL;
|
||||
DnsSearchDomain *sd2 = NULL;
|
||||
|
||||
link_new(&manager, &link, 1);
|
||||
ASSERT_OK(link_new(&manager, &link, 1));
|
||||
ASSERT_NOT_NULL(link);
|
||||
|
||||
dns_search_domain_new(&manager, &sd1, DNS_SEARCH_DOMAIN_LINK, link, "local");
|
||||
|
@ -161,7 +161,7 @@ static void link_alloc_env_setup(LinkAllocEnv *env, int family, DnsServerType se
|
||||
env->manager = (Manager) {};
|
||||
env->ifindex = 1;
|
||||
|
||||
sd_event_new(&env->manager.event);
|
||||
ASSERT_OK(sd_event_new(&env->manager.event));
|
||||
ASSERT_NOT_NULL(env->manager.event);
|
||||
|
||||
ASSERT_OK(link_new(&env->manager, &env->link, env->ifindex));
|
||||
|
@ -256,7 +256,7 @@ TEST(calendar_spec_from_string) {
|
||||
|
||||
static int intro(void) {
|
||||
/* Tests have hard-coded results that do not expect a specific timezone to be set by the caller */
|
||||
ASSERT_OK(unsetenv("TZ"));
|
||||
ASSERT_OK_ERRNO(unsetenv("TZ"));
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
@ -31,33 +31,33 @@ TEST(is_wanted_print) {
|
||||
}
|
||||
|
||||
TEST(is_wanted) {
|
||||
ASSERT_OK(setenv("SYSTEMD_PROC_CMDLINE",
|
||||
"systemd.unified_cgroup_hierarchy", 1));
|
||||
ASSERT_OK_ERRNO(setenv("SYSTEMD_PROC_CMDLINE",
|
||||
"systemd.unified_cgroup_hierarchy", 1));
|
||||
test_is_wanted_print_one(false);
|
||||
|
||||
ASSERT_OK(setenv("SYSTEMD_PROC_CMDLINE",
|
||||
"systemd.unified_cgroup_hierarchy=0", 1));
|
||||
ASSERT_OK_ERRNO(setenv("SYSTEMD_PROC_CMDLINE",
|
||||
"systemd.unified_cgroup_hierarchy=0", 1));
|
||||
test_is_wanted_print_one(false);
|
||||
|
||||
ASSERT_OK(setenv("SYSTEMD_PROC_CMDLINE",
|
||||
"systemd.unified_cgroup_hierarchy=0 "
|
||||
"systemd.legacy_systemd_cgroup_controller", 1));
|
||||
ASSERT_OK_ERRNO(setenv("SYSTEMD_PROC_CMDLINE",
|
||||
"systemd.unified_cgroup_hierarchy=0 "
|
||||
"systemd.legacy_systemd_cgroup_controller", 1));
|
||||
test_is_wanted_print_one(false);
|
||||
|
||||
ASSERT_OK(setenv("SYSTEMD_PROC_CMDLINE",
|
||||
"systemd.unified_cgroup_hierarchy=0 "
|
||||
"systemd.legacy_systemd_cgroup_controller=0", 1));
|
||||
ASSERT_OK_ERRNO(setenv("SYSTEMD_PROC_CMDLINE",
|
||||
"systemd.unified_cgroup_hierarchy=0 "
|
||||
"systemd.legacy_systemd_cgroup_controller=0", 1));
|
||||
test_is_wanted_print_one(false);
|
||||
|
||||
/* cgroup_no_v1=all implies unified cgroup hierarchy, unless otherwise
|
||||
* explicitly specified. */
|
||||
ASSERT_OK(setenv("SYSTEMD_PROC_CMDLINE",
|
||||
"cgroup_no_v1=all", 1));
|
||||
ASSERT_OK_ERRNO(setenv("SYSTEMD_PROC_CMDLINE",
|
||||
"cgroup_no_v1=all", 1));
|
||||
test_is_wanted_print_one(false);
|
||||
|
||||
ASSERT_OK(setenv("SYSTEMD_PROC_CMDLINE",
|
||||
"cgroup_no_v1=all "
|
||||
"systemd.unified_cgroup_hierarchy=0", 1));
|
||||
ASSERT_OK_ERRNO(setenv("SYSTEMD_PROC_CMDLINE",
|
||||
"cgroup_no_v1=all "
|
||||
"systemd.unified_cgroup_hierarchy=0", 1));
|
||||
test_is_wanted_print_one(false);
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,7 @@ TEST(parse_os_release) {
|
||||
log_info("ID: %s", id);
|
||||
}
|
||||
|
||||
ASSERT_EQ(setenv("SYSTEMD_OS_RELEASE", "/dev/null", 1), 0);
|
||||
ASSERT_OK_ERRNO(setenv("SYSTEMD_OS_RELEASE", "/dev/null", 1));
|
||||
ASSERT_EQ(parse_os_release(NULL, "ID", &id2), 0);
|
||||
log_info("ID: %s", strnull(id2));
|
||||
|
||||
@ -36,7 +36,7 @@ TEST(parse_os_release) {
|
||||
"ID=the-id \n"
|
||||
"NAME=the-name"), 0);
|
||||
|
||||
ASSERT_EQ(setenv("SYSTEMD_OS_RELEASE", tmpfile, 1), 0);
|
||||
ASSERT_OK_ERRNO(setenv("SYSTEMD_OS_RELEASE", tmpfile, 1));
|
||||
ASSERT_EQ(parse_os_release(NULL, "ID", &id, "NAME", &name), 0);
|
||||
log_info("ID: %s NAME: %s", id, name);
|
||||
ASSERT_STREQ(id, "the-id");
|
||||
@ -48,7 +48,7 @@ TEST(parse_os_release) {
|
||||
"ID=\"the-id\" \n"
|
||||
"NAME='the-name'"), 0);
|
||||
|
||||
ASSERT_EQ(setenv("SYSTEMD_OS_RELEASE", tmpfile2, 1), 0);
|
||||
ASSERT_OK_ERRNO(setenv("SYSTEMD_OS_RELEASE", tmpfile2, 1));
|
||||
ASSERT_EQ(parse_os_release(NULL, "ID", &id, "NAME", &name), 0);
|
||||
log_info("ID: %s NAME: %s", id, name);
|
||||
ASSERT_STREQ(id, "the-id");
|
||||
@ -58,7 +58,7 @@ TEST(parse_os_release) {
|
||||
log_info("FOOBAR: %s", strnull(foobar));
|
||||
ASSERT_NULL(foobar);
|
||||
|
||||
assert_se(unsetenv("SYSTEMD_OS_RELEASE") == 0);
|
||||
ASSERT_OK_ERRNO(unsetenv("SYSTEMD_OS_RELEASE"));
|
||||
}
|
||||
|
||||
TEST(parse_extension_release) {
|
||||
@ -111,14 +111,14 @@ TEST(load_os_release_pairs) {
|
||||
"ID=\"the-id\" \n"
|
||||
"NAME='the-name'"), 0);
|
||||
|
||||
ASSERT_EQ(setenv("SYSTEMD_OS_RELEASE", tmpfile, 1), 0);
|
||||
ASSERT_OK_ERRNO(setenv("SYSTEMD_OS_RELEASE", tmpfile, 1));
|
||||
|
||||
_cleanup_strv_free_ char **pairs = NULL;
|
||||
ASSERT_EQ(load_os_release_pairs(NULL, &pairs), 0);
|
||||
assert_se(strv_equal(pairs, STRV_MAKE("ID", "the-id",
|
||||
"NAME", "the-name")));
|
||||
|
||||
ASSERT_EQ(unsetenv("SYSTEMD_OS_RELEASE"), 0);
|
||||
ASSERT_OK_ERRNO(unsetenv("SYSTEMD_OS_RELEASE"));
|
||||
}
|
||||
|
||||
TEST(os_release_support_ended) {
|
||||
|
@ -251,7 +251,7 @@ TEST(terminal_is_pty_fd) {
|
||||
}
|
||||
|
||||
static void test_get_color_mode_with_env(const char *key, const char *val, ColorMode expected) {
|
||||
ASSERT_OK(setenv(key, val, true));
|
||||
ASSERT_OK_ERRNO(setenv(key, val, true));
|
||||
reset_terminal_feature_caches();
|
||||
log_info("get_color_mode($%s=%s): %s", key, val, color_mode_to_string(get_color_mode()));
|
||||
ASSERT_EQ(get_color_mode(), expected);
|
||||
@ -269,17 +269,17 @@ TEST(get_color_mode) {
|
||||
test_get_color_mode_with_env("SYSTEMD_COLORS", "yes", COLOR_24BIT);
|
||||
test_get_color_mode_with_env("SYSTEMD_COLORS", "24bit", COLOR_24BIT);
|
||||
|
||||
ASSERT_OK(setenv("NO_COLOR", "1", true));
|
||||
ASSERT_OK_ERRNO(setenv("NO_COLOR", "1", true));
|
||||
test_get_color_mode_with_env("SYSTEMD_COLORS", "42", COLOR_OFF);
|
||||
test_get_color_mode_with_env("SYSTEMD_COLORS", "invalid", COLOR_OFF);
|
||||
ASSERT_OK(unsetenv("NO_COLOR"));
|
||||
ASSERT_OK(unsetenv("SYSTEMD_COLORS"));
|
||||
ASSERT_OK_ERRNO(unsetenv("NO_COLOR"));
|
||||
ASSERT_OK_ERRNO(unsetenv("SYSTEMD_COLORS"));
|
||||
|
||||
test_get_color_mode_with_env("COLORTERM", "truecolor", terminal_is_dumb() ? COLOR_OFF : COLOR_24BIT);
|
||||
test_get_color_mode_with_env("COLORTERM", "24bit", terminal_is_dumb() ? COLOR_OFF : COLOR_24BIT);
|
||||
test_get_color_mode_with_env("COLORTERM", "invalid", terminal_is_dumb() ? COLOR_OFF : COLOR_256);
|
||||
test_get_color_mode_with_env("COLORTERM", "42", terminal_is_dumb() ? COLOR_OFF : COLOR_256);
|
||||
unsetenv("COLORTERM");
|
||||
ASSERT_OK_ERRNO(unsetenv("COLORTERM"));
|
||||
reset_terminal_feature_caches();
|
||||
}
|
||||
|
||||
|
@ -626,10 +626,10 @@ static int read_vsock_notify(NotifyConnectionData *d, int fd) {
|
||||
if (n == 0) /* We hit EOF! Let's parse this */
|
||||
break;
|
||||
|
||||
d->full += n;
|
||||
|
||||
if (d->full >= sizeof(d->buffer))
|
||||
if ((size_t) n >= sizeof(d->buffer) - d->full)
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EBADMSG), "Received notify message exceeded maximum size.");
|
||||
|
||||
d->full += n;
|
||||
}
|
||||
|
||||
/* We reached EOF, now parse the thing */
|
||||
|
Loading…
Reference in New Issue
Block a user