summaryrefslogtreecommitdiffstats
path: root/libblkid
diff options
context:
space:
mode:
authorKarel Zak2012-12-04 12:12:54 +0100
committerKarel Zak2012-12-04 12:12:54 +0100
commite343695663e8c43601d25e10eccf68969288ad9b (patch)
tree62a185b585c9fd33efaac92fa5ae9078ca3a3ae5 /libblkid
parentlibblkid: cleanup nonnull attribute usage (diff)
downloadkernel-qcow2-util-linux-e343695663e8c43601d25e10eccf68969288ad9b.tar.gz
kernel-qcow2-util-linux-e343695663e8c43601d25e10eccf68969288ad9b.tar.xz
kernel-qcow2-util-linux-e343695663e8c43601d25e10eccf68969288ad9b.zip
libblkid: cleanup arguments checks
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libblkid')
-rw-r--r--libblkid/src/cache.c3
-rw-r--r--libblkid/src/dev.c10
-rw-r--r--libblkid/src/devname.c14
-rw-r--r--libblkid/src/encode.c4
-rw-r--r--libblkid/src/partitions/partitions.c8
-rw-r--r--libblkid/src/probe.c9
-rw-r--r--libblkid/src/resolve.c14
-rw-r--r--libblkid/src/superblocks/superblocks.c3
-rw-r--r--libblkid/src/tag.c20
-rw-r--r--libblkid/src/topology/topology.c10
-rw-r--r--libblkid/src/verify.c2
11 files changed, 51 insertions, 46 deletions
diff --git a/libblkid/src/cache.c b/libblkid/src/cache.c
index 2592d6fe7..cc2cf8e94 100644
--- a/libblkid/src/cache.c
+++ b/libblkid/src/cache.c
@@ -141,6 +141,9 @@ int blkid_get_cache(blkid_cache *ret_cache, const char *filename)
{
blkid_cache cache;
+ if (!ret_cache)
+ return -BLKID_ERR_PARAM;
+
blkid_init_debug(0);
DBG(DEBUG_CACHE, printf("creating blkid cache (using %s)\n",
diff --git a/libblkid/src/dev.c b/libblkid/src/dev.c
index 58ee6f864..62dfc24d3 100644
--- a/libblkid/src/dev.c
+++ b/libblkid/src/dev.c
@@ -69,7 +69,7 @@ void blkid_free_dev(blkid_dev dev)
*/
extern const char *blkid_dev_devname(blkid_dev dev)
{
- return dev->bid_name;
+ return dev ? dev->bid_name : NULL;
}
#ifdef CONFIG_BLKID_DEBUG
@@ -127,7 +127,7 @@ struct blkid_struct_dev_iterate {
extern blkid_dev_iterate blkid_dev_iterate_begin(blkid_cache cache)
{
- blkid_dev_iterate iter;
+ blkid_dev_iterate iter;
iter = malloc(sizeof(struct blkid_struct_dev_iterate));
if (iter) {
@@ -137,7 +137,7 @@ extern blkid_dev_iterate blkid_dev_iterate_begin(blkid_cache cache)
iter->search_type = 0;
iter->search_value = 0;
}
- return (iter);
+ return iter;
}
extern int blkid_dev_set_search(blkid_dev_iterate iter,
@@ -172,9 +172,9 @@ extern int blkid_dev_next(blkid_dev_iterate iter,
{
blkid_dev dev;
- *ret_dev = 0;
- if (!iter || iter->magic != DEV_ITERATE_MAGIC)
+ if (!ret_dev || !iter || iter->magic != DEV_ITERATE_MAGIC)
return -1;
+ *ret_dev = 0;
while (iter->p != &iter->cache->bic_devs) {
dev = list_entry(iter->p, struct blkid_struct_dev, bid_devs);
iter->p = iter->p->next;
diff --git a/libblkid/src/devname.c b/libblkid/src/devname.c
index 95f1d7ec9..b27b6612c 100644
--- a/libblkid/src/devname.c
+++ b/libblkid/src/devname.c
@@ -199,7 +199,7 @@ static void probe_one(blkid_cache cache, const char *ptname,
struct stat st;
char device[256];
- sprintf(device, "%s/%s", *dir, ptname);
+ snprintf(device, sizeof(device), "%s/%s", *dir, ptname);
if ((dev = blkid_get_dev(cache, device, BLKID_DEV_FIND)) &&
dev->bid_devno == devno)
goto set_pri;
@@ -595,9 +595,11 @@ int blkid_probe_all(blkid_cache cache)
DBG(DEBUG_PROBE, printf("Begin blkid_probe_all()\n"));
ret = probe_all(cache, 0);
- cache->bic_time = time(0);
- cache->bic_flags |= BLKID_BIC_FL_PROBED;
- DBG(DEBUG_PROBE, printf("End blkid_probe_all()\n"));
+ if (ret == 0) {
+ cache->bic_time = time(0);
+ cache->bic_flags |= BLKID_BIC_FL_PROBED;
+ }
+ DBG(DEBUG_PROBE, printf("End blkid_probe_all() [rc=%d]\n", ret));
return ret;
}
@@ -615,7 +617,7 @@ int blkid_probe_all_new(blkid_cache cache)
DBG(DEBUG_PROBE, printf("Begin blkid_probe_all_new()\n"));
ret = probe_all(cache, 1);
- DBG(DEBUG_PROBE, printf("End blkid_probe_all_new()\n"));
+ DBG(DEBUG_PROBE, printf("End blkid_probe_all_new() [rc=%d]\n", ret));
return ret;
}
@@ -643,7 +645,7 @@ int blkid_probe_all_removable(blkid_cache cache)
DBG(DEBUG_PROBE, printf("Begin blkid_probe_all_removable()\n"));
ret = probe_all_removable(cache);
- DBG(DEBUG_PROBE, printf("End blkid_probe_all_removable()\n"));
+ DBG(DEBUG_PROBE, printf("End blkid_probe_all_removable() [rc=%d]\n", ret));
return ret;
}
diff --git a/libblkid/src/encode.c b/libblkid/src/encode.c
index 9a0570e8f..ff57be4cb 100644
--- a/libblkid/src/encode.c
+++ b/libblkid/src/encode.c
@@ -284,7 +284,7 @@ int blkid_encode_string(const char *str, char *str_enc, size_t len)
{
size_t i, j;
- if (str == NULL || str_enc == NULL)
+ if (!str || !str_enc || !len)
return -1;
for (i = 0, j = 0; str[i] != '\0'; i++) {
@@ -332,6 +332,8 @@ err:
*/
int blkid_safe_string(const char *str, char *str_safe, size_t len)
{
+ if (!str || !str_safe || !len)
+ return -1;
replace_whitespace(str, str_safe, len);
replace_chars(str_safe, UDEV_ALLOWED_CHARS_INPUT);
return 0;
diff --git a/libblkid/src/partitions/partitions.c b/libblkid/src/partitions/partitions.c
index c9f7ff667..d51d40744 100644
--- a/libblkid/src/partitions/partitions.c
+++ b/libblkid/src/partitions/partitions.c
@@ -228,7 +228,6 @@ int blkid_probe_set_partitions_flags(blkid_probe pr, int flags)
{
if (!pr)
return -1;
-
pr->chains[BLKID_CHAIN_PARTS].flags = flags;
return 0;
}
@@ -921,6 +920,9 @@ blkid_partition blkid_partlist_devno_to_partition(blkid_partlist ls, dev_t devno
uint64_t start, size;
int i, rc, partno = 0;
+ if (!ls)
+ return NULL;
+
DBG(DEBUG_LOWPROBE,
printf("triyng to convert devno 0x%llx to partition\n",
(long long) devno));
@@ -1289,7 +1291,7 @@ blkid_loff_t blkid_partition_get_size(blkid_partition par)
*/
int blkid_partition_get_type(blkid_partition par)
{
- return par ? par->type : 0;
+ return par->type;
}
/* Sets partition 'type' for PT where the type is defined by string rather
@@ -1350,6 +1352,6 @@ int blkid_partition_set_flags(blkid_partition par, unsigned long long flags)
*/
unsigned long long blkid_partition_get_flags(blkid_partition par)
{
- return par ? par->flags : 0;
+ return par->flags;
}
diff --git a/libblkid/src/probe.c b/libblkid/src/probe.c
index c371656a4..eabcf9010 100644
--- a/libblkid/src/probe.c
+++ b/libblkid/src/probe.c
@@ -461,6 +461,9 @@ int __blkid_probe_invert_filter(blkid_probe pr, int chain)
size_t i;
struct blkid_chain *chn;
+ if (!pr)
+ return -1;
+
chn = &pr->chains[chain];
if (!chn->driver->has_fltr || !chn->fltr)
@@ -1397,7 +1400,7 @@ blkid_loff_t blkid_probe_get_offset(blkid_probe pr)
* blkid_probe_get_fd:
* @pr: probe
*
- * Returns: file descriptor for assigned device/file.
+ * Returns: file descriptor for assigned device/file or -1 in case of error.
*/
int blkid_probe_get_fd(blkid_probe pr)
{
@@ -1523,7 +1526,7 @@ int blkid_probe_has_value(blkid_probe pr, const char *name)
struct blkid_prval *__blkid_probe_get_value(blkid_probe pr, int num)
{
- if (pr == NULL || num < 0 || num >= pr->nvals)
+ if (!pr || num < 0 || num >= pr->nvals)
return NULL;
return &pr->vals[num];
@@ -1533,7 +1536,7 @@ struct blkid_prval *__blkid_probe_lookup_value(blkid_probe pr, const char *name)
{
int i;
- if (pr == NULL || pr->nvals == 0 || name == NULL)
+ if (!pr || !pr->nvals || !name)
return NULL;
for (i = 0; i < pr->nvals; i++) {
diff --git a/libblkid/src/resolve.c b/libblkid/src/resolve.c
index e5c4b5876..96749b3ec 100644
--- a/libblkid/src/resolve.c
+++ b/libblkid/src/resolve.c
@@ -36,11 +36,8 @@ char *blkid_get_tag_value(blkid_cache cache, const char *tagname,
if (!devname)
return NULL;
-
- if (!cache) {
- if (blkid_get_cache(&c, NULL) < 0)
- return NULL;
- }
+ if (!cache && blkid_get_cache(&c, NULL) < 0)
+ return NULL;
if ((dev = blkid_get_dev(c, devname, BLKID_DEV_NORMAL)) &&
(found = blkid_find_tag_dev(dev, tagname)))
@@ -68,11 +65,8 @@ char *blkid_get_devname(blkid_cache cache, const char *token,
if (!token)
return NULL;
-
- if (!cache) {
- if (blkid_get_cache(&c, NULL) < 0)
- return NULL;
- }
+ if (!cache && blkid_get_cache(&c, NULL) < 0)
+ return NULL;
DBG(DEBUG_RESOLVE,
printf("looking for %s%s%s %s\n", token, value ? "=" : "",
diff --git a/libblkid/src/superblocks/superblocks.c b/libblkid/src/superblocks/superblocks.c
index 879a40ff5..2929a5f2c 100644
--- a/libblkid/src/superblocks/superblocks.c
+++ b/libblkid/src/superblocks/superblocks.c
@@ -255,9 +255,6 @@ int blkid_probe_filter_superblocks_usage(blkid_probe pr, int flag, int usage)
struct blkid_chain *chn;
size_t i;
- if (!pr)
- return -1;
-
fltr = blkid_probe_get_filter(pr, BLKID_CHAIN_SUBLKS, TRUE);
if (!fltr)
return -1;
diff --git a/libblkid/src/tag.c b/libblkid/src/tag.c
index 8fe333634..9dbacef04 100644
--- a/libblkid/src/tag.c
+++ b/libblkid/src/tag.c
@@ -86,9 +86,6 @@ extern int blkid_dev_has_tag(blkid_dev dev, const char *type,
{
blkid_tag tag;
- if (!dev || !type)
- return -1;
-
tag = blkid_find_tag_dev(dev, type);
if (!value)
return (tag != NULL);
@@ -242,12 +239,15 @@ int blkid_parse_tag_string(const char *token, char **ret_type, char **ret_val)
goto errout; /* missing closing quote */
*cp = '\0';
}
- value = strdup(value);
+ if (value && *value)
+ value = strdup(value);
if (!value)
goto errout;
- *ret_type = name;
- *ret_val = value;
+ if (ret_type)
+ *ret_type = name;
+ if (ret_val)
+ *ret_val = value;
return 0;
@@ -300,11 +300,13 @@ extern int blkid_tag_next(blkid_tag_iterate iter,
{
blkid_tag tag;
- *type = 0;
- *value = 0;
- if (!iter || iter->magic != TAG_ITERATE_MAGIC ||
+ if (!type || !value ||
+ !iter || iter->magic != TAG_ITERATE_MAGIC ||
iter->p == &iter->dev->bid_tags)
return -1;
+
+ *type = 0;
+ *value = 0;
tag = list_entry(iter->p, struct blkid_struct_tag, bit_tags);
*type = tag->bit_name;
*value = tag->bit_val;
diff --git a/libblkid/src/topology/topology.c b/libblkid/src/topology/topology.c
index 73a397afd..9d4e7bdf1 100644
--- a/libblkid/src/topology/topology.c
+++ b/libblkid/src/topology/topology.c
@@ -317,7 +317,7 @@ int blkid_topology_set_physical_sector_size(blkid_probe pr, unsigned long val)
*/
unsigned long blkid_topology_get_alignment_offset(blkid_topology tp)
{
- return tp ? tp->alignment_offset : 0;
+ return tp->alignment_offset;
}
/**
@@ -328,7 +328,7 @@ unsigned long blkid_topology_get_alignment_offset(blkid_topology tp)
*/
unsigned long blkid_topology_get_minimum_io_size(blkid_topology tp)
{
- return tp ? tp->minimum_io_size : 0;
+ return tp->minimum_io_size;
}
/**
@@ -339,7 +339,7 @@ unsigned long blkid_topology_get_minimum_io_size(blkid_topology tp)
*/
unsigned long blkid_topology_get_optimal_io_size(blkid_topology tp)
{
- return tp ? tp->optimal_io_size : 0;
+ return tp->optimal_io_size;
}
/**
@@ -350,7 +350,7 @@ unsigned long blkid_topology_get_optimal_io_size(blkid_topology tp)
*/
unsigned long blkid_topology_get_logical_sector_size(blkid_topology tp)
{
- return tp ? tp->logical_sector_size : 0;
+ return tp->logical_sector_size;
}
/**
@@ -361,6 +361,6 @@ unsigned long blkid_topology_get_logical_sector_size(blkid_topology tp)
*/
unsigned long blkid_topology_get_physical_sector_size(blkid_topology tp)
{
- return tp ? tp->physical_sector_size : 0;
+ return tp->physical_sector_size;
}
diff --git a/libblkid/src/verify.c b/libblkid/src/verify.c
index 207152cd8..da78d6b08 100644
--- a/libblkid/src/verify.c
+++ b/libblkid/src/verify.c
@@ -81,7 +81,7 @@ blkid_dev blkid_verify(blkid_cache cache, blkid_dev dev)
char *fltr[2];
int fd;
- if (!dev)
+ if (!dev || !cache)
return NULL;
now = time(0);