diff --git a/scripts/boilerplate_generator.py b/scripts/boilerplate_generator.py index 736e160db..d582cf787 100755 --- a/scripts/boilerplate_generator.py +++ b/scripts/boilerplate_generator.py @@ -219,8 +219,10 @@ def get_loading_func(fn_infos, module_name): # clear any previous error and load the function ret += ' dlerror();\n' ret += ' * (void**) (&_{0.name}) = dlsym(handle, "{0.name}");\n'.format(info) - ret += ' if ((error = dlerror()) != NULL)\n' - ret += ' bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load {0.name}: %s", error);\n\n'.format(info) + ret += ' if ((error = dlerror()) != NULL) {\n' + ret += ' bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load {0.name}: %s", error);\n'.format(info) + ret += ' _{0.name} = {0.name}_stub;\n'.format(info) + ret += ' }\n\n' ret += ' return handle;\n' ret += '}\n\n' diff --git a/src/lib/blockdev.c.in b/src/lib/blockdev.c.in index b81e802e6..f8f86ce41 100644 --- a/src/lib/blockdev.c.in +++ b/src/lib/blockdev.c.in @@ -142,8 +142,10 @@ static gboolean process_config_file (const gchar *config_file, GSList **plugins_ gsize n_sonames = 0; config = g_key_file_new (); - if (!g_key_file_load_from_file (config, config_file, G_KEY_FILE_NONE, error)) + if (!g_key_file_load_from_file (config, config_file, G_KEY_FILE_NONE, error)) { + g_key_file_free (config); return FALSE; + } /* get sonames for each plugin (if specified) */ for (i=0; (i < BD_PLUGIN_UNDEF); i++) { @@ -330,15 +332,19 @@ static gboolean load_plugins (BDPluginSpec **require_plugins, gboolean reload, g unload_plugins (); /* clean all so names and populate back those that are requested or the defaults */ - for (i=0; i < BD_PLUGIN_UNDEF; i++) + for (i=0; i < BD_PLUGIN_UNDEF; i++) { + g_free ((gchar *) plugins[i].spec.so_name); plugins[i].spec.so_name = NULL; + } } if (require_plugins) { /* set requested sonames */ for (i=0; *(require_plugins + i); i++) { plugin_name = require_plugins[i]->name; - required_plugins_mask |= (1 << plugin_name); + if (plugin_name >= BD_PLUGIN_UNDEF) + continue; + required_plugins_mask |= ((guint64) 1 << plugin_name); if (require_plugins[i]->so_name) { g_slist_free_full (plugins_sonames[plugin_name], (GDestroyNotify) g_free); plugins_sonames[plugin_name] = NULL; @@ -348,7 +354,7 @@ static gboolean load_plugins (BDPluginSpec **require_plugins, gboolean reload, g /* now remove the defaults for plugins that are not required */ for (i=0; (i < BD_PLUGIN_UNDEF); i++) - if (!(required_plugins_mask & (1 << i))) { + if (!(required_plugins_mask & ((guint64) 1 << i))) { /* plugin not required */ g_slist_free_full (plugins_sonames[i], (GDestroyNotify) g_free); plugins_sonames[i] = NULL; @@ -361,7 +367,7 @@ static gboolean load_plugins (BDPluginSpec **require_plugins, gboolean reload, g for (i=0; (i < BD_PLUGIN_UNDEF); i++) { /* if this plugin was required or all plugins were required, check if it was successfully loaded or not */ - if (!require_plugins || (required_plugins_mask & (1 << i))) { + if (!require_plugins || (required_plugins_mask & ((guint64) 1 << i))) { #if !defined(__s390__) && !defined(__s390x__) if (!require_plugins && (i == BD_PLUGIN_S390)) /* do not check the s390 plugin on different archs unless @@ -496,7 +502,7 @@ gboolean bd_ensure_init (BDPluginSpec **require_plugins, BDUtilsLogFunc log_func missing = !bd_is_plugin_available((*check_plugin)->name); else /* all plugins requested */ - for (plugin=BD_PLUGIN_LVM; plugin != BD_PLUGIN_UNDEF; plugin++) + for (plugin=BD_PLUGIN_LVM; !missing && plugin != BD_PLUGIN_UNDEF; plugin++) missing = !bd_is_plugin_available(plugin); if (!missing) { @@ -757,6 +763,9 @@ gboolean bd_is_plugin_available (BDPlugin plugin) { * %NULL if none is loaded */ gchar* bd_get_plugin_soname (BDPlugin plugin) { + if (plugin >= BD_PLUGIN_UNDEF) + return NULL; + if (plugins[plugin].handle) return g_strdup (plugins[plugin].spec.so_name); @@ -770,5 +779,8 @@ gchar* bd_get_plugin_soname (BDPlugin plugin) { * Returns: (transfer none): name of the plugin */ gchar* bd_get_plugin_name (BDPlugin plugin) { + if (plugin >= BD_PLUGIN_UNDEF) + return NULL; + return plugin_names[plugin]; } diff --git a/src/lib/plugin_apis/crypto.api b/src/lib/plugin_apis/crypto.api index adf43ffc6..3ebdfde55 100644 --- a/src/lib/plugin_apis/crypto.api +++ b/src/lib/plugin_apis/crypto.api @@ -1058,7 +1058,7 @@ gboolean bd_crypto_luks_suspend (const gchar *luks_device, GError **error); /** * bd_crypto_luks_resume: * @luks_device: LUKS device to resume - * @context: (nullable): key slot context (passphrase/keyfile/token...) for @luks_device + * @context: key slot context (passphrase/keyfile/token...) for @luks_device * @error: (out) (optional): place to store error (if any) * * Supported @context types for this function: passphrase, key file diff --git a/src/plugins/crypto.c b/src/plugins/crypto.c index 9e9b09c11..e65b532ad 100644 --- a/src/plugins/crypto.c +++ b/src/plugins/crypto.c @@ -360,6 +360,7 @@ gboolean bd_crypto_init (void) { * */ void bd_crypto_close (void) { + freelocale (c_locale); c_locale = (locale_t) 0; crypt_set_log_callback (NULL, NULL, NULL); crypt_set_debug_level (CRYPT_DEBUG_NONE); @@ -770,14 +771,17 @@ void bd_crypto_keyslot_context_free (BDCryptoKeyslotContext *context) { if (context == NULL) return; - if (context->type == BD_CRYPTO_KEYSLOT_CONTEXT_TYPE_PASSPHRASE) + if (context->type == BD_CRYPTO_KEYSLOT_CONTEXT_TYPE_PASSPHRASE) { + explicit_bzero (context->u.passphrase.pass_data, context->u.passphrase.data_len); g_free (context->u.passphrase.pass_data); - else if (context->type == BD_CRYPTO_KEYSLOT_CONTEXT_TYPE_KEYFILE) + } else if (context->type == BD_CRYPTO_KEYSLOT_CONTEXT_TYPE_KEYFILE) g_free (context->u.keyfile.keyfile); else if (context->type == BD_CRYPTO_KEYSLOT_CONTEXT_TYPE_KEYRING) g_free (context->u.keyring.key_desc); - else if (context->type == BD_CRYPTO_KEYSLOT_CONTEXT_TYPE_VOLUME_KEY) + else if (context->type == BD_CRYPTO_KEYSLOT_CONTEXT_TYPE_VOLUME_KEY) { + explicit_bzero (context->u.volume_key.volume_key, context->u.volume_key.volume_key_size); g_free (context->u.volume_key.volume_key); + } g_free (context); } @@ -1543,6 +1547,8 @@ gboolean bd_crypto_luks_add_key (const gchar *device, BDCryptoKeyslotContext *co } else { g_set_error (&l_error, BD_CRYPTO_ERROR, BD_CRYPTO_ERROR_INVALID_CONTEXT, "Only 'passphrase' and 'key file' context types are valid for LUKS add key."); + if (context->type == BD_CRYPTO_KEYSLOT_CONTEXT_TYPE_KEYFILE) + crypt_safe_free (key_buf); bd_utils_report_finished (progress_id, l_error->message); g_propagate_error (error, l_error); crypt_free (cd); @@ -1642,6 +1648,7 @@ gboolean bd_crypto_luks_remove_key (const gchar *device, BDCryptoKeyslotContext if (ret < 0) { g_set_error (&l_error, BD_CRYPTO_ERROR, BD_CRYPTO_ERROR_KEY_SLOT, "Failed to determine key slot: %s", strerror_l (-ret, c_locale)); + crypt_free (cd); bd_utils_report_finished (progress_id, l_error->message); g_propagate_error (error, l_error); return FALSE; @@ -1753,6 +1760,8 @@ gboolean bd_crypto_luks_change_key (const gchar *device, BDCryptoKeyslotContext } else { g_set_error (&l_error, BD_CRYPTO_ERROR, BD_CRYPTO_ERROR_INVALID_CONTEXT, "Only 'passphrase' and 'key file' context types are valid for LUKS change key."); + if (context->type == BD_CRYPTO_KEYSLOT_CONTEXT_TYPE_KEYFILE) + crypt_safe_free (key_buf); bd_utils_report_finished (progress_id, l_error->message); g_propagate_error (error, l_error); crypt_free (cd); @@ -1951,7 +1960,7 @@ gboolean bd_crypto_luks_suspend (const gchar *luks_device, GError **error) { /** * bd_crypto_luks_resume: * @luks_device: LUKS device to resume - * @context: (nullable): key slot context (passphrase/keyfile/token...) for @luks_device + * @context: key slot context (passphrase/keyfile/token...) for @luks_device * @error: (out) (optional): place to store error (if any) * * Supported @context types for this function: passphrase, key file @@ -2252,7 +2261,7 @@ gboolean bd_crypto_luks_set_label (const gchar *device, const gchar *label, cons if (g_strcmp0 (crypt_get_type (cd), CRYPT_LUKS2) != 0) { g_set_error (error, BD_CRYPTO_ERROR, BD_CRYPTO_ERROR_TECH_UNAVAIL, - "Label can be set only on LUKS 2 devices: %s", strerror_l (-ret, c_locale)); + "Label can be set only on LUKS 2 devices."); crypt_free (cd); return FALSE; } @@ -2965,11 +2974,10 @@ gboolean bd_crypto_integrity_format (const gchar *device, const gchar *algorithm ret = crypt_deactivate (cd, tmp_name); if (ret != 0) bd_utils_log_format (BD_UTILS_LOG_ERR, "Failed to deactivate temporary device %s", tmp_name); - - } else - bd_utils_report_finished (progress_id, "Completed"); + } crypt_free (cd); + bd_utils_report_finished (progress_id, "Completed"); return TRUE; } @@ -3909,7 +3917,7 @@ gboolean bd_crypto_opal_is_supported (const gchar *device, GError **error) { g_set_error (error, BD_CRYPTO_ERROR, BD_CRYPTO_ERROR_DEVICE, "Failed to get opal status for the device '%s': %s", device, - strerror_l (-ret, c_locale)); + strerror_l (errno, c_locale)); close (fd); return FALSE; } @@ -4146,6 +4154,9 @@ gboolean bd_crypto_opal_reset_device (const gchar *device, BDCryptoKeyslotContex } ret = crypt_wipe_hw_opal (cd, CRYPT_NO_SEGMENT, key_buf, buf_len, 0); + if (context->type == BD_CRYPTO_KEYSLOT_CONTEXT_TYPE_KEYFILE) + crypt_safe_free (key_buf); + if (ret != 0) { g_set_error (&l_error, BD_CRYPTO_ERROR, BD_CRYPTO_ERROR_DEVICE, "Failed to wipe LUKS HW-OPAL device: %s", strerror_l (-ret, c_locale)); diff --git a/src/plugins/dm.c b/src/plugins/dm.c index 51cc1e9c1..d764232d8 100644 --- a/src/plugins/dm.c +++ b/src/plugins/dm.c @@ -126,7 +126,7 @@ gboolean bd_dm_is_tech_avail (BDDMTech tech, guint64 mode G_GNUC_UNUSED, GError */ gboolean bd_dm_create_linear (const gchar *map_name, const gchar *device, guint64 length, const gchar *uuid, GError **error) { gboolean success = FALSE; - const gchar *argv[9] = {"dmsetup", "create", map_name, "--table", NULL, NULL, NULL, NULL, NULL}; + const gchar *argv[8] = {"dmsetup", "create", map_name, "--table", NULL, NULL, NULL, NULL}; if (!check_deps (&avail_deps, DEPS_DMSETUP_MASK, deps, DEPS_LAST, &deps_check_lock, error)) return FALSE; @@ -137,9 +137,7 @@ gboolean bd_dm_create_linear (const gchar *map_name, const gchar *device, guint6 if (uuid) { argv[5] = "-u"; argv[6] = uuid; - argv[7] = device; - } else - argv[5] = device; + } success = bd_utils_exec_and_report_error (argv, NULL, error); g_free (table); diff --git a/src/plugins/fs/btrfs.c b/src/plugins/fs/btrfs.c index e0290c6e3..71071809c 100644 --- a/src/plugins/fs/btrfs.c +++ b/src/plugins/fs/btrfs.c @@ -326,7 +326,7 @@ BDFSBtrfsInfo* bd_fs_btrfs_get_info (const gchar *mpoint, GError **error) { GRegex *regex = NULL; GMatchInfo *match_info = NULL; BDFSBtrfsInfo *ret = NULL; - g_autofree gchar *item = NULL; + gchar *item = NULL; guint64 num_devices = 0; guint64 min_size = 0; gint scanned = 0; @@ -351,12 +351,14 @@ BDFSBtrfsInfo* bd_fs_btrfs_get_info (const gchar *mpoint, GError **error) { success = g_regex_match (regex, output, 0, &match_info); if (!success) { + g_set_error (error, BD_FS_ERROR, BD_FS_ERROR_PARSE, + "Failed to parse btrfs filesystem information"); g_regex_unref (regex); g_match_info_free (match_info); return NULL; } - ret = g_new (BDFSBtrfsInfo, 1); + ret = g_new0 (BDFSBtrfsInfo, 1); ret->label = g_match_info_fetch_named (match_info, "label"); ret->uuid = g_match_info_fetch_named (match_info, "uuid"); @@ -368,14 +370,17 @@ BDFSBtrfsInfo* bd_fs_btrfs_get_info (const gchar *mpoint, GError **error) { "Btrfs filesystem mounted on %s spans multiple devices (%"G_GUINT64_FORMAT")." \ "Filesystem plugin is not suitable for multidevice Btrfs volumes, please use " \ "Btrfs plugin instead.", mpoint, num_devices); + g_free (item); g_match_info_free (match_info); g_regex_unref (regex); bd_fs_btrfs_info_free (ret); return NULL; } + g_free (item); item = g_match_info_fetch_named (match_info, "size"); ret->size = g_ascii_strtoull (item, NULL, 0); + g_free (item); g_match_info_free (match_info); g_regex_unref (regex); diff --git a/src/plugins/fs/common.c b/src/plugins/fs/common.c index b6fcbbf5f..586484a4b 100644 --- a/src/plugins/fs/common.c +++ b/src/plugins/fs/common.c @@ -115,7 +115,8 @@ get_uuid_label (const gchar *device, gchar **uuid, gchar **label, GError **error "Failed to get UUID for the device '%s'", device); blkid_free_probe (probe); synced_close (fd); - g_free (label); + g_free (*label); + *label = NULL; return FALSE; } diff --git a/src/plugins/fs/mount.c b/src/plugins/fs/mount.c index ef83c22cb..eaf098a9b 100644 --- a/src/plugins/fs/mount.c +++ b/src/plugins/fs/mount.c @@ -764,7 +764,7 @@ gboolean bd_fs_mount (const gchar *device, const gchar *mountpoint, const gchar } } else { g_set_error (error, BD_FS_ERROR, BD_FS_ERROR_FAIL, - "Unsupported argument for unmount: '%s'", (*extra_p)->opt); + "Unsupported argument for mount: '%s'", (*extra_p)->opt); return FALSE; } } @@ -811,6 +811,7 @@ gchar* bd_fs_get_mountpoint (const gchar *device, GError **error) { g_set_error (error, BD_FS_ERROR, BD_FS_ERROR_FAIL, "Failed to set cache for mount info table."); mnt_free_table (table); + mnt_free_cache (cache); return NULL; } @@ -832,14 +833,12 @@ gchar* bd_fs_get_mountpoint (const gchar *device, GError **error) { target = mnt_fs_get_target (fs); if (!target) { - mnt_free_fs (fs); mnt_free_table (table); mnt_free_cache (cache); return NULL; } mountpoint = g_strdup (target); - mnt_free_fs (fs); mnt_free_table (table); mnt_free_cache (cache); return mountpoint; @@ -869,6 +868,7 @@ gboolean bd_fs_is_mountpoint (const gchar *path, GError **error) { g_set_error (error, BD_FS_ERROR, BD_FS_ERROR_FAIL, "Failed to set cache for mount info table."); mnt_free_table (table); + mnt_free_cache (cache); return FALSE; } @@ -890,13 +890,11 @@ gboolean bd_fs_is_mountpoint (const gchar *path, GError **error) { target = mnt_fs_get_target (fs); if (!target) { - mnt_free_fs (fs); mnt_free_table (table); mnt_free_cache (cache); return FALSE; } - mnt_free_fs (fs); mnt_free_table (table); mnt_free_cache (cache); return TRUE; diff --git a/src/plugins/fs/ntfs.c b/src/plugins/fs/ntfs.c index 6bc552ee9..a7b626c7d 100644 --- a/src/plugins/fs/ntfs.c +++ b/src/plugins/fs/ntfs.c @@ -372,7 +372,7 @@ BDFSNtfsInfo* bd_fs_ntfs_get_info (const gchar *device, GError **error) { mountpoint = bd_fs_get_mountpoint (device, &l_error); if (mountpoint != NULL) { - g_set_error (error, BD_FS_ERROR, BD_FS_ERROR_NOT_MOUNTED, + g_set_error (error, BD_FS_ERROR, BD_FS_ERROR_FAIL, "Can't get NTFS file system information for '%s': Device is mounted.", device); return NULL; } else { @@ -403,7 +403,7 @@ BDFSNtfsInfo* bd_fs_ntfs_get_info (const gchar *device, GError **error) { line_p = lines; /* find the beginning of the (data) section we are interested in */ - while (line_p && *line_p && !strstr (*line_p, "Cluster Size")) + while (line_p && *line_p && !strstr (*line_p, "Cluster Size:")) line_p++; if (!line_p || !(*line_p)) { g_set_error (error, BD_FS_ERROR, BD_FS_ERROR_PARSE, "Failed to parse NTFS file system information"); @@ -417,7 +417,7 @@ BDFSNtfsInfo* bd_fs_ntfs_get_info (const gchar *device, GError **error) { val_start++; cluster_size = g_ascii_strtoull (val_start, NULL, 0); - while (line_p && *line_p && !strstr (*line_p, "Volume Size in Clusters")) + while (line_p && *line_p && !strstr (*line_p, "Volume Size in Clusters:")) line_p++; if (!line_p || !(*line_p)) { g_set_error (error, BD_FS_ERROR, BD_FS_ERROR_PARSE, "Failed to parse NTFS file system information"); @@ -431,7 +431,7 @@ BDFSNtfsInfo* bd_fs_ntfs_get_info (const gchar *device, GError **error) { val_start++; ret->size = g_ascii_strtoull (val_start, NULL, 0) * cluster_size; - while (line_p && *line_p && !strstr (*line_p, "Free Clusters")) + while (line_p && *line_p && !strstr (*line_p, "Free Clusters:")) line_p++; if (!line_p || !(*line_p)) { g_set_error (error, BD_FS_ERROR, BD_FS_ERROR_PARSE, "Failed to parse NTFS file system information"); diff --git a/src/plugins/loop.c b/src/plugins/loop.c index 037dde841..f17e445bb 100644 --- a/src/plugins/loop.c +++ b/src/plugins/loop.c @@ -480,7 +480,7 @@ gboolean bd_loop_set_autoclear (const gchar *loop, gboolean autoclear, GError ** if (!g_str_has_prefix (loop, "/dev/")) dev_loop = g_strdup_printf ("/dev/%s", loop); - msg = g_strdup_printf ("Started setting up the autoclear flag on the /dev/%s device", + msg = g_strdup_printf ("Started setting up the autoclear flag on the %s device", dev_loop ? dev_loop : loop); progress_id = bd_utils_report_started (msg); g_free (msg); diff --git a/src/plugins/lvm/lvm-common.c b/src/plugins/lvm/lvm-common.c index b5ec770b9..847d96ba3 100644 --- a/src/plugins/lvm/lvm-common.c +++ b/src/plugins/lvm/lvm-common.c @@ -620,7 +620,7 @@ static gboolean _lvm_devices_enabled () { gboolean ret = FALSE; GError *loc_error = NULL; gchar *output = NULL; - gboolean enabled = FALSE; + guint enabled = 0; gint scanned = 0; g_autofree gchar *config_arg = NULL; @@ -643,7 +643,7 @@ static gboolean _lvm_devices_enabled () { if (scanned != 1) return FALSE; - return enabled; + return enabled != 0; } else { g_clear_error (&loc_error); g_free (output); @@ -660,7 +660,7 @@ static gboolean _lvm_devices_enabled () { if (scanned != 1) return FALSE; - return enabled; + return enabled != 0; } else { g_clear_error (&loc_error); g_free (output); @@ -791,7 +791,6 @@ gchar* bd_lvm_config_get (const gchar *section, const gchar *setting, const gcha gboolean _vgcfgbackup_restore (const gchar *command, const gchar *vg_name, const gchar *file, const BDExtraArg **extra, GError **error) { const gchar *args[6] = {"lvm", NULL, NULL, NULL, NULL, NULL}; guint next_arg = 1; - gchar *output = NULL; g_autofree gchar *config_arg = NULL; args[next_arg++] = command; @@ -808,7 +807,7 @@ gboolean _vgcfgbackup_restore (const gchar *command, const gchar *vg_name, const } g_mutex_unlock (&global_config_lock); - return bd_utils_exec_and_capture_output (args, extra, &output, error); + return bd_utils_exec_and_report_error (args, extra, error); } /** diff --git a/src/plugins/lvm/lvm.c b/src/plugins/lvm/lvm.c index 51d5354db..f591c68ae 100644 --- a/src/plugins/lvm/lvm.c +++ b/src/plugins/lvm/lvm.c @@ -281,7 +281,7 @@ static const UtilDep deps[DEPS_LAST] = { #define FEATURES_VDO 0 #define FEATURES_VDO_MASK (1 << FEATURES_VDO) -#define FEATURES_WRITECACHE 0 +#define FEATURES_WRITECACHE 1 #define FEATURES_WRITECACHE_MASK (1 << FEATURES_WRITECACHE) #define FEATURES_LAST 2 @@ -1157,14 +1157,15 @@ BDLVMPVdata** bd_lvm_pvs (GError **error) { guint num_items; GPtrArray *pvs; BDLVMPVdata *pvdata = NULL; + GError *l_error = NULL; pvs = g_ptr_array_new (); - success = call_lvm_and_capture_output (args, NULL, &output, error); + success = call_lvm_and_capture_output (args, NULL, &output, &l_error); if (!success) { - if (g_error_matches (*error, BD_UTILS_EXEC_ERROR, BD_UTILS_EXEC_ERROR_NOOUT)) { - /* no output => no VGs, not an error */ - g_clear_error (error); + if (g_error_matches (l_error, BD_UTILS_EXEC_ERROR, BD_UTILS_EXEC_ERROR_NOOUT)) { + /* no output => no PVs, not an error */ + g_clear_error (&l_error); /* return an empty list */ g_ptr_array_add (pvs, NULL); return (BDLVMPVdata **) g_ptr_array_free (pvs, FALSE); @@ -1172,6 +1173,7 @@ BDLVMPVdata** bd_lvm_pvs (GError **error) { else { /* the error is already populated from the call */ g_ptr_array_free (pvs, TRUE); + g_propagate_error (error, l_error); return NULL; } } @@ -1487,7 +1489,7 @@ BDLVMVGdata* bd_lvm_vginfo (const gchar *vg_name, GError **error) { BDLVMVGdata** bd_lvm_vgs (GError **error) { const gchar *args[9] = {"vgs", "--noheadings", "--nosuffix", "--nameprefixes", "--unquoted", "--units=b", - "-o", "name,uuid,size,free,extent_size,extent_count,free_count,pv_count,vg_tags", + "-o", "name,uuid,size,free,extent_size,extent_count,free_count,pv_count,vg_exported,vg_tags", NULL}; GHashTable *table = NULL; gboolean success = FALSE; @@ -1522,7 +1524,7 @@ BDLVMVGdata** bd_lvm_vgs (GError **error) { for (lines_p = lines; *lines_p; lines_p++) { table = parse_lvm_vars ((*lines_p), &num_items); - if (table && (num_items == 9)) { + if (table && (num_items == 10)) { /* valid line, try to parse and record it */ vgdata = get_vg_data_from_table (table, TRUE); if (vgdata) @@ -1590,7 +1592,7 @@ gchar* bd_lvm_lvorigin (const gchar *vg_name, const gchar *lv_name, GError **err * Tech category: %BD_LVM_TECH_BASIC-%BD_LVM_TECH_MODE_CREATE */ gboolean bd_lvm_lvcreate (const gchar *vg_name, const gchar *lv_name, guint64 size, const gchar *type, const gchar **pv_list, const BDExtraArg **extra, GError **error) { - guint8 pv_list_len = pv_list ? g_strv_length ((gchar **) pv_list) : 0; + guint pv_list_len = pv_list ? g_strv_length ((gchar **) pv_list) : 0; const gchar **args = g_new0 (const gchar*, pv_list_len + 10); gboolean success = FALSE; guint64 i = 0; @@ -2560,7 +2562,7 @@ gboolean bd_lvm_cache_create_cached_lv (const gchar *vg_name, const gchar *lv_na success = bd_lvm_cache_attach (vg_name, lv_name, name, NULL, &l_error); if (!success) { - g_prefix_error (error, "Failed to attach the cache pool '%s' to the data LV: ", name); + g_prefix_error (&l_error, "Failed to attach the cache pool '%s' to the data LV: ", name); g_free (name); bd_utils_report_finished (progress_id, l_error->message); g_propagate_error (error, l_error); @@ -3078,7 +3080,7 @@ gboolean bd_lvm_vdo_pool_convert (const gchar *vg_name, const gchar *pool_lv, co "--deduplication", deduplication ? "y" : "n", NULL, NULL, NULL, NULL, NULL, NULL}; gboolean success = FALSE; - guint next_arg = 4; + guint next_arg = 8; gchar *size_str = NULL; gchar *lv_spec = NULL; gchar *old_config = NULL; diff --git a/src/plugins/mdraid.c b/src/plugins/mdraid.c index ee3aef1b4..1a1de32dd 100644 --- a/src/plugins/mdraid.c +++ b/src/plugins/mdraid.c @@ -1058,7 +1058,6 @@ BDMDExamineData* bd_md_examine (const gchar *device, GError **error) { /* something bad happened or some expected items were missing */ g_set_error (error, BD_MD_ERROR, BD_MD_ERROR_PARSE, "Failed to parse mdexamine metadata"); - g_hash_table_destroy (table); bd_md_examine_data_free (ret); return NULL; } @@ -1133,6 +1132,12 @@ BDMDDetailData* bd_md_detail (const gchar *raid_spec, GError **error) { orig_uuid = ret->uuid; if (orig_uuid) { ret->uuid = bd_md_canonicalize_uuid (orig_uuid, error); + if (!ret->uuid) { + g_prefix_error (error, "Failed to canonicalize MD UUID '%s': ", orig_uuid); + g_free (orig_uuid); + bd_md_detail_data_free (ret); + return NULL; + } g_free (orig_uuid); } diff --git a/src/plugins/mpath.c b/src/plugins/mpath.c index dd231bf60..6a62d010e 100644 --- a/src/plugins/mpath.c +++ b/src/plugins/mpath.c @@ -286,7 +286,7 @@ static gchar** get_map_deps (const gchar *map_name, guint64 *n_deps, GError **er if (l_error) { g_propagate_prefixed_error (error, l_error, "Failed to resolve '%s' to device name", major_minor); - g_free (dep_devs); + g_strfreev (dep_devs); g_free (major_minor); return NULL; } @@ -333,8 +333,10 @@ gboolean bd_mpath_is_mpath_member (const gchar *device, GError **error) { dm_task_run (task_names); names = dm_task_get_names (task_names); - if (!names || !names->dev) + if (!names || !names->dev) { + dm_task_destroy (task_names); return FALSE; + } /* in case the device is dev_path, we need to resolve it because maps's deps are devices and not their dev_paths */ @@ -431,6 +433,7 @@ gchar** bd_mpath_get_mpath_members (GError **error) { names = dm_task_get_names (task_names); if (!names || !names->dev) { + dm_task_destroy (task_names); bd_utils_report_finished (progress_id, "Completed"); return NULL; } diff --git a/src/plugins/nvme/nvme-fabrics.c b/src/plugins/nvme/nvme-fabrics.c index 4445141e9..918481f62 100644 --- a/src/plugins/nvme/nvme-fabrics.c +++ b/src/plugins/nvme/nvme-fabrics.c @@ -684,7 +684,7 @@ gboolean bd_nvme_set_host_nqn (const gchar *host_nqn, GError **error) { return FALSE; } filename = g_build_filename (path, "hostnqn", NULL); - if (host_nqn[strlen (host_nqn) - 1] != '\n') + if (strlen (host_nqn) == 0 || host_nqn[strlen (host_nqn) - 1] != '\n') s = g_strdup_printf ("%s\n", host_nqn); else s = g_strdup (host_nqn); @@ -728,7 +728,7 @@ gboolean bd_nvme_set_host_id (const gchar *host_id, GError **error) { return FALSE; } filename = g_build_filename (path, "hostid", NULL); - if (host_id[strlen (host_id) - 1] != '\n') + if (strlen (host_id) == 0 || host_id[strlen (host_id) - 1] != '\n') s = g_strdup_printf ("%s\n", host_id); else s = g_strdup (host_id); diff --git a/src/plugins/nvme/nvme-info.c b/src/plugins/nvme/nvme-info.c index fb99938c7..b36a644b5 100644 --- a/src/plugins/nvme/nvme-info.c +++ b/src/plugins/nvme/nvme-info.c @@ -479,8 +479,10 @@ BDNVMEControllerInfo * bd_nvme_get_controller_info (const gchar *device, GError return NULL; ctrl_id = _nvme_alloc (sizeof (struct nvme_id_ctrl), error); - if (!ctrl_id) + if (!ctrl_id) { + close (fd); return NULL; + } /* send the NVME_IDENTIFY_CNS_CTRL ioctl */ ret = nvme_identify_ctrl (fd, ctrl_id); if (ret != 0) { @@ -601,6 +603,7 @@ BDNVMENamespaceInfo *bd_nvme_get_namespace_info (const gchar *device, GError **e struct nvme_ns_id_desc *descs = NULL; guint8 flbas; guint i; + guint j; guint len; BDNVMENamespaceInfo *info; GPtrArray *ptr_array; @@ -685,14 +688,14 @@ BDNVMENamespaceInfo *bd_nvme_get_namespace_info (const gchar *device, GError **e case NVME_NIDT_EUI64: g_free (info->eui64); info->eui64 = g_malloc0 (d->nidl * 2 + 1); - for (i = 0; i < d->nidl; i++) - snprintf (info->eui64 + i * 2, 3, "%02x", d->nid[i]); + for (j = 0; j < d->nidl; j++) + snprintf (info->eui64 + j * 2, 3, "%02x", d->nid[j]); break; case NVME_NIDT_NGUID: g_free (info->nguid); info->nguid = g_malloc0 (d->nidl * 2 + 1); - for (i = 0; i < d->nidl; i++) - snprintf (info->nguid + i * 2, 3, "%02x", d->nid[i]); + for (j = 0; j < d->nidl; j++) + snprintf (info->nguid + j * 2, 3, "%02x", d->nid[j]); break; case NVME_NIDT_UUID: g_free (info->uuid); diff --git a/src/plugins/part.c b/src/plugins/part.c index 0b87846e4..03a5c8564 100644 --- a/src/plugins/part.c +++ b/src/plugins/part.c @@ -308,6 +308,7 @@ gboolean bd_part_init (void) { * */ void bd_part_close (void) { + freelocale (c_locale); c_locale = (locale_t) 0; } @@ -476,6 +477,8 @@ static gchar* get_part_type_guid_and_gpt_flags (const gchar *device, int part_nu if (!ptype_string) { g_set_error (error, BD_PART_ERROR, BD_PART_ERROR_FAIL, "Failed to get partition type for partition %d on device '%s'", part_num, device); + g_free (*type_name); + *type_name = NULL; fdisk_unref_partition (pa); close_context (cxt); return NULL; @@ -1825,9 +1828,11 @@ gboolean bd_part_set_part_name (const gchar *disk, const gchar *part, const gcha progress_id = bd_utils_report_started (msg); g_free (msg); - cxt = get_device_context (disk, FALSE, error); + cxt = get_device_context (disk, FALSE, &l_error); if (!cxt) { /* error is already populated */ + bd_utils_report_finished (progress_id, l_error->message); + g_propagate_error (error, l_error); return FALSE; } @@ -2056,9 +2061,11 @@ gboolean bd_part_set_part_uuid (const gchar *disk, const gchar *part, const gcha progress_id = bd_utils_report_started (msg); g_free (msg); - cxt = get_device_context (disk, FALSE, error); + cxt = get_device_context (disk, FALSE, &l_error); if (!cxt) { /* error is already populated */ + bd_utils_report_finished (progress_id, l_error->message); + g_propagate_error (error, l_error); return FALSE; } diff --git a/src/plugins/s390.c b/src/plugins/s390.c index 20a59828e..15b0644ed 100644 --- a/src/plugins/s390.c +++ b/src/plugins/s390.c @@ -243,7 +243,7 @@ gboolean bd_s390_dasd_online (const gchar *dasd, GError **error) { g_propagate_error (error, l_error); return FALSE; } - if (online == 1) { + if (online == '1') { g_set_error (&l_error, BD_S390_ERROR, BD_S390_ERROR_DEVICE, "DASD device %s is already online.", dasd); fclose (fd); @@ -607,7 +607,7 @@ gboolean bd_s390_zfcp_online (const gchar *devno, const gchar *wwpn, const gchar g_propagate_error (error, l_error); return FALSE; } - if (rc == 1) { + if (rc == '1') { /* otherwise device's status indicates that it's already online, so just close the fd and proceed; we don't return because although 'online' status may be correct, the device may not be completely online and ready @@ -633,10 +633,11 @@ gboolean bd_s390_zfcp_online (const gchar *devno, const gchar *wwpn, const gchar portdir = g_strdup_printf ("%s/%s/%s", zfcpsysfs, devno, wwpn); pdfd = opendir (portdir); if (!pdfd) { - g_set_error (error, BD_S390_ERROR, BD_S390_ERROR_DEVICE, + g_set_error (&l_error, BD_S390_ERROR, BD_S390_ERROR_DEVICE, "WWPN %s not found for zFCP device %s", wwpn, devno); g_free (portdir); - bd_utils_report_finished (progress_id, (*error)->message); + bd_utils_report_finished (progress_id, l_error->message); + g_propagate_error (error, l_error); return FALSE; } closedir (pdfd); @@ -796,6 +797,8 @@ gboolean bd_s390_zfcp_scsi_offline (const gchar *devno, const gchar *wwpn, const g_free (hba_path); g_free (fcpsysfs); g_free (scsidev); + fclose (scsifd); + g_free (line); bd_utils_report_finished (progress_id, l_error->message); g_propagate_error (error, l_error); return FALSE; @@ -808,6 +811,8 @@ gboolean bd_s390_zfcp_scsi_offline (const gchar *devno, const gchar *wwpn, const g_free (hba_path); g_free (fcpsysfs); g_free (scsidev); + fclose (scsifd); + g_free (line); bd_utils_report_finished (progress_id, l_error->message); g_propagate_error (error, l_error); return FALSE; @@ -827,6 +832,8 @@ gboolean bd_s390_zfcp_scsi_offline (const gchar *devno, const gchar *wwpn, const g_free (fcphbasysfs); g_free (fcpsysfs); g_free (scsidev); + fclose (scsifd); + g_free (line); bd_utils_report_finished (progress_id, l_error->message); g_propagate_error (error, l_error); return FALSE; @@ -840,6 +847,8 @@ gboolean bd_s390_zfcp_scsi_offline (const gchar *devno, const gchar *wwpn, const g_free (fcpsysfs); g_free (scsidev); fclose (fd); + fclose (scsifd); + g_free (line); bd_utils_report_finished (progress_id, l_error->message); g_propagate_error (error, l_error); return FALSE; @@ -860,6 +869,8 @@ gboolean bd_s390_zfcp_scsi_offline (const gchar *devno, const gchar *wwpn, const g_free (fcphbasysfs); g_free (fcpsysfs); g_free (scsidev); + fclose (scsifd); + g_free (line); bd_utils_report_finished (progress_id, l_error->message); g_propagate_error (error, l_error); return FALSE; @@ -874,6 +885,8 @@ gboolean bd_s390_zfcp_scsi_offline (const gchar *devno, const gchar *wwpn, const g_free (fcphbasysfs); g_free (fcpsysfs); g_free (scsidev); + fclose (scsifd); + g_free (line); bd_utils_report_finished (progress_id, l_error->message); g_propagate_error (error, l_error); return FALSE; @@ -896,6 +909,8 @@ gboolean bd_s390_zfcp_scsi_offline (const gchar *devno, const gchar *wwpn, const g_free (fcpwwpnsysfs); g_free (fcphbasysfs); g_free (scsidev); + fclose (scsifd); + g_free (line); bd_utils_report_finished (progress_id, l_error->message); g_propagate_error (error, l_error); return FALSE; @@ -910,19 +925,28 @@ gboolean bd_s390_zfcp_scsi_offline (const gchar *devno, const gchar *wwpn, const g_free (fcpwwpnsysfs); g_free (fcphbasysfs); g_free (scsidev); + fclose (scsifd); + g_free (line); bd_utils_report_finished (progress_id, l_error->message); g_propagate_error (error, l_error); return FALSE; } fclose (fd); } + + g_free (scsidel); + scsidel = NULL; + g_free (scsidev); + scsidev = NULL; + g_free (fcplunsysfs); + fcplunsysfs = NULL; + g_free (fcpwwpnsysfs); + fcpwwpnsysfs = NULL; + g_free (fcphbasysfs); + fcphbasysfs = NULL; } fclose (scsifd); - g_free (scsidel); - g_free (fcplunsysfs); - g_free (fcpwwpnsysfs); - g_free (fcphbasysfs); - g_free (scsidev); + g_free (line); bd_utils_report_finished (progress_id, "Completed"); return TRUE; } @@ -1022,7 +1046,7 @@ gboolean bd_s390_zfcp_offline (const gchar *devno, const gchar *wwpn, const gcha g_free (offline); if (!success) { g_set_error (&l_error, BD_S390_ERROR, BD_S390_ERROR_DEVICE, - "Could not set zFCP device %s online", devno); + "Could not set zFCP device %s offline", devno); bd_utils_report_finished (progress_id, l_error->message); g_propagate_error (error, l_error); return FALSE; diff --git a/src/plugins/swap.c b/src/plugins/swap.c index e6d1f744a..2ba3d333b 100644 --- a/src/plugins/swap.c +++ b/src/plugins/swap.c @@ -347,10 +347,11 @@ gboolean bd_swap_swapon (const gchar *device, gint priority, GError **error) { "Failed to activate swap on %s: %m", device); bd_utils_report_finished (progress_id, l_error->message); g_propagate_error (error, l_error); + return FALSE; } bd_utils_report_finished (progress_id, "Completed"); - return ret == 0; + return TRUE; } /** @@ -378,10 +379,11 @@ gboolean bd_swap_swapoff (const gchar *device, GError **error) { "Failed to deactivate swap on %s: %m", device); bd_utils_report_finished (progress_id, l_error->message); g_propagate_error (error, l_error); + return FALSE; } bd_utils_report_finished (progress_id, "Completed"); - return ret == 0; + return TRUE; } /** @@ -424,15 +426,16 @@ gboolean bd_swap_swapstatus (const gchar *device, GError **error) { return TRUE; } - next_line = (strchr (file_content, '\n') + 1); + next_line = strchr (file_content, '\n'); while (next_line && ((gsize)(next_line - file_content) < length)) { + next_line++; if (g_str_has_prefix (next_line, real_device ? real_device : device)) { g_free (real_device); g_free (file_content); return TRUE; } - next_line = (strchr (next_line, '\n') + 1); + next_line = strchr (next_line, '\n'); } g_free (real_device); diff --git a/src/utils/dbus.c b/src/utils/dbus.c index ebaaa8ed8..fc68415f9 100644 --- a/src/utils/dbus.c +++ b/src/utils/dbus.c @@ -62,14 +62,14 @@ gboolean bd_utils_dbus_service_available (GDBusConnection *connection, GBusType g_prefix_error (error, "Failed to get system bus: "); return FALSE; } + } - ret = g_dbus_connection_call_sync (bus, DBUS_TOP_IFACE, DBUS_TOP_OBJ, DBUS_TOP_IFACE, - "ListNames", NULL, NULL, G_DBUS_CALL_FLAGS_NONE, - -1, NULL, error); - if (!ret) { - g_object_unref (bus); - return FALSE; - } + ret = g_dbus_connection_call_sync (bus, DBUS_TOP_IFACE, DBUS_TOP_OBJ, DBUS_TOP_IFACE, + "ListNames", NULL, NULL, G_DBUS_CALL_FLAGS_NONE, + -1, NULL, error); + if (!ret) { + g_object_unref (bus); + return FALSE; } real_ret = g_variant_get_child_value (ret, 0); diff --git a/src/utils/exec.c b/src/utils/exec.c index e8b3b6ba2..89fb23489 100644 --- a/src/utils/exec.c +++ b/src/utils/exec.c @@ -677,12 +677,14 @@ gint bd_utils_version_cmp (const gchar *ver_string1, const gchar *ver_string2, G if (!success) { g_set_error (error, BD_UTILS_EXEC_ERROR, BD_UTILS_EXEC_ERROR_INVAL_VER, "Invalid or unsupported version (1) format: %s", ver_string1); + g_regex_unref (regex); return -2; } success = g_regex_match (regex, ver_string2, 0, NULL); if (!success) { g_set_error (error, BD_UTILS_EXEC_ERROR, BD_UTILS_EXEC_ERROR_INVAL_VER, "Invalid or unsupported version (2) format: %s", ver_string2); + g_regex_unref (regex); return -2; } g_regex_unref (regex); @@ -955,8 +957,13 @@ gboolean bd_utils_echo_str_to_file (const gchar *str, const gchar *file_path, GE gsize bytes_written = 0; out_file = g_io_channel_new_file (file_path, "w", error); - if (!out_file || g_io_channel_write_chars (out_file, str, -1, &bytes_written, error) != G_IO_STATUS_NORMAL) { + if (!out_file) { + g_prefix_error (error, "Failed to write '%s' to file '%s': ", str, file_path); + return FALSE; + } + if (g_io_channel_write_chars (out_file, str, -1, &bytes_written, error) != G_IO_STATUS_NORMAL) { g_prefix_error (error, "Failed to write '%s' to file '%s': ", str, file_path); + g_io_channel_unref (out_file); return FALSE; } if (g_io_channel_shutdown (out_file, TRUE, error) != G_IO_STATUS_NORMAL) { diff --git a/tests/_lvm_cases.py b/tests/_lvm_cases.py index a00d50554..770d37ff8 100644 --- a/tests/_lvm_cases.py +++ b/tests/_lvm_cases.py @@ -2134,7 +2134,8 @@ def test_vdo_pool_convert(self): succ = BlockDev.lvm_lvcreate("testVDOVG", "testLV", 7 * 1024**3) self.assertTrue(succ) - succ = BlockDev.lvm_vdo_pool_convert("testVDOVG", "testLV", "vdoLV", 35 * 1024**3) + succ = BlockDev.lvm_vdo_pool_convert("testVDOVG", "testLV", "vdoLV", 35 * 1024**3, + 0, True, False) self.assertTrue(succ) lv_info = BlockDev.lvm_lvinfo("testVDOVG", "vdoLV") @@ -2152,7 +2153,7 @@ def test_vdo_pool_convert(self): vdo_info = BlockDev.lvm_vdo_info("testVDOVG", "testLV") self.assertIsNotNone(vdo_info) self.assertTrue(vdo_info.compression) - self.assertTrue(vdo_info.deduplication) + self.assertFalse(vdo_info.deduplication) self.assertEqual(BlockDev.lvm_get_vdo_write_policy_str(vdo_info.write_policy), "auto") @tag_test(TestTags.SLOW)