[FIX] fix strlen error in kernel space.
authorKudrjavtsev Nickita <n.kudryavcev@samsung.com>
Mon, 1 Apr 2013 18:44:45 +0000 (22:44 +0400)
committerKudrjavtsev Nickita <n.kudryavcev@samsung.com>
Mon, 1 Apr 2013 18:44:45 +0000 (22:44 +0400)
When lib path is zeroed daemon was crushed.

driver/error_storage.c
driver/error_storage.h
driver/storage.c

index ee9dfce..427a8a4 100644 (file)
@@ -43,28 +43,44 @@ static unsigned int get_max_error_buffer_size(void)
        return (unsigned int)MAX_ERROR_BUF_PATH;
 }
 
-int update_errno_buffer(const char *buffer)
+int update_errno_buffer(char *buffer, const unsigned int type)
 {
         unsigned int size;
+       char* tmp_buffer;
+       int return_value = 0;
 
         if (last_error == NULL) {
                 if (create_errno_buffer() != 0)
                         return -1;
         }
 
-        size = strlen(buffer);
+       if (buffer == NULL) {
+               if (type == IS_LIB) {
+                       tmp_buffer = "Unknown lib path. Zero pointer";
+               } else if(type == IS_APP) {
+                       tmp_buffer = "Unknown app path. Zero pointer";
+               } else {
+                       tmp_buffer = "Undefined instrumentation type. Zero pointer";
+               }
+
+               return_value = -1;
+       } else {
+               tmp_buffer = buffer;
+       }
+
+        size = strlen(tmp_buffer);
 
         if (last_error->size + size + 2 >= get_max_error_buffer_size()) {
                 return -1;
        }
 
-        strncat((char*)(last_error->buffer), buffer, size);
+        strncat((char*)(last_error->buffer), tmp_buffer, size);
 
         last_error->size += size + 1;
         last_error->buffer[last_error->size - 1] = ',';
         last_error->buffer[last_error->size] = '\0';
 
-        return 0;
+        return return_value;
 }
 
 static void delete_errno_buffer(void)
index d32b4f1..1f404a6 100644 (file)
@@ -1,6 +1,8 @@
 #define MAX_ERROR_BUF_PATH 256
+#define IS_APP  0
+#define IS_LIB  1
 
 // copy error buffer from kernelspace to userspace
 int get_last_error(void* u_addr);
 int has_last_error(void);
-int update_errno_buffer(const char *buffer);
+int update_errno_buffer(char *buffer, const unsigned int type);
index 4338115..8be3179 100644 (file)
@@ -698,7 +698,7 @@ int link_bundle(void)
                if (strcmp(us_proc_info.path, "*")) {
                        us_proc_info.m_f_dentry = dentry_by_path(us_proc_info.path);
                        if (us_proc_info.m_f_dentry == NULL) {
-                               update_errno_buffer(us_proc_info.path);
+                               update_errno_buffer(us_proc_info.path, IS_APP);
                                return -1;
                        }
                }
@@ -768,7 +768,9 @@ int link_bundle(void)
                                {
                                        if (strcmp(d_lib->path_dyn, "") == 0) {
                                                EPRINTF("Cannot find path for lib %s!", d_lib->path);
-                                               update_errno_buffer(d_lib->path);
+                                               if (update_errno_buffer(d_lib->path, IS_LIB) == -1) {
+                                                       return -1;
+                                               }
                                                /* Just skip all the IPs and go to next lib */
                                                p += d_lib->ips_count * 3 * sizeof(u_int32_t);
                                                d_lib->ips_count = 0;
@@ -788,7 +790,9 @@ int link_bundle(void)
                        d_lib->m_f_dentry = dentry_by_path(d_lib->path);
                        if (d_lib->m_f_dentry == NULL) {
                                EPRINTF ("failed to lookup dentry for path %s!", d_lib->path);
-                               update_errno_buffer(d_lib->path);
+                               if (update_errno_buffer(d_lib->path, IS_LIB) == -1) {
+                                       return -1;
+                               }
                                /* Just skip all the IPs and go to next lib */
                                p += d_lib->ips_count * 3 * sizeof(u_int32_t);
                                d_lib->ips_count = 0;