Discussion:
[Libstoragemgmt-devel] [PATCH 5/5] lsm_rest: Use strdup when appropriate
Christophe Fergeau
2014-11-12 22:37:13 UTC
Permalink
---
daemon/lsm_rest.c | 9 ++-------
1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/daemon/lsm_rest.c b/daemon/lsm_rest.c
index 0fee48a..d1e0a00 100644
--- a/daemon/lsm_rest.c
+++ b/daemon/lsm_rest.c
@@ -157,8 +157,7 @@ static int connect_socket(const char *uri_str, const char *plugin_dir,
uri_obj = xmlParseURI(uri_str);
char *uri_scheme = NULL;
if (uri_obj != NULL){
- uri_scheme = (char *)malloc(strlen((*uri_obj).scheme)+ 1);
- strcpy(uri_scheme, (*uri_obj).scheme);
+ uri_scheme = strdup(uri_obj->scheme);
xmlFreeURI(uri_obj);
uri_obj = NULL;
}else{
@@ -338,11 +337,7 @@ static char *rpc(int socket_fd, const char *method, ParaList_t *para_list,
result_str = (char*) json_object_to_json_string_ext(
result_json,
JSON_C_TO_STRING_PRETTY);
- char *rc_msg = NULL;
- if (strlen(result_str) > 0){
- rc_msg = (char *)malloc(strlen(result_str) + 1);
- strcpy(rc_msg, result_str);
- }
+ char *rc_msg = strdup(result_str);
json_object_put(recv_json);
return rc_msg;
}
--
2.1.0
Christophe Fergeau
2014-11-12 22:37:11 UTC
Permalink
The correct name is LSM_ERR_OK.
---
c_binding/include/libstoragemgmt/libstoragemgmt.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/c_binding/include/libstoragemgmt/libstoragemgmt.h b/c_binding/include/libstoragemgmt/libstoragemgmt.h
index b421424..879f184 100644
--- a/c_binding/include/libstoragemgmt/libstoragemgmt.h
+++ b/c_binding/include/libstoragemgmt/libstoragemgmt.h
@@ -201,7 +201,7 @@ extern "C" {
* @param[in] conn Valid connection pointer
* @param[in] job_id Job ID
* @param[in] flags Reserved for future use, must be zero.
- * @return LSM_ERROR_OK, else error reason.
+ * @return LSM_ERR_OK, else error reason.
*/
int LSM_DLL_EXPORT lsm_job_free(lsm_connect *conn, char **job_id,
lsm_flag flags);
--
2.1.0
Tony Asleson
2014-11-13 23:00:24 UTC
Permalink
Patch committed!

Thanks,
Tony
Post by Christophe Fergeau
The correct name is LSM_ERR_OK.
---
c_binding/include/libstoragemgmt/libstoragemgmt.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/c_binding/include/libstoragemgmt/libstoragemgmt.h b/c_binding/include/libstoragemgmt/libstoragemgmt.h
index b421424..879f184 100644
--- a/c_binding/include/libstoragemgmt/libstoragemgmt.h
+++ b/c_binding/include/libstoragemgmt/libstoragemgmt.h
@@ -201,7 +201,7 @@ extern "C" {
*/
int LSM_DLL_EXPORT lsm_job_free(lsm_connect *conn, char **job_id,
lsm_flag flags);
Christophe Fergeau
2014-11-12 22:37:12 UTC
Permalink
---
c_binding/include/libstoragemgmt/libstoragemgmt_volumes.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/c_binding/include/libstoragemgmt/libstoragemgmt_volumes.h b/c_binding/include/libstoragemgmt/libstoragemgmt_volumes.h
index 5d4d798..ee03010 100644
--- a/c_binding/include/libstoragemgmt/libstoragemgmt_volumes.h
+++ b/c_binding/include/libstoragemgmt/libstoragemgmt_volumes.h
@@ -57,7 +57,7 @@ int LSM_DLL_EXPORT lsm_volume_record_array_free( lsm_volume *init[], uint32_t si
const char LSM_DLL_EXPORT *lsm_volume_id_get(lsm_volume *v);

/**
- * Retrieves the volume name (human recognizable
+ * Retrieves the volume name (human recognizable)
* Note: returned value only valid when v is valid!
* @param v Volume ptr.
* @return Volume name
--
2.1.0
Tony Asleson
2014-11-13 23:00:35 UTC
Permalink
Patch committed!

Thanks,
Tony
Post by Christophe Fergeau
---
c_binding/include/libstoragemgmt/libstoragemgmt_volumes.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/c_binding/include/libstoragemgmt/libstoragemgmt_volumes.h b/c_binding/include/libstoragemgmt/libstoragemgmt_volumes.h
index 5d4d798..ee03010 100644
--- a/c_binding/include/libstoragemgmt/libstoragemgmt_volumes.h
+++ b/c_binding/include/libstoragemgmt/libstoragemgmt_volumes.h
@@ -57,7 +57,7 @@ int LSM_DLL_EXPORT lsm_volume_record_array_free( lsm_volume *init[], uint32_t si
const char LSM_DLL_EXPORT *lsm_volume_id_get(lsm_volume *v);
/**
- * Retrieves the volume name (human recognizable
+ * Retrieves the volume name (human recognizable)
* Note: returned value only valid when v is valid!
Christophe Fergeau
2014-11-12 22:37:10 UTC
Permalink
Running 'make install' in the packaging dir tries to write some files to
/usr regardless of the prefix being used, which fails if make install is
ran as non-root. As the daemon dir is listed after the packaging dir,
the daemon will not get installed in this situation as make install will
fail while processing packaging.

The files from packaging/ are not mandatory during
development/local testing, so they can be processed last. make install
will still fail when being run unpriviledged, but at least the daemon
will be installed.
---
Makefile.am | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Makefile.am b/Makefile.am
index 50a5455..99e7578 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -4,7 +4,7 @@ ACLOCAL_AMFLAGS = -I m4

DISTCHECK_CONFIGURE_FLAGS = --with-systemdsystemunitdir=$$dc_install_base/$(systemdsystemunitdir)

-SUBDIRS= c_binding python_binding plugin doc tools packaging daemon
+SUBDIRS= c_binding python_binding plugin doc tools daemon packaging

if BUILD_C_UNIT
SUBDIRS += test
--
2.1.0
Tony Asleson
2014-11-13 23:00:14 UTC
Permalink
Patch committed!

Thanks,
Tony
Post by Christophe Fergeau
Running 'make install' in the packaging dir tries to write some files to
/usr regardless of the prefix being used, which fails if make install is
ran as non-root. As the daemon dir is listed after the packaging dir,
the daemon will not get installed in this situation as make install will
fail while processing packaging.
The files from packaging/ are not mandatory during
development/local testing, so they can be processed last. make install
will still fail when being run unpriviledged, but at least the daemon
will be installed.
---
Makefile.am | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Makefile.am b/Makefile.am
index 50a5455..99e7578 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -4,7 +4,7 @@ ACLOCAL_AMFLAGS = -I m4
DISTCHECK_CONFIGURE_FLAGS = --with-systemdsystemunitdir=$$dc_install_base/$(systemdsystemunitdir)
-SUBDIRS= c_binding python_binding plugin doc tools packaging daemon
+SUBDIRS= c_binding python_binding plugin doc tools daemon packaging
if BUILD_C_UNIT
SUBDIRS += test
Tony Asleson
2014-11-13 18:06:46 UTC
Permalink
On 11/12/2014 04:37 PM, Christophe Fergeau wrote:> @@ -338,11 +337,7 @@
static char *rpc(int socket_fd, const char *method, ParaList_t *para_list,
Post by Christophe Fergeau
result_str = (char*) json_object_to_json_string_ext(
result_json,
JSON_C_TO_STRING_PRETTY);
- char *rc_msg = NULL;
- if (strlen(result_str) > 0){
- rc_msg = (char *)malloc(strlen(result_str) + 1);
- strcpy(rc_msg, result_str);
- }
+ char *rc_msg = strdup(result_str);
Both strlen & strdup are expecting a null terminated string parameter,
so this code change isn't any different from existing. I do wonder if
json_object_to_json_string_ext can ever return NULL though.

Thanks,
Tony
Tony Asleson
2014-11-13 23:00:05 UTC
Permalink
Patch committed!

Thanks,
Tony
The rest of the daemon uses the 'plugin_extension' constant rather than
directly referring to "_lsmplugin"
---
daemon/lsm_daemon.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/daemon/lsm_daemon.c b/daemon/lsm_daemon.c
index ef958f1..acc8ef5 100644
--- a/daemon/lsm_daemon.c
+++ b/daemon/lsm_daemon.c
@@ -336,7 +336,7 @@ int setup_socket(char *full_name)
memset(name, 0, sizeof(name));
char *base_nm = basename(full_name);
- strncpy(name, base_nm, min(abs(strlen(base_nm) - 10), (sizeof(name)-1)));
+ strncpy(name, base_nm, min(abs(strlen(base_nm) - strlen(plugin_extension)), (sizeof(name)-1)));
char *socket_file = path_form(socket_dir, name);
delete_socket(NULL, socket_file);
Tony Asleson
2014-11-13 23:00:46 UTC
Permalink
Patch committed!

Thanks,
Tony
Post by Christophe Fergeau
---
daemon/lsm_rest.c | 9 ++-------
1 file changed, 2 insertions(+), 7 deletions(-)
diff --git a/daemon/lsm_rest.c b/daemon/lsm_rest.c
index 0fee48a..d1e0a00 100644
--- a/daemon/lsm_rest.c
+++ b/daemon/lsm_rest.c
@@ -157,8 +157,7 @@ static int connect_socket(const char *uri_str, const char *plugin_dir,
uri_obj = xmlParseURI(uri_str);
char *uri_scheme = NULL;
if (uri_obj != NULL){
- uri_scheme = (char *)malloc(strlen((*uri_obj).scheme)+ 1);
- strcpy(uri_scheme, (*uri_obj).scheme);
+ uri_scheme = strdup(uri_obj->scheme);
xmlFreeURI(uri_obj);
uri_obj = NULL;
}else{
@@ -338,11 +337,7 @@ static char *rpc(int socket_fd, const char *method, ParaList_t *para_list,
result_str = (char*) json_object_to_json_string_ext(
result_json,
JSON_C_TO_STRING_PRETTY);
- char *rc_msg = NULL;
- if (strlen(result_str) > 0){
- rc_msg = (char *)malloc(strlen(result_str) + 1);
- strcpy(rc_msg, result_str);
- }
+ char *rc_msg = strdup(result_str);
json_object_put(recv_json);
return rc_msg;
}
Loading...