Discussion:
[PATCH 02/16] Check value_to_volume return for NULL
Tony Asleson
2015-04-29 15:12:46 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
Tony Asleson
2015-04-29 15:12:45 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-29 15:12:47 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-29 15:12:48 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-29 15:12:51 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-29 15:12:53 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-29 15:12:50 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-29 15:12:52 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-29 15:12:56 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
Tony Asleson
2015-04-29 15:12:54 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-29 15:12:55 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-29 15:12:57 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-29 15:12:49 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-29 15:13:00 UTC
Permalink
Incorrectly validating arguments.

Signed-off-by: Tony Asleson <***@redhat.com>
---
c_binding/lsm_plugin_ipc.cpp | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/c_binding/lsm_plugin_ipc.cpp b/c_binding/lsm_plugin_ipc.cpp
index 14bffca..5b2e523 100644
--- a/c_binding/lsm_plugin_ipc.cpp
+++ b/c_binding/lsm_plugin_ipc.cpp
@@ -1720,7 +1720,8 @@ static int fs_file_clone(lsm_plugin_ptr p, Value &params, Value &response)

if( IS_CLASS_FILE_SYSTEM(v_fs) &&
Value::string_t == v_src_name.valueType() &&
- (Value::string_t == v_dest_name.valueType() ||
+ Value::string_t == v_dest_name.valueType() &&
+ (Value::null_t == v_ss.valueType() ||
Value::object_t == v_ss.valueType()) &&
LSM_FLAG_EXPECTED_TYPE(params)) {
--
1.7.1
Tony Asleson
2015-04-29 15:12:59 UTC
Permalink
Signed-off-by: Tony Asleson <***@redhat.com>
---
c_binding/lsm_convert.hpp | 2 ++
c_binding/lsm_plugin_ipc.cpp | 24 ++++++++++++------------
2 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/c_binding/lsm_convert.hpp b/c_binding/lsm_convert.hpp
index 0057a5c..7236654 100644
--- a/c_binding/lsm_convert.hpp
+++ b/c_binding/lsm_convert.hpp
@@ -47,6 +47,8 @@ const char CLASS_NAME_TARGET_PORT[] = "TargetPort";
#define IS_CLASS_BLOCK_RANGE(x) IS_CLASS(x, CLASS_NAME_BLOCK_RANGE)
#define IS_CLASS_ACCESS_GROUP(x) IS_CLASS(x, CLASS_NAME_ACCESS_GROUP)
#define IS_CLASS_FILE_SYSTEM(x) IS_CLASS(x, CLASS_NAME_FILE_SYSTEM)
+#define IS_CLASS_FS_SNAPSHOT(x) IS_CLASS(x, CLASS_NAME_FS_SNAPSHOT)
+#define IS_CLASS_FS_EXPORT(x) IS_CLASS(x, CLASS_NAME_FS_EXPORT)



diff --git a/c_binding/lsm_plugin_ipc.cpp b/c_binding/lsm_plugin_ipc.cpp
index 84e1c5f..14bffca 100644
--- a/c_binding/lsm_plugin_ipc.cpp
+++ b/c_binding/lsm_plugin_ipc.cpp
@@ -1611,7 +1611,7 @@ static int fs_resize(lsm_plugin_ptr p, Value &params, Value &response)
Value v_fs = params["fs"];
Value v_size = params["new_size_bytes"];

- if( Value::object_t == v_fs.valueType() &&
+ if( IS_CLASS_FILE_SYSTEM(v_fs) &&
Value::numeric_t == v_size.valueType() &&
LSM_FLAG_EXPECTED_TYPE(params) ) {

@@ -1660,7 +1660,7 @@ static int fs_clone(lsm_plugin_ptr p, Value &params, Value &response)
Value v_name = params["dest_fs_name"];
Value v_ss = params["snapshot"]; /* This is optional */

- if( Value::object_t == v_src_fs.valueType() &&
+ if( IS_CLASS_FILE_SYSTEM(v_src_fs) &&
Value::string_t == v_name.valueType() &&
(Value::null_t == v_ss.valueType() ||
Value::object_t == v_ss.valueType()) &&
@@ -1718,7 +1718,7 @@ static int fs_file_clone(lsm_plugin_ptr p, Value &params, Value &response)
Value v_dest_name = params["dest_file_name"];
Value v_ss = params["snapshot"]; /* This is optional */

- if( Value::object_t == v_fs.valueType() &&
+ if( IS_CLASS_FILE_SYSTEM(v_fs) &&
Value::string_t == v_src_name.valueType() &&
(Value::string_t == v_dest_name.valueType() ||
Value::object_t == v_ss.valueType()) &&
@@ -1768,7 +1768,7 @@ static int fs_child_dependency(lsm_plugin_ptr p, Value &params, Value &response)
Value v_fs = params["fs"];
Value v_files = params["files"];

- if( Value::object_t == v_fs.valueType() &&
+ if( IS_CLASS_FILE_SYSTEM(v_fs) &&
(Value::array_t == v_files.valueType() ||
Value::null_t == v_files.valueType()) &&
LSM_FLAG_EXPECTED_TYPE(params)) {
@@ -1808,7 +1808,7 @@ static int fs_child_dependency_rm(lsm_plugin_ptr p, Value &params, Value &respon
Value v_fs = params["fs"];
Value v_files = params["files"];

- if( Value::object_t == v_fs.valueType() &&
+ if( IS_CLASS_FILE_SYSTEM(v_fs) &&
(Value::array_t == v_files.valueType() ||
Value::null_t == v_files.valueType()) &&
LSM_FLAG_EXPECTED_TYPE(params) ) {
@@ -1848,7 +1848,7 @@ static int ss_list(lsm_plugin_ptr p, Value &params, Value &response)

Value v_fs = params["fs"];

- if( Value::object_t == v_fs.valueType() &&
+ if( IS_CLASS_FILE_SYSTEM(v_fs) &&
LSM_FLAG_EXPECTED_TYPE(params)) {

lsm_fs *fs = value_to_fs(v_fs);
@@ -1891,7 +1891,7 @@ static int ss_create(lsm_plugin_ptr p, Value &params, Value &response)
Value v_fs = params["fs"];
Value v_ss_name = params["snapshot_name"];

- if( Value::object_t == v_fs.valueType() &&
+ if( IS_CLASS_FILE_SYSTEM(v_fs) &&
Value::string_t == v_ss_name.valueType() &&
LSM_FLAG_EXPECTED_TYPE(params) ) {
lsm_fs *fs = value_to_fs(v_fs);
@@ -1939,8 +1939,8 @@ static int ss_delete(lsm_plugin_ptr p, Value &params, Value &response)
Value v_fs = params["fs"];
Value v_ss = params["snapshot"];

- if( Value::object_t == v_fs.valueType() &&
- Value::object_t == v_ss.valueType() &&
+ if( IS_CLASS_FILE_SYSTEM(v_fs) &&
+ IS_CLASS_FS_SNAPSHOT(v_ss) &&
LSM_FLAG_EXPECTED_TYPE(params)) {

lsm_fs *fs = value_to_fs(v_fs);
@@ -1979,8 +1979,8 @@ static int ss_restore(lsm_plugin_ptr p, Value &params, Value &response)
Value v_restore_files = params["restore_files"];
Value v_all_files = params["all_files"];

- if( Value::object_t == v_fs.valueType() &&
- Value::object_t == v_ss.valueType() &&
+ if( IS_CLASS_FILE_SYSTEM(v_fs) &&
+ IS_CLASS_FS_SNAPSHOT(v_ss) &&
(Value::array_t == v_files.valueType() ||
Value::null_t == v_files.valueType() ) &&
(Value::array_t == v_restore_files.valueType() ||
@@ -2172,7 +2172,7 @@ static int export_remove(lsm_plugin_ptr p, Value &params, Value &response)
if( p && p->nas_ops && p->nas_ops->nfs_export_remove ) {
Value v_export = params["export"];

- if( Value::object_t == v_export.valueType() &&
+ if( IS_CLASS_FS_EXPORT(v_export) &&
LSM_FLAG_EXPECTED_TYPE(params)) {
lsm_nfs_export *exp = value_to_nfs_export(v_export);
--
1.7.1
Tony Asleson
2015-04-29 15:12:58 UTC
Permalink
Signed-off-by: Tony Asleson <***@redhat.com>
---
c_binding/lsm_convert.cpp | 72 ++++++++++++++++++++++++++++++++--------
c_binding/lsm_convert.hpp | 9 +++--
c_binding/lsm_mgmt.cpp | 75 +++++++++++++++++++++++++----------------
c_binding/lsm_plugin_ipc.cpp | 23 ++++++++----
4 files changed, 123 insertions(+), 56 deletions(-)

diff --git a/c_binding/lsm_convert.cpp b/c_binding/lsm_convert.cpp
index 9d64e78..69c9820 100644
--- a/c_binding/lsm_convert.cpp
+++ b/c_binding/lsm_convert.cpp
@@ -50,6 +50,8 @@ lsm_volume *value_to_volume(Value &vol)
v["system_id"].asString().c_str(),
v["pool_id"].asString().c_str(),
v["plugin_data"].asC_str());
+ } else {
+ throw ValueException("value_to_volume: Not correct type");
}

return rc;
@@ -133,6 +135,8 @@ lsm_disk *value_to_disk(Value &disk)
d["status"].asUint64_t(),
d["system_id"].asString().c_str()
);
+ } else {
+ throw ValueException("value_to_disk: Not correct type");
}
return rc;
}
@@ -217,6 +221,8 @@ lsm_pool *value_to_pool(Value &pool)
i["status_info"].asString().c_str(),
i["system_id"].asString().c_str(),
i["plugin_data"].asC_str());
+ } else {
+ throw ValueException("value_to_pool: Not correct type");
}
return rc;
}
@@ -252,6 +258,8 @@ lsm_system *value_to_system(Value &system)
i["status"].asUint32_t(),
i["status_info"].asString().c_str(),
i["plugin_data"].asC_str());
+ } else {
+ throw ValueException("value_to_system: Not correct type");
}
return rc;
}
@@ -289,6 +297,8 @@ lsm_string_list *value_to_string_list(Value &v)
}
}
}
+ } else {
+ throw ValueException("value_to_string_list: Not correct type");
}
return il;
}
@@ -326,6 +336,8 @@ lsm_access_group *value_to_access_group( Value &group )
}
/* This stuff is copied in lsm_access_group_record_alloc */
lsm_string_list_free(il);
+ } else {
+ throw ValueException("value_to_access_group: Not correct type");
}
return ag;
}
@@ -346,28 +358,46 @@ Value access_group_to_value( lsm_access_group *group )
return Value();
}

-lsm_access_group **value_to_access_group_list( Value &group, uint32_t *count )
+int value_array_to_access_groups( Value &group,
+ lsm_access_group **ag_list[],
+ uint32_t *count )
{
- lsm_access_group **rc = NULL;
- std::vector<Value> ag = group.asArray();
+ int rc = LSM_ERR_OK;

- *count = ag.size();
+ try {
+ std::vector<Value> ag = group.asArray();
+ *count = ag.size();

- if( *count ) {
- rc = lsm_access_group_record_array_alloc(*count);
- if( rc ) {
- uint32_t i;
- for(i = 0; i < *count; ++i ) {
- rc[i] = value_to_access_group(ag[i]);
- if( !rc[i] ) {
- lsm_access_group_record_array_free(rc, i);
- rc = NULL;
- break;
+ if( *count ) {
+ *ag_list = lsm_access_group_record_array_alloc(*count);
+ if( *ag_list ) {
+ uint32_t i;
+ for(i = 0; i < *count; ++i ) {
+ (*ag_list)[i] = value_to_access_group(ag[i]);
+ if( !((*ag_list)[i]) ) {
+ rc = LSM_ERR_NO_MEMORY;
+ goto error;
+ }
}
+ } else {
+ rc = LSM_ERR_NO_MEMORY;
}
}
+ } catch( const ValueException &ve) {
+ rc = LSM_ERR_LIB_BUG;
+ goto error;
}
+
+ out:
return rc;
+
+error:
+ if( *ag_list && *count ) {
+ lsm_access_group_record_array_free(*ag_list, *count);
+ *ag_list = NULL;
+ *count = 0;
+ }
+ goto out;
}

Value access_group_list_to_value( lsm_access_group **group, uint32_t count)
@@ -393,6 +423,8 @@ lsm_block_range *value_to_block_range(Value &br)
rc = lsm_block_range_record_alloc(range["src_block"].asUint64_t(),
range["dest_block"].asUint64_t(),
range["block_count"].asUint64_t());
+ } else {
+ throw ValueException("value_to_block_range: Not correct type");
}
return rc;
}
@@ -457,6 +489,8 @@ lsm_fs *value_to_fs(Value &fs)
f["pool_id"].asString().c_str(),
f["system_id"].asString().c_str(),
f["plugin_data"].asC_str());
+ } else {
+ throw ValueException("value_to_fs: Not correct type");
}
return rc;
}
@@ -489,6 +523,8 @@ lsm_fs_ss *value_to_ss(Value &ss)
f["name"].asString().c_str(),
f["ts"].asUint64_t(),
f["plugin_data"].asC_str());
+ } else {
+ throw ValueException("value_to_ss: Not correct type");
}
return rc;
}
@@ -555,6 +591,8 @@ lsm_nfs_export *value_to_nfs_export(Value &exp)
lsm_string_list_free(rw);
lsm_string_list_free(ro);
}
+ } else {
+ throw ValueException("value_to_nfs_export: Not correct type");
}
return rc;
}
@@ -587,6 +625,8 @@ lsm_storage_capabilities *value_to_capabilities(Value &exp)
if( is_expected_object(exp, CLASS_NAME_CAPABILITIES) ) {
const char *val = exp["cap"].asC_str();
rc = lsm_capability_record_alloc(val);
+ } else {
+ throw ValueException("value_to_capabilities: Not correct type");
}
return rc;
}
@@ -618,6 +658,8 @@ lsm_target_port *value_to_target_port(Value &tp)
tp["physical_name"].asC_str(),
tp["system_id"].asC_str(),
tp["plugin_data"].asC_str());
+ } else {
+ throw ValueException("value_to_target_port: Not correct type");
}
return rc;
}
diff --git a/c_binding/lsm_convert.hpp b/c_binding/lsm_convert.hpp
index 907a229..0057a5c 100644
--- a/c_binding/lsm_convert.hpp
+++ b/c_binding/lsm_convert.hpp
@@ -166,12 +166,13 @@ Value LSM_DLL_LOCAL access_group_to_value(lsm_access_group *group);
/**
* Converts an access group list to an array of access group pointers
* @param[in] group Value representing a std::vector of access groups
+ * @param[out]
* @param[out] count Number of items in the returned array.
- * @return NULL on memory allocation failure, else pointer to access group
- * array.
+ * @return LSM_ERR_OK on success, else error reason
*/
-lsm_access_group LSM_DLL_LOCAL **value_to_access_group_list( Value &group,
- uint32_t *count );
+int LSM_DLL_LOCAL value_array_to_access_groups( Value &group,
+ lsm_access_group **ag_list[],
+ uint32_t *count );

/**
* Converts an array of lsm_access_group to Value(s)
diff --git a/c_binding/lsm_mgmt.cpp b/c_binding/lsm_mgmt.cpp
index 09b05dc..ee3fd1a 100644
--- a/c_binding/lsm_mgmt.cpp
+++ b/c_binding/lsm_mgmt.cpp
@@ -283,10 +283,7 @@ 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;
- }
+ rc = value_array_to_access_groups(response, groups, count);
}
} catch( const ValueException &ve ) {
rc = logException(c, LSM_ERR_LIB_BUG, "Unexpected type",
@@ -959,10 +956,11 @@ static int get_volume_array(lsm_connect *c, int rc, Value &response,
lsm_volume **volumes[], uint32_t *count)
{
if( LSM_ERR_OK == rc && Value::array_t == response.valueType()) {
- rc = value_array_to_volumes(response, volumes, count);
-
- if( LSM_ERR_OK != rc ) {
- rc = logException(c, LSM_ERR_LIB_BUG, "Unexpected type", NULL);
+ try {
+ rc = value_array_to_volumes(response, volumes, count);
+ } catch( const ValueException &ve ) {
+ rc = logException(c, LSM_ERR_LIB_BUG, "Wrong type",
+ ve.what());
}
}
return rc;
@@ -1443,14 +1441,19 @@ int lsm_access_group_create(lsm_connect *c, const char *name,
*access_group = NULL;

int rc = rpc(c, "access_group_create", parameters, response);
- if( LSM_ERR_OK == rc ) {
- //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;
+ try {
+ if( LSM_ERR_OK == rc ) {
+ //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;
+ }
}
}
+ } catch( const ValueException &ve ) {
+ rc = logException(c, LSM_ERR_LIB_BUG, "Unexpected type",
+ ve.what());
}
return rc;
}
@@ -1504,14 +1507,19 @@ static int _lsm_ag_add_delete(lsm_connect *c,
Value response;

int rc = rpc(c, message, parameters, response);
- if( LSM_ERR_OK == rc ) {
- //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;
+ try {
+ if( LSM_ERR_OK == rc ) {
+ //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;
+ }
}
}
+ } catch( const ValueException &ve ) {
+ rc = logException(c, LSM_ERR_LIB_BUG, "Unexpected type",
+ ve.what());
}

return rc;
@@ -2349,11 +2357,16 @@ int lsm_nfs_export_fs( lsm_connect *c,
Value response;

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;
+ try {
+ if( LSM_ERR_OK == rc && Value::object_t == response.valueType()) {
+ *exported = value_to_nfs_export(response);
+ if( !(*exported) ) {
+ rc = LSM_ERR_NO_MEMORY;
+ }
}
+ } catch ( const ValueException &ve ) {
+ rc = logException(c, LSM_ERR_LIB_BUG, "Unexpected type",
+ ve.what());
}
return rc;
}
@@ -2503,12 +2516,16 @@ int lsm_volume_raid_create(
Value response;

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;
+ try {
+ if( LSM_ERR_OK == rc ) {
+ *new_volume = value_to_volume(response);
+ if( ! (*new_volume) ) {
+ rc = LSM_ERR_NO_MEMORY;
+ }
}
+ } catch( const ValueException &ve ) {
+ rc = logException(c, LSM_ERR_LIB_BUG, "Unexpected type",
+ ve.what());
}
return rc;
-
}
diff --git a/c_binding/lsm_plugin_ipc.cpp b/c_binding/lsm_plugin_ipc.cpp
index 6719b85..84e1c5f 100644
--- a/c_binding/lsm_plugin_ipc.cpp
+++ b/c_binding/lsm_plugin_ipc.cpp
@@ -784,7 +784,8 @@ static int handle_volume_replicate(lsm_plugin_ptr p, Value &params, Value &respo
Value::string_t == v_name.valueType() &&
LSM_FLAG_EXPECTED_TYPE(params) ) {

- lsm_pool *pool = value_to_pool(v_pool);
+ lsm_pool *pool = (Value::null_t == v_pool.valueType()) ? NULL :
+ value_to_pool(v_pool);
lsm_volume *vol = value_to_volume(v_vol_src);
lsm_volume *newVolume = NULL;
lsm_replication_type rep = (lsm_replication_type)v_rep.asInt32_t();
@@ -1669,7 +1670,8 @@ static int fs_clone(lsm_plugin_ptr p, Value &params, Value &response)
char *job = NULL;
lsm_fs *fs = value_to_fs(v_src_fs);
const char* name = v_name.asC_str();
- lsm_fs_ss *ss = value_to_ss(v_ss);
+ lsm_fs_ss *ss = (Value::null_t == v_ss.valueType()) ?
+ NULL : value_to_ss(v_ss);

if( fs &&
(( ss && v_ss.valueType() == Value::object_t) ||
@@ -1724,7 +1726,8 @@ static int fs_file_clone(lsm_plugin_ptr p, Value &params, Value &response)


lsm_fs *fs = value_to_fs(v_fs);
- lsm_fs_ss *ss = value_to_ss(v_ss);
+ lsm_fs_ss *ss = (Value::null_t == v_ss.valueType()) ?
+ NULL : value_to_ss(v_ss);

if( fs &&
(( ss && v_ss.valueType() == Value::object_t) ||
@@ -1771,7 +1774,8 @@ static int fs_child_dependency(lsm_plugin_ptr p, Value &params, Value &response)
LSM_FLAG_EXPECTED_TYPE(params)) {

lsm_fs *fs = value_to_fs(v_fs);
- lsm_string_list *files = value_to_string_list(v_files);
+ lsm_string_list *files = (Value::null_t == v_files.valueType()) ?
+ NULL : value_to_string_list(v_files);

if( fs && ( files ||
(!files && Value::null_t == v_files.valueType()) )) {
@@ -1810,7 +1814,8 @@ static int fs_child_dependency_rm(lsm_plugin_ptr p, Value &params, Value &respon
LSM_FLAG_EXPECTED_TYPE(params) ) {

lsm_fs *fs = value_to_fs(v_fs);
- lsm_string_list *files = value_to_string_list(v_files);
+ lsm_string_list *files = (Value::null_t == v_files.valueType()) ?
+ NULL: value_to_string_list(v_files);

if( fs &&
(files || (!files && Value::null_t == v_files.valueType())) ) {
@@ -1986,9 +1991,11 @@ static int ss_restore(lsm_plugin_ptr p, Value &params, Value &response)
char *job = NULL;
lsm_fs *fs = value_to_fs(v_fs);
lsm_fs_ss *ss = value_to_ss(v_ss);
- lsm_string_list *files = value_to_string_list(v_files);
- lsm_string_list *restore_files =
- value_to_string_list(v_restore_files);
+ lsm_string_list *files = (Value::null_t == v_files.valueType()) ?
+ NULL : value_to_string_list(v_files);
+ lsm_string_list *restore_files = (Value::null_t ==
+ v_restore_files.valueType()) ?
+ NULL : value_to_string_list(v_restore_files);
int all_files = (v_all_files.asBool()) ? 1 : 0;

if( fs && ss &&
--
1.7.1
Gris Ge
2015-04-30 13:19:38 UTC
Permalink
Post by Tony Asleson
Not always consistent checking the return for NULL.
} catch( const ValueException &ve ) {
rc = logException(c, LSM_ERR_LIB_BUG, "Unexpected type",
ve.what());
- free(*job);
- *job = NULL;
+ goto error;
}
We might need to return LSM_ERR_PLUGIN_BUG when value_to_volume()
raise 'ValueException'.

Thanks for the patch works.
Best regards.
--
Gris Ge
Tony Asleson
2015-05-01 19:41:06 UTC
Permalink
Post by Gris Ge
Post by Tony Asleson
Not always consistent checking the return for NULL.
} catch( const ValueException &ve ) {
rc = logException(c, LSM_ERR_LIB_BUG, "Unexpected type",
ve.what());
- free(*job);
- *job = NULL;
+ goto error;
}
We might need to return LSM_ERR_PLUGIN_BUG when value_to_volume()
raise 'ValueException'.
Hi Gris,

I switched most of the cases from LSM_ERR_LIB_BUG to LSM_ERR_PLUGIN_BUG.
I updated the branch with an additional commit for this and added a
trivial rename on some C function names too.

Please take a look.

Thanks,
Tony
Gris Ge
2015-05-05 14:39:06 UTC
Permalink
Post by Tony Asleson
Post by Gris Ge
Post by Tony Asleson
Not always consistent checking the return for NULL.
} catch( const ValueException &ve ) {
rc = logException(c, LSM_ERR_LIB_BUG, "Unexpected type",
ve.what());
- free(*job);
- *job = NULL;
+ goto error;
}
We might need to return LSM_ERR_PLUGIN_BUG when value_to_volume()
raise 'ValueException'.
Hi Gris,
I switched most of the cases from LSM_ERR_LIB_BUG to LSM_ERR_PLUGIN_BUG.
I updated the branch with an additional commit for this and added a
trivial rename on some C function names too.
Please take a look.
Thanks,
Tony
Hi Tony,

Looks good. Merged.

Thanks for the patches.
Best regards.
--
Gris Ge
Loading...