celix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pnol...@apache.org
Subject celix git commit: CELIX-358: Fixes coverity issues (many low and some high priority)
Date Mon, 02 May 2016 13:19:29 GMT
Repository: celix
Updated Branches:
  refs/heads/develop 137fdf5c3 -> d813e8b47


CELIX-358: Fixes coverity issues (many low and some high priority)


Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/d813e8b4
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/d813e8b4
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/d813e8b4

Branch: refs/heads/develop
Commit: d813e8b47ebd074a18d39bf05aa9ab7f70103597
Parents: 137fdf5
Author: Pepijn Noltes <pepijnnoltes@gmail.com>
Authored: Mon May 2 15:21:12 2016 +0200
Committer: Pepijn Noltes <pepijnnoltes@gmail.com>
Committed: Mon May 2 15:21:12 2016 +0200

----------------------------------------------------------------------
 deployment_admin/private/src/deployment_admin.c | 16 +++--
 deployment_admin/private/src/unzip.c            |  1 +
 dfi/private/src/json_rpc.c                      |  4 +-
 dfi/private/test/dyn_interface_tests.cpp        | 15 ++---
 examples/mongoose/private/src/mongoose.c        | 15 ++---
 .../database/private/src/activator.c            | 10 ++--
 .../database/private/src/reader.c               |  4 +-
 framework/private/src/bundle_archive.c          |  6 +-
 framework/private/src/framework.c               |  7 ++-
 framework/private/src/manifest_parser.c         | 23 ++++---
 framework/private/src/resolver.c                |  2 +
 framework/private/src/service_reference.c       |  2 +-
 framework/private/src/unzip.c                   |  1 +
 framework/private/test/bundle_cache_test.cpp    |  1 +
 .../discovery/private/src/discovery_activator.c |  3 +
 .../private/src/remote_service_admin_impl.c     |  4 +-
 .../private/src/remote_service_admin_impl.c     | 63 +++++++++++---------
 remote_services/utils/private/src/civetweb.c    | 28 ++++-----
 shell/private/src/update_command.c              |  2 +
 utils/private/src/hash_map.c                    |  2 +-
 20 files changed, 121 insertions(+), 88 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/d813e8b4/deployment_admin/private/src/deployment_admin.c
----------------------------------------------------------------------
diff --git a/deployment_admin/private/src/deployment_admin.c b/deployment_admin/private/src/deployment_admin.c
index 2c4b9ee..1d39477 100644
--- a/deployment_admin/private/src/deployment_admin.c
+++ b/deployment_admin/private/src/deployment_admin.c
@@ -438,8 +438,9 @@ celix_status_t deploymentAdmin_download(deployment_admin_pt admin, char
* url, c
 			snprintf(*inputFile, 1024, "%s/%s", dir, "updateXXXXXX");
 		}
 		else {
-				*inputFile = strdup("updateXXXXXX");
+			*inputFile = strdup("updateXXXXXX");
 		}
+		umask(0000);
         int fd = mkstemp(*inputFile);
         if (fd != -1) {
             FILE *fp = fopen(*inputFile, "wb+");
@@ -451,19 +452,22 @@ celix_status_t deploymentAdmin_download(deployment_admin_pt admin, char
* url, c
             //curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0);
             //curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, updateCommand_downloadProgress);
             res = curl_easy_perform(curl);
-            if (res != CURLE_OK) {
-                status = CELIX_BUNDLE_EXCEPTION;
-            }
+
             /* always cleanup */
             curl_easy_cleanup(curl);
             fclose(fp);
         }
+        else{
+		status = CELIX_FILE_IO_EXCEPTION;
+        }
 	}
+	else{
+		res = CURLE_FAILED_INIT;
+	}
+
 	if (res != CURLE_OK) {
 		*inputFile[0] = '\0';
 		status = CELIX_ILLEGAL_STATE;
-	} else {
-		status = CELIX_SUCCESS;
 	}
 
 	return status;

http://git-wip-us.apache.org/repos/asf/celix/blob/d813e8b4/deployment_admin/private/src/unzip.c
----------------------------------------------------------------------
diff --git a/deployment_admin/private/src/unzip.c b/deployment_admin/private/src/unzip.c
index 3aab52c..d8a6716 100644
--- a/deployment_admin/private/src/unzip.c
+++ b/deployment_admin/private/src/unzip.c
@@ -603,6 +603,7 @@ local unzFile unzOpenInternal (const void *path,
     if (unz_copyright[0]!=' ')
         return NULL;
 
+    memset(&us,0,sizeof(unz64_s));
     us.z_filefunc.zseek32_file = NULL;
     us.z_filefunc.ztell32_file = NULL;
     if (pzlib_filefunc64_32_def==NULL)

http://git-wip-us.apache.org/repos/asf/celix/blob/d813e8b4/dfi/private/src/json_rpc.c
----------------------------------------------------------------------
diff --git a/dfi/private/src/json_rpc.c b/dfi/private/src/json_rpc.c
index 72e3c7e..0abbc93 100644
--- a/dfi/private/src/json_rpc.c
+++ b/dfi/private/src/json_rpc.c
@@ -178,7 +178,9 @@ int jsonRpc_call(dyn_interface_type *intf, void *service, const char *request,
c
 							status = dynType_typedPointer_getTypedType(typedType, &typedTypedType);
 						}
 
-						status = jsonSerializer_serializeJson(typedTypedType, ptr, &jsonResult);
+						if(status == OK){
+							status = jsonSerializer_serializeJson(typedTypedType, ptr, &jsonResult);
+						}
 
 						if (status == OK) {
 							dynType_free(typedTypedType, ptr);

http://git-wip-us.apache.org/repos/asf/celix/blob/d813e8b4/dfi/private/test/dyn_interface_tests.cpp
----------------------------------------------------------------------
diff --git a/dfi/private/test/dyn_interface_tests.cpp b/dfi/private/test/dyn_interface_tests.cpp
index d417685..ea578f2 100644
--- a/dfi/private/test/dyn_interface_tests.cpp
+++ b/dfi/private/test/dyn_interface_tests.cpp
@@ -119,7 +119,7 @@ extern "C" {
         FILE *desc = fopen("descriptors/invalids/invalid.descriptor", "r");
         assert(desc != NULL);
         status = dynInterface_parse(desc, &dynIntf);
-        dynInterface_destroy(dynIntf);
+        //dynInterface_destroy(dynIntf);
         CHECK_EQUAL(1, status); //Test fails because of a space at the end of the name
         fclose(desc); desc=NULL;
 
@@ -128,7 +128,7 @@ extern "C" {
         desc = fopen("descriptors/invalids/noVersion.descriptor", "r");
         assert(desc != NULL);
         status = dynInterface_parse(desc, &dynIntf);
-        dynInterface_destroy(dynIntf);
+        //dynInterface_destroy(dynIntf);
         CHECK_EQUAL(1, status); //Test fails because of missing version field in header section
         fclose(desc); desc=NULL;
 
@@ -136,7 +136,7 @@ extern "C" {
         desc = fopen("descriptors/invalids/invalidSection.descriptor", "r");
         assert(desc != NULL);
         status = dynInterface_parse(desc, &dynIntf);
-        dynInterface_destroy(dynIntf);
+        //dynInterface_destroy(dynIntf);
         CHECK_EQUAL(1, status); //Test fails because of unknown section type
         fclose(desc); desc=NULL;
 
@@ -144,7 +144,7 @@ extern "C" {
         desc = fopen("descriptors/invalids/invalidMethodReturnType.descriptor", "r");
         assert(desc != NULL);
         status = dynInterface_parse(desc, &dynIntf);
-        dynInterface_destroy(dynIntf);
+        //dynInterface_destroy(dynIntf);
         CHECK_EQUAL(1, status); //Test fails because of invalid return type (D instead of
N)
         fclose(desc); desc=NULL;
 
@@ -152,7 +152,7 @@ extern "C" {
         desc = fopen("descriptors/invalids/invalidMethod.descriptor", "r");
         assert(desc != NULL);
         status = dynInterface_parse(desc, &dynIntf);
-        dynInterface_destroy(dynIntf);
+        //dynInterface_destroy(dynIntf);
         CHECK_EQUAL(1, status); //Test fails because of space at the end of the method
         fclose(desc); desc=NULL;
 
@@ -160,7 +160,7 @@ extern "C" {
         desc = fopen("descriptors/invalids/invalidType.descriptor", "r");
         assert(desc != NULL);
         status = dynInterface_parse(desc, &dynIntf);
-        dynInterface_destroy(dynIntf);
+        //dynInterface_destroy(dynIntf);
         CHECK_EQUAL(1, status); //Test fails because of space at the end of the type
         fclose(desc); desc=NULL;
 
@@ -170,12 +170,13 @@ extern "C" {
         status = dynInterface_parse(desc, &dynIntf);
         dynInterface_destroy(dynIntf);
         CHECK_EQUAL(0, status); //Invalid meta type doesn't generate errors, just warnings
-        fclose(desc); desc=NULL;
+        fclose(desc); desc=NULL; dynIntf=NULL;
 
         /* Invalid version section */
         desc = fopen("descriptors/invalids/invalidVersion.descriptor", "r");
         assert(desc != NULL);
         status = dynInterface_parse(desc, &dynIntf);
+        //dynInterface_destroy(dynIntf);
         CHECK_EQUAL(1, status); //Invalid meta type doesn't generate errors, just warnings
         fclose(desc); desc=NULL;
 

http://git-wip-us.apache.org/repos/asf/celix/blob/d813e8b4/examples/mongoose/private/src/mongoose.c
----------------------------------------------------------------------
diff --git a/examples/mongoose/private/src/mongoose.c b/examples/mongoose/private/src/mongoose.c
index d133ab3..68f1a77 100644
--- a/examples/mongoose/private/src/mongoose.c
+++ b/examples/mongoose/private/src/mongoose.c
@@ -1204,12 +1204,12 @@ static int start_thread(struct mg_context *ctx, mg_thread_func_pt
func,
 
 #ifndef NO_CGI
 static pid_t spawn_process(struct mg_connection *conn, const char *prog,
-                           char *envblk, char *envp[], int fd_stdin,
+		__attribute__((unused)) char *envblk, char *envp[], int fd_stdin,
                            int fd_stdout, const char *dir) {
   pid_t pid;
   const char *interp;
 
-  envblk = NULL; // Unused
+  // envblk = NULL; // Unused
 
   if ((pid = fork()) == -1) {
     // Parent
@@ -3454,10 +3454,10 @@ static int set_uid_option(struct mg_context *ctx) {
 #if !defined(NO_SSL)
 static pthread_mutex_t *ssl_mutexes;
 
-static void ssl_locking_callback(int mode, int mutex_num, const char *file,
-                                 int line) {
-  line = 0;    // Unused
-  file = NULL; // Unused
+static void ssl_locking_callback(int mode, int mutex_num, __attribute__((unused)) const char
*file,
+		__attribute__((unused)) int line) {
+  // line = 0;    // Unused
+  // file = NULL; // Unused
 
   if (mode & CRYPTO_LOCK) {
     (void) pthread_mutex_lock(&ssl_mutexes[mutex_num]);
@@ -3816,7 +3816,8 @@ static void worker_thread(struct mg_context *ctx) {
 
   conn = calloc(1, sizeof(*conn));
   conn->buf_size = buf_size;
-  conn->buf = calloc(buf_size + 1, sizeof(char));
+  //+5 because in some point of the code there are direct accesses to buf with index>=2
+  conn->buf = calloc(buf_size + 5, sizeof(char));
   assert(conn != NULL);
 
   while (ctx->stop_flag == 0 && consume_socket(ctx, &conn->client)) {

http://git-wip-us.apache.org/repos/asf/celix/blob/d813e8b4/examples/producer_consumer/database/private/src/activator.c
----------------------------------------------------------------------
diff --git a/examples/producer_consumer/database/private/src/activator.c b/examples/producer_consumer/database/private/src/activator.c
index babb2b5..3d866e1 100644
--- a/examples/producer_consumer/database/private/src/activator.c
+++ b/examples/producer_consumer/database/private/src/activator.c
@@ -75,7 +75,7 @@ celix_status_t bundleActivator_create(bundle_context_pt context, void **userData
 
 
 celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) {
-	celix_status_t status = CELIX_SUCCESS;
+	celix_status_t status = CELIX_ENOMEM;
 	struct activator *activator = userData;
 	reader_service_pt readerService = calloc(1, sizeof(struct reader_service));
 	writer_service_pt writerService = calloc(1, sizeof(struct writer_service));
@@ -103,12 +103,13 @@ celix_status_t bundleActivator_start(void * userData, bundle_context_pt
context)
 
 			status = bundleContext_registerService(context, READER_SERVICE_NAME, activator->readerService,
NULL,  &activator->readerRegistration);
 
-			if (status == CELIX_SUCCESS)
+			if (status == CELIX_SUCCESS){
 				status = bundleContext_registerService(context, WRITER_SERVICE_NAME, activator->writerService,
NULL,  &activator->writerRegistration);
+			}
 		}
 	}
-	else
-	{
+
+	if(status != CELIX_SUCCESS){
 		if(readerService!=NULL){
 			free(readerService);
 		}
@@ -118,7 +119,6 @@ celix_status_t bundleActivator_start(void * userData, bundle_context_pt
context)
 		if(databaseHandler!=NULL){
 			free(databaseHandler);
 		}
-		status = CELIX_ENOMEM;
 	}
 
 	return status;

http://git-wip-us.apache.org/repos/asf/celix/blob/d813e8b4/examples/producer_consumer/database/private/src/reader.c
----------------------------------------------------------------------
diff --git a/examples/producer_consumer/database/private/src/reader.c b/examples/producer_consumer/database/private/src/reader.c
index de4df77..c28cd7b 100644
--- a/examples/producer_consumer/database/private/src/reader.c
+++ b/examples/producer_consumer/database/private/src/reader.c
@@ -36,13 +36,13 @@
 #include "reader_service.h"
 
 
-celix_status_t readerService_getFirstData(database_handler_pt handler, data_pt firstData)
+celix_status_t readerService_getFirstData(database_handler_pt handler, __attribute__((unused))
data_pt firstData)
 {
 	celix_status_t status = CELIX_BUNDLE_EXCEPTION;
 
 	celixThreadMutex_lock(&handler->lock);
 
-	if ((firstData = (data_pt) arrayList_remove(handler->data, 0)) != NULL)
+	if (arrayList_remove(handler->data, 0) != NULL)
 	{
 		handler->dataIndex--;
 		status = CELIX_SUCCESS;

http://git-wip-us.apache.org/repos/asf/celix/blob/d813e8b4/framework/private/src/bundle_archive.c
----------------------------------------------------------------------
diff --git a/framework/private/src/bundle_archive.c b/framework/private/src/bundle_archive.c
index 4c838a6..5f851c3 100644
--- a/framework/private/src/bundle_archive.c
+++ b/framework/private/src/bundle_archive.c
@@ -71,7 +71,7 @@ celix_status_t bundleArchive_createSystemBundleArchive(bundle_archive_pt
*bundle
 		status = CELIX_ILLEGAL_ARGUMENT;
 		error = "Missing required arguments and/or incorrect values";
 	} else {
-		archive = (bundle_archive_pt) malloc(sizeof(*archive));
+		archive = (bundle_archive_pt) calloc(1,sizeof(*archive));
 		if (archive == NULL) {
 			status = CELIX_ENOMEM;
 		} else {
@@ -108,7 +108,7 @@ celix_status_t bundleArchive_create(char * archiveRoot, long id, char
* location
 		status = CELIX_ILLEGAL_ARGUMENT;
 		error = "bundle_archive_pt must be NULL";
 	} else {
-		archive = (bundle_archive_pt) malloc(sizeof(*archive));
+		archive = (bundle_archive_pt) calloc(1,sizeof(*archive));
 		if (archive == NULL) {
 			status = CELIX_ENOMEM;
 		} else {
@@ -179,7 +179,7 @@ celix_status_t bundleArchive_recreate(char * archiveRoot, bundle_archive_pt
*bun
 
 	bundle_archive_pt archive = NULL;
 
-	archive = (bundle_archive_pt) malloc(sizeof(*archive));
+	archive = (bundle_archive_pt) calloc(1,sizeof(*archive));
 	if (archive == NULL) {
 		status = CELIX_ENOMEM;
 	} else {

http://git-wip-us.apache.org/repos/asf/celix/blob/d813e8b4/framework/private/src/framework.c
----------------------------------------------------------------------
diff --git a/framework/private/src/framework.c b/framework/private/src/framework.c
index 3df30c9..b81c77a 100644
--- a/framework/private/src/framework.c
+++ b/framework/private/src/framework.c
@@ -440,7 +440,7 @@ celix_status_t fw_init(framework_pt framework) {
             bundle_context_pt context = NULL;
             void * userData = NULL;
 
-			create_function_pt create = NULL;
+			//create_function_pt create = NULL;
 			start_function_pt start = (start_function_pt) frameworkActivator_start;
 			stop_function_pt stop = (stop_function_pt) frameworkActivator_stop;
 			destroy_function_pt destroy = (destroy_function_pt) frameworkActivator_destroy;
@@ -452,9 +452,12 @@ celix_status_t fw_init(framework_pt framework) {
             status = CELIX_DO_IF(status, bundle_getContext(framework->bundle, &context));
 
             if (status == CELIX_SUCCESS) {
-                if (create != NULL) {
+                /* This code part is in principle dead, but in future it may do something.
+                 * That's why it's outcommented and not deleted
+		if (create != NULL) {
                     create(context, &userData);
                 }
+                */
                 activator->userData = userData;
 
                 if (start != NULL) {

http://git-wip-us.apache.org/repos/asf/celix/blob/d813e8b4/framework/private/src/manifest_parser.c
----------------------------------------------------------------------
diff --git a/framework/private/src/manifest_parser.c b/framework/private/src/manifest_parser.c
index e16a4f3..a400a99 100644
--- a/framework/private/src/manifest_parser.c
+++ b/framework/private/src/manifest_parser.c
@@ -176,7 +176,7 @@ static linked_list_pt manifestParser_parseStandardHeaderClause(char *
clauseStri
 
 	pieces = manifestParser_parseDelimitedString(clauseString, ";");
 
-	if (linkedList_create(&paths) == CELIX_SUCCESS) {
+	if ((pieces != NULL) && (linkedList_create(&paths) == CELIX_SUCCESS)) {
 		int pathCount = 0;
 		int pieceIdx;
 		hash_map_pt dirsMap = NULL;
@@ -245,6 +245,10 @@ static linked_list_pt manifestParser_parseStandardHeaderClause(char *
clauseStri
 				}
 			}
 
+			if(linkedList_create(&clause) != CELIX_SUCCESS){
+				failure=true;
+			}
+
 			if(failure){
 				hashMap_destroy(dirsMap,false,false);
 				hash_map_iterator_pt attrIter = hashMapIterator_create(attrsMap);
@@ -263,8 +267,12 @@ static linked_list_pt manifestParser_parseStandardHeaderClause(char *
clauseStri
 				if(value!=NULL){
 					free(value);
 				}
+				linkedList_destroy(paths);
+				if(clause!=NULL){
+					linkedList_destroy(clause);
+				}
 			}
-			else if(linkedList_create(&clause) == CELIX_SUCCESS) {
+			else{
 				linkedList_addElement(clause, paths);
 				linkedList_addElement(clause, dirsMap);
 				linkedList_addElement(clause, attrsMap);
@@ -274,14 +282,15 @@ static linked_list_pt manifestParser_parseStandardHeaderClause(char
* clauseStri
 		else{
 			linkedList_destroy(paths);
 		}
-	}
 
-	for(int listIdx = 0; listIdx < linkedList_size(pieces); listIdx++){
-		void * element = linkedList_get(pieces, listIdx);
-		free(element);
+		for(int listIdx = 0; listIdx < linkedList_size(pieces); listIdx++){
+			void * element = linkedList_get(pieces, listIdx);
+			free(element);
+		}
+		linkedList_destroy(pieces);
 	}
 
-	linkedList_destroy(pieces);
+
 
 	return clause;
 }

http://git-wip-us.apache.org/repos/asf/celix/blob/d813e8b4/framework/private/src/resolver.c
----------------------------------------------------------------------
diff --git a/framework/private/src/resolver.c b/framework/private/src/resolver.c
index 02d371c..f9c1227 100644
--- a/framework/private/src/resolver.c
+++ b/framework/private/src/resolver.c
@@ -275,6 +275,7 @@ void resolver_addModule(module_pt module) {
                     else{
                     	free(list->serviceName);
                     	free(list);
+			list=NULL;
                     }
                 }
             }
@@ -398,6 +399,7 @@ void resolver_moduleResolved(module_pt module) {
                             else{
                             	free(list->serviceName);
                             	free(list);
+				list=NULL;
                             }
                         }
                     }

http://git-wip-us.apache.org/repos/asf/celix/blob/d813e8b4/framework/private/src/service_reference.c
----------------------------------------------------------------------
diff --git a/framework/private/src/service_reference.c b/framework/private/src/service_reference.c
index c40d3c2..5230be6 100644
--- a/framework/private/src/service_reference.c
+++ b/framework/private/src/service_reference.c
@@ -222,7 +222,7 @@ FRAMEWORK_EXPORT celix_status_t serviceReference_getPropertyKeys(service_referen
     int i = 0;
     int vsize = hashMap_size(props);
     *size = (unsigned int)vsize;
-    *keys = malloc(vsize * sizeof(*keys));
+    *keys = malloc(vsize * sizeof(**keys));
     it = hashMapIterator_create(props);
     while (hashMapIterator_hasNext(it)) {
         (*keys)[i] = hashMapIterator_nextKey(it);

http://git-wip-us.apache.org/repos/asf/celix/blob/d813e8b4/framework/private/src/unzip.c
----------------------------------------------------------------------
diff --git a/framework/private/src/unzip.c b/framework/private/src/unzip.c
index 3aab52c..d8a6716 100644
--- a/framework/private/src/unzip.c
+++ b/framework/private/src/unzip.c
@@ -603,6 +603,7 @@ local unzFile unzOpenInternal (const void *path,
     if (unz_copyright[0]!=' ')
         return NULL;
 
+    memset(&us,0,sizeof(unz64_s));
     us.z_filefunc.zseek32_file = NULL;
     us.z_filefunc.ztell32_file = NULL;
     if (pzlib_filefunc64_32_def==NULL)

http://git-wip-us.apache.org/repos/asf/celix/blob/d813e8b4/framework/private/test/bundle_cache_test.cpp
----------------------------------------------------------------------
diff --git a/framework/private/test/bundle_cache_test.cpp b/framework/private/test/bundle_cache_test.cpp
index f61186c..13e0e80 100644
--- a/framework/private/test/bundle_cache_test.cpp
+++ b/framework/private/test/bundle_cache_test.cpp
@@ -84,6 +84,7 @@ TEST(bundle_cache, deleteTree) {
 	LONGS_EQUAL(rv,0);
 
 	//mkstemp opens the file for safety, but bundlecache_delete needs to reopen the file
+	umask(0033);
 	int fd = mkstemp(cacheFile);
 	if(fd>=0){
 		close(fd);

http://git-wip-us.apache.org/repos/asf/celix/blob/d813e8b4/remote_services/discovery/private/src/discovery_activator.c
----------------------------------------------------------------------
diff --git a/remote_services/discovery/private/src/discovery_activator.c b/remote_services/discovery/private/src/discovery_activator.c
index bf5d157..e98de1a 100644
--- a/remote_services/discovery/private/src/discovery_activator.c
+++ b/remote_services/discovery/private/src/discovery_activator.c
@@ -84,6 +84,9 @@ celix_status_t bundleActivator_create(bundle_context_pt context, void **userData
 			bundleActivator_destroy(activator,context);
 		}
 	}
+	else{
+		free(activator);
+	}
 
 	return status;
 }

http://git-wip-us.apache.org/repos/asf/celix/blob/d813e8b4/remote_services/remote_service_admin_http/private/src/remote_service_admin_impl.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_http/private/src/remote_service_admin_impl.c
b/remote_services/remote_service_admin_http/private/src/remote_service_admin_impl.c
index e508c0f..7f76e3a 100644
--- a/remote_services/remote_service_admin_http/private/src/remote_service_admin_impl.c
+++ b/remote_services/remote_service_admin_http/private/src/remote_service_admin_impl.c
@@ -162,8 +162,9 @@ celix_status_t remoteServiceAdmin_create(bundle_context_pt context, remote_servi
 		memset(&callbacks, 0, sizeof(callbacks));
 		callbacks.begin_request = remoteServiceAdmin_callback;
 
+		char newPort[10];
 		do {
-			char newPort[10];
+
 			const char *options[] = { "listening_ports", port, NULL};
 
 			(*admin)->ctx = mg_start(&callbacks, (*admin), options);
@@ -171,7 +172,6 @@ celix_status_t remoteServiceAdmin_create(bundle_context_pt context, remote_servi
 			if ((*admin)->ctx != NULL) {
 				logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_INFO, "RSA: Start webserver: %s",
port);
 				(*admin)->port = strdup(port);
-
 			}
 			else {
 		        char* endptr = port;

http://git-wip-us.apache.org/repos/asf/celix/blob/d813e8b4/remote_services/remote_service_admin_shm/private/src/remote_service_admin_impl.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_shm/private/src/remote_service_admin_impl.c
b/remote_services/remote_service_admin_shm/private/src/remote_service_admin_impl.c
index 5b1ffa8..9f54902 100644
--- a/remote_services/remote_service_admin_shm/private/src/remote_service_admin_impl.c
+++ b/remote_services/remote_service_admin_shm/private/src/remote_service_admin_impl.c
@@ -389,14 +389,17 @@ celix_status_t remoteServiceAdmin_getSharedIdentifierFile(remote_service_admin_p
 celix_status_t remoteServiceAdmin_removeSharedIdentityFile(remote_service_admin_pt admin,
char *fwUuid, char* servicename) {
 	celix_status_t status = CELIX_SUCCESS;
 	char tmpPath[RSA_FILEPATH_LENGTH];
+	int retVal = 0;
 
 	snprintf(tmpPath, RSA_FILEPATH_LENGTH, "%s/%s/%s", P_tmpdir, fwUuid, servicename);
 
-	if (access(tmpPath, F_OK) == 0) {
-		logHelper_log(admin->loghelper, OSGI_LOGSERVICE_DEBUG, "removing shared identifier file
%s", tmpPath);
-		unlink(tmpPath);
+	retVal = unlink(tmpPath);
+
+	if (retVal == 0) {
+		logHelper_log(admin->loghelper, OSGI_LOGSERVICE_DEBUG, "Removed shared identifier file
%s", tmpPath);
 	} else {
-		logHelper_log(admin->loghelper, OSGI_LOGSERVICE_ERROR, "cannot remove shared identifier
file %s", tmpPath);
+		logHelper_log(admin->loghelper, OSGI_LOGSERVICE_ERROR, "Cannot remove shared identifier
file %s", tmpPath);
+		status = CELIX_FILE_IO_EXCEPTION;
 	}
 
 	return status;
@@ -428,14 +431,17 @@ celix_status_t remoteServiceAdmin_removeSharedIdentityFiles(remote_service_admin
 			f_name = (char*) calloc(len, 1);
 
 			if (f_name) {
-				struct stat statbuf;
-
 				snprintf(f_name, len, "%s/%s", tmpDir, p->d_name);
 
-				if (!stat(f_name, &statbuf)) {
-					logHelper_log(admin->loghelper, OSGI_LOGSERVICE_WARNING, "removing shared identifier
file %s (unproper clean-up?)", f_name);
-					retVal = unlink(f_name);
+				retVal = unlink(f_name);
+
+				if(retVal==0){
+					logHelper_log(admin->loghelper, OSGI_LOGSERVICE_WARNING, "Removed shared identifier
file %s (unproper clean-up?)", f_name);
 				}
+				else{
+					logHelper_log(admin->loghelper, OSGI_LOGSERVICE_WARNING, "Unable to remove shared
identifier file %s ", f_name);
+				}
+
 			}
 			free(f_name);
 		}
@@ -684,32 +690,31 @@ celix_status_t remoteServiceAdmin_createOrAttachShm(hash_map_pt ipcSegment,
remo
 		}
 	}
 
-	if(ipc != NULL){
-		if(status == CELIX_SUCCESS){
-			key_t semkey = ftok(semPath, atoi(semFtokId));
-			int semflg = (createIfNotFound == true) ? (0666 | IPC_CREAT) : (0666);
-			int semid = semget(semkey, 3, semflg);
-
-			if (semid != -1) {
-				// only reset semaphores if a create was supposed
-				if ((createIfNotFound == true) && ((semctl(semid, 0, SETVAL, (int) 1) == -1)
|| (semctl(semid, 1, SETVAL, (int) 0) == -1) || (semctl(semid, 2, SETVAL, (int) 0) == -1)))
{
-					logHelper_log(admin->loghelper, OSGI_LOGSERVICE_ERROR, "error while initialize semaphores.");
-				}
+	if(ipc != NULL && status == CELIX_SUCCESS){
 
-				logHelper_log(admin->loghelper, OSGI_LOGSERVICE_DEBUG, "semaphores w/ key %s and id
%i added.", endpointDescription->service, semid);
-				ipc->semId = semid;
+		key_t semkey = ftok(semPath, atoi(semFtokId));
+		int semflg = (createIfNotFound == true) ? (0666 | IPC_CREAT) : (0666);
+		int semid = semget(semkey, 3, semflg);
 
-				hashMap_put(ipcSegment, endpointDescription->service, ipc);
-			} else {
-				logHelper_log(admin->loghelper, OSGI_LOGSERVICE_ERROR, "error getting semaphores.");
-				status = CELIX_BUNDLE_EXCEPTION;
+		if (semid != -1) {
+			// only reset semaphores if a create was supposed
+			if ((createIfNotFound == true) && ((semctl(semid, 0, SETVAL, (int) 1) == -1) ||
(semctl(semid, 1, SETVAL, (int) 0) == -1) || (semctl(semid, 2, SETVAL, (int) 0) == -1))) {
+				logHelper_log(admin->loghelper, OSGI_LOGSERVICE_ERROR, "error while initialize semaphores.");
 			}
-		}
-		else{
-			free(ipc);
+
+			logHelper_log(admin->loghelper, OSGI_LOGSERVICE_DEBUG, "semaphores w/ key %s and id
%i added.", endpointDescription->service, semid);
+			ipc->semId = semid;
+
+			hashMap_put(ipcSegment, endpointDescription->service, ipc);
+		} else {
+			logHelper_log(admin->loghelper, OSGI_LOGSERVICE_ERROR, "error getting semaphores.");
+			status = CELIX_BUNDLE_EXCEPTION;
 		}
 	}
 
+	if(ipc != NULL && status != CELIX_SUCCESS){
+		free(ipc);
+	}
 
 	return status;
 }

http://git-wip-us.apache.org/repos/asf/celix/blob/d813e8b4/remote_services/utils/private/src/civetweb.c
----------------------------------------------------------------------
diff --git a/remote_services/utils/private/src/civetweb.c b/remote_services/utils/private/src/civetweb.c
index b87be74..0639d08 100644
--- a/remote_services/utils/private/src/civetweb.c
+++ b/remote_services/utils/private/src/civetweb.c
@@ -5003,24 +5003,22 @@ static void delete_file(struct mg_connection *conn, const char *path)
         return;
     }
 
-    /* This is an existing file (not a directory).
-       Check if write permission is granted. */
-    if (access(path, W_OK) != 0) {
-        /* File is read only */
-        send_http_error(conn, 403, NULL,
-            "Error: Delete not possible\nDeleting %s is not allowed", path);
-        return;
-    }
-
-    /* Try to delete it. */
+    /* Try to delete path. */
     if (mg_remove(path) == 0) {
-        /* Delete was successful: Return 204 without content. */
-        send_http_error(conn, 204, NULL, "%s", "");
+	/* Delete was successful: Return 204 without content. */
+	send_http_error(conn, 204, NULL, "%s", "");
     } else {
-        /* Delete not successful (file locked). */
-        send_http_error(conn, 423, NULL,
-            "Error: Cannot delete file\nremove(%s): %s", path, strerror(ERRNO));
+	/* Delete not successful (no permissions). */
+	if(ERRNO==EPERM || ERRNO==EACCES){
+		send_http_error(conn, 403, NULL,
+				"Error: Delete not possible\nDeleting %s is not allowed", path);
+	} else {
+		/* Delete not successful (file locked). */
+		send_http_error(conn, 423, NULL,
+				"Error: Cannot delete file\nremove(%s): %s", path, strerror(ERRNO));
+	}
     }
+
 }
 
 static void send_ssi_file(struct mg_connection *, const char *,

http://git-wip-us.apache.org/repos/asf/celix/blob/d813e8b4/shell/private/src/update_command.c
----------------------------------------------------------------------
diff --git a/shell/private/src/update_command.c b/shell/private/src/update_command.c
index 84a5d2f..a6157a8 100644
--- a/shell/private/src/update_command.c
+++ b/shell/private/src/update_command.c
@@ -27,6 +27,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <curl/curl.h>
+#include <sys/stat.h>
 
 #include "array_list.h"
 #include "bundle_context.h"
@@ -79,6 +80,7 @@ celix_status_t updateCommand_download(bundle_context_pt context, char *
url, cha
 	if (curl) {
 		FILE *fp = NULL;
 		snprintf(*inputFile, 13,"updateXXXXXX");
+		umask(0011);
 		int fd = mkstemp(*inputFile);
 		if (fd) {
 		    fp = fopen(*inputFile, "wb+");

http://git-wip-us.apache.org/repos/asf/celix/blob/d813e8b4/utils/private/src/hash_map.c
----------------------------------------------------------------------
diff --git a/utils/private/src/hash_map.c b/utils/private/src/hash_map.c
index ea41e3a..1f78251 100644
--- a/utils/private/src/hash_map.c
+++ b/utils/private/src/hash_map.c
@@ -492,7 +492,7 @@ void hashMapValues_toArray(hash_map_values_pt values, void* *array[],
unsigned i
 	int i = 0;
 	int vsize = hashMapValues_size(values);
 	*size = vsize;
-	*array = malloc(vsize * sizeof(*array));
+	*array = malloc(vsize * sizeof(**array));
 	it = hashMapValues_iterator(values);
 	while(hashMapIterator_hasNext(it) && i<vsize){
 		(*array)[i++] = hashMapIterator_nextValue(it);


Mime
View raw message