1
0
mirror of https://github.com/systemd/systemd synced 2025-09-30 17:24:46 +02:00

Compare commits

..

8 Commits

Author SHA1 Message Date
Luca Boccassi
1c3c43a417
Merge pull request #18550 from keszybz/coverity-inspired-fixes
Coverity inspired fixes
2021-02-11 15:44:25 +00:00
Zbigniew Jędrzejewski-Szmek
a4aa5742f7 homework: fix unitialized variable
Coverity CID#1444703.
2021-02-11 12:00:09 +01:00
Zbigniew Jędrzejewski-Szmek
78b4e9ed17 homework: reduce scope of iterator variables 2021-02-11 11:59:22 +01:00
Zbigniew Jędrzejewski-Szmek
0eacd1852a basic/locale-util: reduce variable scope 2021-02-11 09:55:01 +01:00
Zbigniew Jędrzejewski-Szmek
333ab199a1 fsck: make sure we don't read an unitialized variable
This use on %n was completely unnecessary: fprintf returns the number of
characters written. And the issue was that if fprintf failed for whatever
reason, it would not process the %n and m would be unitialized. Rework the
code a bit to simplify it.

Coverity CID#1444708.
2021-02-11 09:50:49 +01:00
Zbigniew Jędrzejewski-Szmek
363729c470 sd-journal: add forgotten unmap in error path
Bug introduced in 4b5bc5396c090ee41c45cab9052372d296c4a2f4 :(

Coverity CID#1444709.
2021-02-11 09:35:52 +01:00
Zbigniew Jędrzejewski-Szmek
47237e0ed4 shared/generator: add missing initializer
Coverity CID#1444710.
2021-02-11 09:23:22 +01:00
Zbigniew Jędrzejewski-Szmek
b5f1c0d88b udev: add assert to make coverity happy
Coverity says:
CID 1446387 (#1 of 1): Bad bit shift operation (BAD_SHIFT)
8. negative_shift: In expression 1U << (int)cmd, shifting by a negative amount
has undefined behavior. The shift amount, cmd, is -22.

I don't think there's any issue, unless we forget to set token->data
appropriately. Let's add an assert.
2021-02-11 09:17:46 +01:00
6 changed files with 25 additions and 27 deletions

View File

@ -98,7 +98,6 @@ static int add_locales_from_archive(Set *locales) {
_cleanup_close_ int fd = -1; _cleanup_close_ int fd = -1;
size_t sz = 0; size_t sz = 0;
struct stat st; struct stat st;
size_t i;
int r; int r;
fd = open("/usr/lib/locale/locale-archive", O_RDONLY|O_NOCTTY|O_CLOEXEC); fd = open("/usr/lib/locale/locale-archive", O_RDONLY|O_NOCTTY|O_CLOEXEC);
@ -129,7 +128,7 @@ static int add_locales_from_archive(Set *locales) {
} }
e = (const struct namehashent*) ((const uint8_t*) p + h->namehash_offset); e = (const struct namehashent*) ((const uint8_t*) p + h->namehash_offset);
for (i = 0; i < h->namehash_size; i++) { for (size_t i = 0; i < h->namehash_size; i++) {
char *z; char *z;
if (e[i].locrec_offset == 0) if (e[i].locrec_offset == 0)
@ -434,12 +433,10 @@ const char *special_glyph(SpecialGlyph code) {
} }
void locale_variables_free(char *l[_VARIABLE_LC_MAX]) { void locale_variables_free(char *l[_VARIABLE_LC_MAX]) {
LocaleVariable i;
if (!l) if (!l)
return; return;
for (i = 0; i < _VARIABLE_LC_MAX; i++) for (LocaleVariable i = 0; i < _VARIABLE_LC_MAX; i++)
l[i] = mfree(l[i]); l[i] = mfree(l[i]);
} }

View File

@ -172,7 +172,7 @@ static int process_progress(int fd, FILE* console) {
} }
for (;;) { for (;;) {
int pass, m; int pass;
unsigned long cur, max; unsigned long cur, max;
_cleanup_free_ char *device = NULL; _cleanup_free_ char *device = NULL;
double p; double p;
@ -206,18 +206,17 @@ static int process_progress(int fd, FILE* console) {
last = t; last = t;
p = percent(pass, cur, max); p = percent(pass, cur, max);
fprintf(console, "\r%s: fsck %3.1f%% complete...\r%n", device, p, &m); r = fprintf(console, "\r%s: fsck %3.1f%% complete...\r", device, p);
fflush(console); if (r < 0)
return -EIO; /* No point in continuing if something happend to our output stream */
if (m > clear) fflush(console);
clear = m; clear = MAX(clear, r);
} }
if (clear > 0) { if (clear > 0) {
unsigned j;
fputc('\r', console); fputc('\r', console);
for (j = 0; j < (unsigned) clear; j++) for (int j = 0; j < clear; j++)
fputc(' ', console); fputc(' ', console);
fputc('\r', console); fputc('\r', console);
fflush(console); fflush(console);

View File

@ -518,7 +518,7 @@ static int luks_validate(
blkid_loff_t offset = 0, size = 0; blkid_loff_t offset = 0, size = 0;
blkid_partlist pl; blkid_partlist pl;
bool found = false; bool found = false;
int r, i, n; int r, n;
assert(fd >= 0); assert(fd >= 0);
assert(label); assert(label);
@ -570,9 +570,9 @@ static int luks_validate(
if (n < 0) if (n < 0)
return errno > 0 ? -errno : -EIO; return errno > 0 ? -errno : -EIO;
for (i = 0; i < n; i++) { for (int i = 0; i < n; i++) {
blkid_partition pp; blkid_partition pp;
sd_id128_t id; sd_id128_t id = SD_ID128_NULL;
const char *sid; const char *sid;
errno = 0; errno = 0;
@ -681,12 +681,12 @@ static int luks_validate_home_record(
PasswordCache *cache, PasswordCache *cache,
UserRecord **ret_luks_home_record) { UserRecord **ret_luks_home_record) {
int r, token; int r;
assert(cd); assert(cd);
assert(h); assert(h);
for (token = 0;; token++) { for (int token = 0;; token++) {
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL, *rr = NULL; _cleanup_(json_variant_unrefp) JsonVariant *v = NULL, *rr = NULL;
_cleanup_(EVP_CIPHER_CTX_freep) EVP_CIPHER_CTX *context = NULL; _cleanup_(EVP_CIPHER_CTX_freep) EVP_CIPHER_CTX *context = NULL;
_cleanup_(user_record_unrefp) UserRecord *lhr = NULL; _cleanup_(user_record_unrefp) UserRecord *lhr = NULL;
@ -2423,7 +2423,7 @@ static int prepare_resize_partition(
_cleanup_(fdisk_unref_contextp) struct fdisk_context *c = NULL; _cleanup_(fdisk_unref_contextp) struct fdisk_context *c = NULL;
_cleanup_(fdisk_unref_tablep) struct fdisk_table *t = NULL; _cleanup_(fdisk_unref_tablep) struct fdisk_table *t = NULL;
_cleanup_free_ char *path = NULL, *disk_uuid_as_string = NULL; _cleanup_free_ char *path = NULL, *disk_uuid_as_string = NULL;
size_t n_partitions, i; size_t n_partitions;
sd_id128_t disk_uuid; sd_id128_t disk_uuid;
bool found = false; bool found = false;
int r; int r;
@ -2473,7 +2473,7 @@ static int prepare_resize_partition(
return log_error_errno(r, "Failed to acquire partition table: %m"); return log_error_errno(r, "Failed to acquire partition table: %m");
n_partitions = fdisk_table_get_nents(t); n_partitions = fdisk_table_get_nents(t);
for (i = 0; i < n_partitions; i++) { for (size_t i = 0; i < n_partitions; i++) {
struct fdisk_partition *p; struct fdisk_partition *p;
p = fdisk_table_get_partition(t, i); p = fdisk_table_get_partition(t, i);
@ -2898,7 +2898,7 @@ int home_passwd_luks(
PasswordCache *cache, /* the passwords acquired via PKCS#11/FIDO2 security tokens */ PasswordCache *cache, /* the passwords acquired via PKCS#11/FIDO2 security tokens */
char **effective_passwords /* new passwords */) { char **effective_passwords /* new passwords */) {
size_t volume_key_size, i, max_key_slots, n_effective; size_t volume_key_size, max_key_slots, n_effective;
_cleanup_(erase_and_freep) void *volume_key = NULL; _cleanup_(erase_and_freep) void *volume_key = NULL;
struct crypt_pbkdf_type good_pbkdf, minimal_pbkdf; struct crypt_pbkdf_type good_pbkdf, minimal_pbkdf;
const char *type; const char *type;
@ -2943,7 +2943,7 @@ int home_passwd_luks(
build_good_pbkdf(&good_pbkdf, h); build_good_pbkdf(&good_pbkdf, h);
build_minimal_pbkdf(&minimal_pbkdf, h); build_minimal_pbkdf(&minimal_pbkdf, h);
for (i = 0; i < max_key_slots; i++) { for (size_t i = 0; i < max_key_slots; i++) {
r = crypt_keyslot_destroy(setup->crypt_device, i); r = crypt_keyslot_destroy(setup->crypt_device, i);
if (r < 0 && !IN_SET(r, -ENOENT, -EINVAL)) /* Returns EINVAL or ENOENT if there's no key in this slot already */ if (r < 0 && !IN_SET(r, -ENOENT, -EINVAL)) /* Returns EINVAL or ENOENT if there's no key in this slot already */
return log_error_errno(r, "Failed to destroy LUKS password: %m"); return log_error_errno(r, "Failed to destroy LUKS password: %m");

View File

@ -664,10 +664,11 @@ int compress_stream_lz4(int fdf, int fdt, uint64_t max_bytes) {
offset += n; offset += n;
total_out += n; total_out += n;
if (max_bytes != (uint64_t) -1 && total_out > (size_t) max_bytes) if (max_bytes != (uint64_t) -1 && total_out > (size_t) max_bytes) {
return log_debug_errno(SYNTHETIC_ERRNO(EFBIG), r = log_debug_errno(SYNTHETIC_ERRNO(EFBIG),
"Compressed stream longer than %" PRIu64 " bytes", "Compressed stream longer than %" PRIu64 " bytes", max_bytes);
max_bytes); goto cleanup;
}
if (size - offset < frame_size + 4) { if (size - offset < frame_size + 4) {
k = loop_write(fdt, buf, offset, false); k = loop_write(fdt, buf, offset, false);

View File

@ -652,7 +652,7 @@ int generator_write_veritysetup_service_section(
const char *roothash, const char *roothash,
const char *options) { const char *options) {
_cleanup_free_ char *name_escaped = NULL, *data_what_escaped = NULL, *hash_what_escaped, _cleanup_free_ char *name_escaped = NULL, *data_what_escaped = NULL, *hash_what_escaped = NULL,
*roothash_escaped = NULL, *options_escaped = NULL; *roothash_escaped = NULL, *options_escaped = NULL;
assert(f); assert(f);

View File

@ -1773,6 +1773,7 @@ static int udev_rule_apply_token_to_event(
} }
case TK_M_IMPORT_BUILTIN: { case TK_M_IMPORT_BUILTIN: {
UdevBuiltinCommand cmd = PTR_TO_UDEV_BUILTIN_CMD(token->data); UdevBuiltinCommand cmd = PTR_TO_UDEV_BUILTIN_CMD(token->data);
assert(cmd >= 0 && cmd < _UDEV_BUILTIN_MAX);
unsigned mask = 1U << (int) cmd; unsigned mask = 1U << (int) cmd;
if (udev_builtin_run_once(cmd)) { if (udev_builtin_run_once(cmd)) {