Discussion:
[PATCH 03/13] Check value_to_disk for NULL
Tony Asleson
2015-04-24 22:40:33 UTC
Permalink
Signed-off-by: Tony Asleson <***@redhat.com>
---
c_binding/lsm_convert.cpp | 20 +++++++++++++++-----
1 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/c_binding/lsm_convert.cpp b/c_binding/lsm_convert.cpp
index 8cde280..9d64e78 100644
--- a/c_binding/lsm_convert.cpp
+++ b/c_binding/lsm_convert.cpp
@@ -173,6 +173,10 @@ int value_array_to_disks(Value &disk_values, lsm_disk **disks[], uint32_t *count
if( *disks ){
for( size_t i = 0; i < d.size(); ++i ) {
(*disks)[i] = value_to_disk(d[i]);
+ if( !((*disks)[i]) ) {
+ rc = LSM_ERR_NO_MEMORY;
+ goto error;
+ }
}
} else {
rc = LSM_ERR_NO_MEMORY;
@@ -181,13 +185,19 @@ int value_array_to_disks(Value &disk_values, lsm_disk **disks[], uint32_t *count
}
} catch( const ValueException &ve ) {
rc = LSM_ERR_LIB_BUG;
- if( *disks && *count ) {
- lsm_disk_record_array_free(*disks, *count);
- *disks = NULL;
- *count = 0;
- }
+ goto error;
}
+
+out:
return rc;
+
+error:
+ if( *disks && *count ) {
+ lsm_disk_record_array_free(*disks, *count);
+ *disks = NULL;
+ *count = 0;
+ }
+ goto out;
}

lsm_pool *value_to_pool(Value &pool)
--
1.7.1
Tony Asleson
2015-04-24 22:40:32 UTC
Permalink
Not always consistent checking the return for NULL.

Signed-off-by: Tony Asleson <***@redhat.com>
---
c_binding/lsm_convert.cpp | 21 +++++++++++----
c_binding/lsm_mgmt.cpp | 54 ++++++++++++++++++++++++++++++++---------
c_binding/lsm_plugin_ipc.cpp | 3 +-
3 files changed, 59 insertions(+), 19 deletions(-)

diff --git a/c_binding/lsm_convert.cpp b/c_binding/lsm_convert.cpp
index d7c31fa..8cde280 100644
--- a/c_binding/lsm_convert.cpp
+++ b/c_binding/lsm_convert.cpp
@@ -92,6 +92,10 @@ int value_array_to_volumes(Value &volume_values, lsm_volume **volumes[],
if( *volumes ){
for( size_t i = 0; i < vol.size(); ++i ) {
(*volumes)[i] = value_to_volume(vol[i]);
+ if( !((*volumes)[i]) ) {
+ rc = LSM_ERR_NO_MEMORY;
+ goto error;
+ }
}
} else {
rc = LSM_ERR_NO_MEMORY;
@@ -99,15 +103,20 @@ int value_array_to_volumes(Value &volume_values, lsm_volume **volumes[],
}
}
} catch( const ValueException &ve) {
- if( *volumes && *count ) {
- lsm_volume_record_array_free(*volumes, *count);
- *volumes = NULL;
- *count = 0;
- }
-
rc = LSM_ERR_LIB_BUG;
+ goto error;
}
+
+out:
return rc;
+
+error:
+ if( *volumes && *count ) {
+ lsm_volume_record_array_free(*volumes, *count);
+ *volumes = NULL;
+ *count = 0;
+ }
+ goto out;
}

lsm_disk *value_to_disk(Value &disk)
diff --git a/c_binding/lsm_mgmt.cpp b/c_binding/lsm_mgmt.cpp
index cbe57fe..5075f74 100644
--- a/c_binding/lsm_mgmt.cpp
+++ b/c_binding/lsm_mgmt.cpp
@@ -627,6 +627,9 @@ int lsm_job_status_volume_get( lsm_connect *c, const char *job,
if( LSM_ERR_OK == rc ) {
if( Value::object_t == rv.valueType() ) {
*vol = value_to_volume(rv);
+ if( !(*vol) ) {
+ rc = LSM_ERR_NO_MEMORY;
+ }
} else {
*vol = NULL;
}
@@ -1001,6 +1004,7 @@ static void* parse_job_response(lsm_connect *c, Value response, int &rc,
char **job, convert conv)
{
void *val = NULL;
+ *job = NULL;

try {
//We get an array back. first value is job, second is data of interest.
@@ -1008,25 +1012,34 @@ static void* parse_job_response(lsm_connect *c, Value response, int &rc,
std::vector<Value> r = response.asArray();
if( Value::string_t == r[0].valueType()) {
*job = strdup((r[0].asString()).c_str());
- if( *job ) {
- rc = LSM_ERR_JOB_STARTED;
- } else {
+ if( !(*job) ) {
rc = LSM_ERR_NO_MEMORY;
+ goto error;
}

rc = LSM_ERR_JOB_STARTED;
}
if( Value::object_t == r[1].valueType() ) {
val = conv(r[1]);
+ if( !val ) {
+ rc = LSM_ERR_NO_MEMORY;
+ goto error;
+ }
}
}
} catch( const ValueException &ve ) {
rc = logException(c, LSM_ERR_LIB_BUG, "Unexpected type",
ve.what());
- free(*job);
- *job = NULL;
+ goto error;
}
+
+out:
return val;
+
+error:
+ free(*job);
+ *job = NULL;
+ goto out;
}

int lsm_volume_create(lsm_connect *c, lsm_pool *pool, const char *volumeName,
@@ -1560,21 +1573,35 @@ int lsm_volumes_accessible_by_access_group(lsm_connect *c,
if( vol.size() ) {
*volumes = lsm_volume_record_array_alloc(vol.size());

- for( size_t i = 0; i < vol.size(); ++i ) {
- (*volumes)[i] = value_to_volume(vol[i]);
+ if( *volumes ) {
+ for( size_t i = 0; i < vol.size(); ++i ) {
+ (*volumes)[i] = value_to_volume(vol[i]);
+ if( !((*volumes)[i]) ) {
+ rc = LSM_ERR_NO_MEMORY;
+ goto error;
+ }
+ }
+ } else {
+ rc = LSM_ERR_NO_MEMORY;
}
}
}
} catch( const ValueException &ve ) {
rc = logException(c, LSM_ERR_LIB_BUG, "Unexpected type",
ve.what());
- if( *volumes && *count ) {
- lsm_volume_record_array_free(*volumes, *count);
- *volumes = NULL;
- *count = 0;
- }
+ goto error;
+
}
+
+out:
return rc;
+
+error:
+ if( *volumes && *count ) {
+ lsm_volume_record_array_free(*volumes, *count);
+ *volumes = NULL;
+ *count = 0;
+ }
}

int lsm_access_groups_granted_to_volume(lsm_connect *c,
@@ -2393,6 +2420,9 @@ int lsm_volume_raid_create(
int rc = rpc(c, "volume_raid_create", parameters, response);
if( LSM_ERR_OK == rc ) {
*new_volume = value_to_volume(response);
+ if( ! (*new_volume) ) {
+ rc = LSM_ERR_NO_MEMORY;
+ }
}
return rc;

diff --git a/c_binding/lsm_plugin_ipc.cpp b/c_binding/lsm_plugin_ipc.cpp
index d1b2b41..667b95f 100644
--- a/c_binding/lsm_plugin_ipc.cpp
+++ b/c_binding/lsm_plugin_ipc.cpp
@@ -791,7 +791,8 @@ static int handle_volume_replicate(lsm_plugin_ptr p, Value &params, Value &respo
const char *name = v_name.asC_str();
char *job = NULL;

- if( vol ) {
+ if( vol && (pool ||
+ (!pool && Value::null_t == v_pool.valueType())) ) {
rc = p->san_ops->vol_replicate(p, pool, rep, vol, name,
&newVolume, &job,
LSM_FLAG_GET_VALUE(params));
--
1.7.1
Gris Ge
2015-04-27 09:27:59 UTC
Permalink
Post by Tony Asleson
Not always consistent checking the return for NULL.
---
c_binding/lsm_convert.cpp | 21 +++++++++++----
c_binding/lsm_mgmt.cpp | 54 ++++++++++++++++++++++++++++++++---------
c_binding/lsm_plugin_ipc.cpp | 3 +-
3 files changed, 59 insertions(+), 19 deletions(-)
diff --git a/c_binding/lsm_convert.cpp b/c_binding/lsm_convert.cpp
index d7c31fa..8cde280 100644
--- a/c_binding/lsm_convert.cpp
+++ b/c_binding/lsm_convert.cpp
@@ -92,6 +92,10 @@ int value_array_to_volumes(Value &volume_values, lsm_volume **volumes[],
if( *volumes ){
for( size_t i = 0; i < vol.size(); ++i ) {
(*volumes)[i] = value_to_volume(vol[i]);
+ if( !((*volumes)[i]) ) {
+ rc = LSM_ERR_NO_MEMORY;
+ goto error;
+ }
We will get NULL return from value_to_volume() when plugin return
non-volume data, which is not LSM_ERR_NO_MEMORY error but
LSM_ERR_PLUGIN_BUG.

We might move 'is_expected_object(vol, CLASS_NAME_VOLUME)' to here
from value_to_volume().

Besides this concern, the patch set looks good to me.

Thank you.
Post by Tony Asleson
}
} else {
rc = LSM_ERR_NO_MEMORY;
--
Gris Ge
Tony Asleson
2015-04-27 14:18:18 UTC
Permalink
Post by Gris Ge
Post by Tony Asleson
(*volumes)[i] = value_to_volume(vol[i]);
+ if( !((*volumes)[i]) ) {
+ rc = LSM_ERR_NO_MEMORY;
+ goto error;
+ }
We will get NULL return from value_to_volume() when plugin return
non-volume data, which is not LSM_ERR_NO_MEMORY error but
LSM_ERR_PLUGIN_BUG.
We might move 'is_expected_object(vol, CLASS_NAME_VOLUME)' to here
from value_to_volume().
Besides this concern, the patch set looks good to me.
True, the function value_to_volume can return NULL for incorrect object
type or because a memory allocation failure. However, the former should
be verified during testing whereas the later will likely only occur
during use.

I'm going to re-work the internal conversion functions to remove this
ambiguity.

Thanks!

Regards,
Tony
Tony Asleson
2015-04-28 20:07:25 UTC
Permalink
Post by Tony Asleson
Post by Gris Ge
Post by Tony Asleson
(*volumes)[i] = value_to_volume(vol[i]);
+ if( !((*volumes)[i]) ) {
+ rc = LSM_ERR_NO_MEMORY;
+ goto error;
+ }
We will get NULL return from value_to_volume() when plugin return
non-volume data, which is not LSM_ERR_NO_MEMORY error but
LSM_ERR_PLUGIN_BUG.
We might move 'is_expected_object(vol, CLASS_NAME_VOLUME)' to here
from value_to_volume().
Besides this concern, the patch set looks good to me.
True, the function value_to_volume can return NULL for incorrect object
type or because a memory allocation failure. However, the former should
be verified during testing whereas the later will likely only occur
during use.
I'm going to re-work the internal conversion functions to remove this
ambiguity.
Hi Gris,

Updated pull request with a few more commits that address this
ambiguity, please review.

I tried a couple of different approaches, but ended up with this as the
cleanest.

Thanks,
Tony

Tony Asleson
2015-04-24 22:40:34 UTC
Permalink
Signed-off-by: Tony Asleson <***@redhat.com>
---
c_binding/lsm_mgmt.cpp | 26 +++++++++++++++++++++-----
1 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/c_binding/lsm_mgmt.cpp b/c_binding/lsm_mgmt.cpp
index 5075f74..e593d55 100644
--- a/c_binding/lsm_mgmt.cpp
+++ b/c_binding/lsm_mgmt.cpp
@@ -596,6 +596,9 @@ int lsm_job_status_pool_get(lsm_connect *c,
if( LSM_ERR_OK == rc ) {
if( Value::object_t == rv.valueType() ) {
*pool = value_to_pool(rv);
+ if( !(*pool) ) {
+ rc = LSM_ERR_NO_MEMORY;
+ }
} else {
*pool = NULL;
}
@@ -766,6 +769,9 @@ int lsm_pool_list(lsm_connect *c, char *search_key, char *search_value,
return LSM_ERR_INVALID_ARGUMENT;
}

+ *count = 0;
+ *poolArray = NULL;
+
try {
std::map<std::string, Value> p;

@@ -790,19 +796,29 @@ int lsm_pool_list(lsm_connect *c, char *search_key, char *search_value,

for( size_t i = 0; i < pools.size(); ++i ) {
(*poolArray)[i] = value_to_pool(pools[i]);
+ if( !(*poolArray)[i] ) {
+ rc = LSM_ERR_NO_MEMORY;
+ goto error;
+ }
}
}
}
} catch( const ValueException &ve ) {
rc = logException(c, LSM_ERR_LIB_BUG, "Unexpected type",
ve.what());
- if( *poolArray && *count ) {
- lsm_pool_record_array_free(*poolArray, *count);
- *poolArray = NULL;
- *count = 0;
- }
+ goto error;
}
+
+out:
return rc;
+
+error:
+ if( *poolArray && *count ) {
+ lsm_pool_record_array_free(*poolArray, *count);
+ *poolArray = NULL;
+ *count = 0;
+ }
+ goto out;
}

int lsm_pool_member_info(lsm_connect *c, lsm_pool *pool,
--
1.7.1
Tony Asleson
2015-04-24 22:40:31 UTC
Permalink
Signed-off-by: Tony Asleson <***@redhat.com>
---
c_binding/lsm_plugin_ipc.cpp | 11 ++++++++---
1 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/c_binding/lsm_plugin_ipc.cpp b/c_binding/lsm_plugin_ipc.cpp
index 161e797..d1b2b41 100644
--- a/c_binding/lsm_plugin_ipc.cpp
+++ b/c_binding/lsm_plugin_ipc.cpp
@@ -1772,7 +1772,8 @@ static int fs_child_dependency(lsm_plugin_ptr p, Value &params, Value &response)
lsm_fs *fs = value_to_fs(v_fs);
lsm_string_list *files = value_to_string_list(v_files);

- if( fs ) {
+ if( fs && ( files ||
+ (!files && Value::null_t == v_files.valueType()) )) {
uint8_t yes = 0;

rc = p->fs_ops->fs_child_dependency(p, fs, files, &yes);
@@ -1810,7 +1811,8 @@ static int fs_child_dependency_rm(lsm_plugin_ptr p, Value &params, Value &respon
lsm_fs *fs = value_to_fs(v_fs);
lsm_string_list *files = value_to_string_list(v_files);

- if( fs ) {
+ if( fs &&
+ (files || (!files && Value::null_t == v_files.valueType())) ) {
char *job = NULL;

rc = p->fs_ops->fs_child_dependency_rm(p, fs, files, &job,
@@ -1988,7 +1990,10 @@ static int ss_restore(lsm_plugin_ptr p, Value &params, Value &response)
value_to_string_list(v_restore_files);
int all_files = (v_all_files.asBool()) ? 1 : 0;

- if( fs && ss ) {
+ if( fs && ss &&
+ (files || (!files && Value::null_t == v_files.valueType())) &&
+ (restore_files || (!restore_files &&
+ Value::null_t == v_restore_files.valueType())) ) {
rc = p->fs_ops->fs_ss_restore(p, fs, ss, files, restore_files,
all_files, &job,
LSM_FLAG_GET_VALUE(params));
--
1.7.1
Tony Asleson
2015-04-24 22:40:40 UTC
Permalink
Signed-off-by: Tony Asleson <***@redhat.com>
---
c_binding/lsm_mgmt.cpp | 21 ++++++++++++++++++---
1 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/c_binding/lsm_mgmt.cpp b/c_binding/lsm_mgmt.cpp
index 3194e50..18c4e36 100644
--- a/c_binding/lsm_mgmt.cpp
+++ b/c_binding/lsm_mgmt.cpp
@@ -2225,6 +2225,9 @@ int lsm_nfs_list( lsm_connect *c, const char *search_key,
return LSM_ERR_INVALID_ARGUMENT;
}

+ *count = 0;
+ *exports = NULL;
+
try {
std::map<std::string, Value> p;

@@ -2251,6 +2254,10 @@ int lsm_nfs_list( lsm_connect *c, const char *search_key,
if( *exports ) {
for( size_t i = 0; i < *count; ++i ) {
(*exports)[i] = value_to_nfs_export(exps[i]);
+ if( !((*exports)[i]) ) {
+ rc = LSM_ERR_NO_MEMORY;
+ goto error;
+ }
}
} else {
rc = LSM_ERR_NO_MEMORY;
@@ -2260,13 +2267,18 @@ int lsm_nfs_list( lsm_connect *c, const char *search_key,
} catch( const ValueException &ve ) {
rc = logException(c, LSM_ERR_LIB_BUG, "Unexpected type",
ve.what());
- if( *exports && *count ) {
+ goto error;
+ }
+out:
+ return rc;
+
+error:
+ if( *exports && *count ) {
lsm_nfs_export_record_array_free( *exports, *count );
*exports = NULL;
*count = 0;
- }
}
- return rc;
+ goto out;
}

int lsm_nfs_export_fs( lsm_connect *c,
@@ -2327,6 +2339,9 @@ int lsm_nfs_export_fs( lsm_connect *c,
int rc = rpc(c, "export_fs", parameters, response);
if( LSM_ERR_OK == rc && Value::object_t == response.valueType()) {
*exported = value_to_nfs_export(response);
+ if( !(*exported) ) {
+ rc = LSM_ERR_NO_MEMORY;
+ }
}
return rc;
}
--
1.7.1
Tony Asleson
2015-04-24 22:40:38 UTC
Permalink
---
c_binding/lsm_mgmt.cpp | 22 +++++++++++++++++-----
1 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/c_binding/lsm_mgmt.cpp b/c_binding/lsm_mgmt.cpp
index c81f1a3..23326d5 100644
--- a/c_binding/lsm_mgmt.cpp
+++ b/c_binding/lsm_mgmt.cpp
@@ -665,6 +665,9 @@ int lsm_job_status_fs_get(lsm_connect *c, const char *job,
if( LSM_ERR_OK == rc ) {
if( Value::object_t == rv.valueType() ) {
*fs = value_to_fs(rv);
+ if( !(*fs) ) {
+ rc = LSM_ERR_NO_MEMORY;
+ }
} else {
*fs = NULL;
}
@@ -1810,6 +1813,10 @@ int lsm_fs_list(lsm_connect *c, const char *search_key,
if( *fs ) {
for( size_t i = 0; i < sys.size(); ++i ) {
(*fs)[i] = value_to_fs(sys[i]);
+ if( !((*fs)[i]) ) {
+ rc = LSM_ERR_NO_MEMORY;
+ goto error;
+ }
}
} else {
rc = LSM_ERR_NO_MEMORY;
@@ -1819,14 +1826,19 @@ int lsm_fs_list(lsm_connect *c, const char *search_key,
} catch( const ValueException &ve ) {
rc = logException(c, LSM_ERR_LIB_BUG, "Unexpected type",
ve.what());
- if( *fs && *fsCount) {
- lsm_fs_record_array_free(*fs, *fsCount);
- *fs = NULL;
- *fsCount = 0;
- }
+ goto error;
+
}
+out:
return rc;

+error:
+ if( *fs && *fsCount) {
+ lsm_fs_record_array_free(*fs, *fsCount);
+ *fs = NULL;
+ *fsCount = 0;
+ }
+ goto out;
}

int lsm_fs_create(lsm_connect *c, lsm_pool *pool, const char *name,
--
1.7.1
Tony Asleson
2015-04-24 22:40:36 UTC
Permalink
Signed-off-by: Tony Asleson <***@redhat.com>
---
c_binding/lsm_mgmt.cpp | 6 ++++++
1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/c_binding/lsm_mgmt.cpp b/c_binding/lsm_mgmt.cpp
index ef96443..74fc6a9 100644
--- a/c_binding/lsm_mgmt.cpp
+++ b/c_binding/lsm_mgmt.cpp
@@ -1426,6 +1426,9 @@ int lsm_access_group_create(lsm_connect *c, const char *name,
//We should be getting a value back.
if( Value::object_t == response.valueType() ) {
*access_group = value_to_access_group(response);
+ if( !(*access_group) ) {
+ rc = LSM_ERR_NO_MEMORY;
+ }
}
}
return rc;
@@ -1484,6 +1487,9 @@ static int _lsm_ag_add_delete(lsm_connect *c,
//We should be getting a value back.
if( Value::object_t == response.valueType() ) {
*updated_access_group = value_to_access_group(response);
+ if( !(*updated_access_group) ) {
+ rc = LSM_ERR_NO_MEMORY;
+ }
}
}
--
1.7.1
Tony Asleson
2015-04-24 22:40:37 UTC
Permalink
Signed-off-by: Tony Asleson <***@redhat.com>
---
c_binding/lsm_mgmt.cpp | 3 +++
1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/c_binding/lsm_mgmt.cpp b/c_binding/lsm_mgmt.cpp
index 74fc6a9..c81f1a3 100644
--- a/c_binding/lsm_mgmt.cpp
+++ b/c_binding/lsm_mgmt.cpp
@@ -284,6 +284,9 @@ static int getAccessGroups( lsm_connect *c, int rc, Value &response,
try {
if( LSM_ERR_OK == rc && Value::array_t == response.valueType()) {
*groups = value_to_access_group_list(response, count);
+ if( *count && !(*groups) ) {
+ rc = LSM_ERR_NO_MEMORY;
+ }
}
} catch( const ValueException &ve ) {
rc = logException(c, LSM_ERR_LIB_BUG, "Unexpected type",
--
1.7.1
Tony Asleson
2015-04-24 22:40:35 UTC
Permalink
Signed-off-by: Tony Asleson <***@redhat.com>
---
c_binding/lsm_mgmt.cpp | 19 ++++++++++++-------
c_binding/lsm_plugin_ipc.cpp | 39 ++++++++++++++++++++++-----------------
2 files changed, 34 insertions(+), 24 deletions(-)

diff --git a/c_binding/lsm_mgmt.cpp b/c_binding/lsm_mgmt.cpp
index e593d55..ef96443 100644
--- a/c_binding/lsm_mgmt.cpp
+++ b/c_binding/lsm_mgmt.cpp
@@ -1738,9 +1738,8 @@ int lsm_system_list(lsm_connect *c, lsm_system **systems[],
for( size_t i = 0; i < sys.size(); ++i ) {
(*systems)[i] = value_to_system(sys[i]);
if( !(*systems)[i] ) {
- lsm_system_record_array_free(*systems, i);
rc = LSM_ERR_NO_MEMORY;
- break;
+ goto error;
}
}
} else {
@@ -1751,13 +1750,19 @@ int lsm_system_list(lsm_connect *c, lsm_system **systems[],
} catch( const ValueException &ve ) {
rc = logException(c, LSM_ERR_LIB_BUG, "Unexpected type",
ve.what());
- if( *systems ) {
- lsm_system_record_array_free( *systems, *systemCount);
- *systems = NULL;
- *systemCount = 0;
- }
+ goto error;
+
}
+out:
return rc;
+
+error:
+ if( *systems ) {
+ lsm_system_record_array_free( *systems, *systemCount);
+ *systems = NULL;
+ *systemCount = 0;
+ }
+ goto out;
}

int lsm_fs_list(lsm_connect *c, const char *search_key,
diff --git a/c_binding/lsm_plugin_ipc.cpp b/c_binding/lsm_plugin_ipc.cpp
index 667b95f..6719b85 100644
--- a/c_binding/lsm_plugin_ipc.cpp
+++ b/c_binding/lsm_plugin_ipc.cpp
@@ -2228,7 +2228,6 @@ static int handle_volume_raid_create_cap_get(

if( IS_CLASS_SYSTEM(v_system) &&
LSM_FLAG_EXPECTED_TYPE(params) ) {
- lsm_system *sys = value_to_system(v_system);

uint32_t *supported_raid_types = NULL;
uint32_t supported_raid_type_count = 0;
@@ -2236,22 +2235,29 @@ static int handle_volume_raid_create_cap_get(
uint32_t *supported_strip_sizes = NULL;
uint32_t supported_strip_size_count = 0;

- rc = p->ops_v1_2->vol_create_raid_cap_get(
- p, sys, &supported_raid_types, &supported_raid_type_count,
- &supported_strip_sizes, &supported_strip_size_count,
- LSM_FLAG_GET_VALUE(params));
+ lsm_system *sys = value_to_system(v_system);

- if( LSM_ERR_OK == rc ) {
- std::vector<Value> result;
- result.push_back(
- uint32_array_to_value(
- supported_raid_types, supported_raid_type_count));
- result.push_back(
- uint32_array_to_value(
- supported_strip_sizes, supported_strip_size_count));
- response = Value(result);
- free(supported_raid_types);
- free(supported_strip_sizes);
+ if( sys ) {
+
+ rc = p->ops_v1_2->vol_create_raid_cap_get(
+ p, sys, &supported_raid_types, &supported_raid_type_count,
+ &supported_strip_sizes, &supported_strip_size_count,
+ LSM_FLAG_GET_VALUE(params));
+
+ if( LSM_ERR_OK == rc ) {
+ std::vector<Value> result;
+ result.push_back(
+ uint32_array_to_value(
+ supported_raid_types, supported_raid_type_count));
+ result.push_back(
+ uint32_array_to_value(
+ supported_strip_sizes, supported_strip_size_count));
+ response = Value(result);
+ free(supported_raid_types);
+ free(supported_strip_sizes);
+ }
+ } else {
+ rc = LSM_ERR_NO_MEMORY;
}

lsm_system_record_free(sys);
@@ -2261,7 +2267,6 @@ static int handle_volume_raid_create_cap_get(
}
}
return rc;
-
}

static int handle_volume_raid_create(
--
1.7.1
Tony Asleson
2015-04-24 22:40:39 UTC
Permalink
Signed-off-by: Tony Asleson <***@redhat.com>
---
c_binding/lsm_mgmt.cpp | 22 +++++++++++++++++-----
1 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/c_binding/lsm_mgmt.cpp b/c_binding/lsm_mgmt.cpp
index 23326d5..3194e50 100644
--- a/c_binding/lsm_mgmt.cpp
+++ b/c_binding/lsm_mgmt.cpp
@@ -697,6 +697,9 @@ int lsm_job_status_ss_get(lsm_connect *c, const char *job,
if( LSM_ERR_OK == rc ) {
if( Value::object_t == rv.valueType() ) {
*ss = value_to_ss(rv);
+ if( !(*ss) ) {
+ rc = LSM_ERR_NO_MEMORY;
+ }
} else {
*ss = NULL;
}
@@ -2078,6 +2081,10 @@ int lsm_fs_ss_list(lsm_connect *c, lsm_fs *fs, lsm_fs_ss **ss[],
if( *ss ) {
for( size_t i = 0; i < sys.size(); ++i ) {
(*ss)[i] = value_to_ss(sys[i]);
+ if( !((*ss)[i]) ) {
+ rc = LSM_ERR_NO_MEMORY;
+ goto error;
+ }
}
} else {
rc = LSM_ERR_NO_MEMORY;
@@ -2087,14 +2094,19 @@ int lsm_fs_ss_list(lsm_connect *c, lsm_fs *fs, lsm_fs_ss **ss[],
} catch( const ValueException &ve ) {
rc = logException(c, LSM_ERR_LIB_BUG, "Unexpected type",
ve.what());
- if( *ss && *ssCount ) {
- lsm_fs_ss_record_array_free(*ss, *ssCount);
- *ss = NULL;
- *ssCount = 0;
- }
+ goto error;
}
+out:
return rc;

+error:
+ if( *ss && *ssCount ) {
+ lsm_fs_ss_record_array_free(*ss, *ssCount);
+ *ss = NULL;
+ *ssCount = 0;
+ }
+
+ goto out;
}

int lsm_fs_ss_create(lsm_connect *c, lsm_fs *fs, const char *name, lsm_fs_ss **snapshot, char **job,
--
1.7.1
Tony Asleson
2015-04-24 22:40:43 UTC
Permalink
Signed-off-by: Tony Asleson <***@redhat.com>
---
c_binding/lsm_mgmt.cpp | 24 ++++++++++++++----------
1 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/c_binding/lsm_mgmt.cpp b/c_binding/lsm_mgmt.cpp
index ad74827..09b05dc 100644
--- a/c_binding/lsm_mgmt.cpp
+++ b/c_binding/lsm_mgmt.cpp
@@ -2390,6 +2390,8 @@ int lsm_volume_raid_create_cap_get(
return LSM_ERR_INVALID_ARGUMENT;
}

+ *supported_raid_types = NULL;
+
std::map<std::string, Value> p;
p["system"] = system_to_value(system);
p["flags"] = Value(flags);
@@ -2405,27 +2407,29 @@ int lsm_volume_raid_create_cap_get(
j[0], supported_raid_types, supported_raid_type_count);

if( rc != LSM_ERR_OK ){
- *supported_raid_types = NULL;
- *supported_raid_type_count = 0;
- *supported_strip_sizes = NULL;
- *supported_strip_size_count = 0;
- return rc;
+ goto error;
}

rc = values_to_uint32_array(
j[1], supported_strip_sizes, supported_strip_size_count);
if( rc != LSM_ERR_OK ){
- free(*supported_raid_types);
- *supported_raid_types = NULL;
- *supported_raid_type_count = 0;
- *supported_strip_sizes = NULL;
- *supported_strip_size_count = 0;
+ goto error;
}
} catch( const ValueException &ve ) {
rc = logException(c, LSM_ERR_LIB_BUG, "Unexpected type",
ve.what());
}
+
+out:
return rc;
+
+error:
+ free(*supported_raid_types);
+ *supported_raid_types = NULL;
+ *supported_raid_type_count = 0;
+ *supported_strip_sizes = NULL;
+ *supported_strip_size_count = 0;
+ goto out;
}

int lsm_volume_raid_create(
--
1.7.1
Tony Asleson
2015-04-24 22:40:41 UTC
Permalink
Signed-off-by: Tony Asleson <***@redhat.com>
---
c_binding/lsm_mgmt.cpp | 3 +++
1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/c_binding/lsm_mgmt.cpp b/c_binding/lsm_mgmt.cpp
index 18c4e36..d0f532c 100644
--- a/c_binding/lsm_mgmt.cpp
+++ b/c_binding/lsm_mgmt.cpp
@@ -759,6 +759,9 @@ int lsm_capabilities(lsm_connect *c, lsm_system *system,

if( LSM_ERR_OK == rc && Value::object_t == response.valueType() ) {
*cap = value_to_capabilities(response);
+ if( !(*cap) ) {
+ rc = LSM_ERR_NO_MEMORY;
+ }
}
} catch( const ValueException &ve ) {
rc = logException(c, LSM_ERR_LIB_BUG, "Unexpected type",
--
1.7.1
Tony Asleson
2015-04-24 22:40:42 UTC
Permalink
Signed-off-by: Tony Asleson <***@redhat.com>
---
c_binding/lsm_mgmt.cpp | 19 ++++++++++++++-----
1 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/c_binding/lsm_mgmt.cpp b/c_binding/lsm_mgmt.cpp
index d0f532c..ad74827 100644
--- a/c_binding/lsm_mgmt.cpp
+++ b/c_binding/lsm_mgmt.cpp
@@ -931,19 +931,28 @@ int lsm_target_port_list(lsm_connect *c, const char *search_key,

for( size_t i = 0; i < tp.size(); ++i ) {
(*target_ports)[i] = value_to_target_port(tp[i]);
+ if( !((*target_ports)[i]) ) {
+ rc = LSM_ERR_NO_MEMORY;
+ goto error;
+ }
}
}
}
} catch( const ValueException &ve ) {
rc = logException(c, LSM_ERR_LIB_BUG, "Unexpected type",
ve.what());
- if( *target_ports && *count ) {
- lsm_target_port_record_array_free(*target_ports, *count);
- *target_ports = NULL;
- *count = 0;
- }
+ goto error;
}
+out:
return rc;
+
+error:
+ if( *target_ports && *count ) {
+ lsm_target_port_record_array_free(*target_ports, *count);
+ *target_ports = NULL;
+ *count = 0;
+ }
+ goto out;
}

static int get_volume_array(lsm_connect *c, int rc, Value &response,
--
1.7.1
Loading...