fix potential bugs 63/103063/1 accepted/tizen/3.0/common/20161207.195648 accepted/tizen/3.0/ivi/20161207.135606 accepted/tizen/3.0/mobile/20161207.135556 accepted/tizen/3.0/tv/20161207.135421 accepted/tizen/3.0/wearable/20161207.135744 submit/tizen_3.0/20161207.080751
authorgreatim <jaewon81.lim@samsung.com>
Wed, 7 Dec 2016 06:46:39 +0000 (15:46 +0900)
committergreatim <jaewon81.lim@samsung.com>
Wed, 7 Dec 2016 06:46:39 +0000 (15:46 +0900)
fix potential bugs
1. NO_LOCK.STAT for errno in log.h
2. NULL_AFTER_DEREF by asprintf

Change-Id: I3470fd2d8d0b86c3417add3657a38b45d1222626
Signed-off-by: greatim <jaewon81.lim@samsung.com>
src/log.h
src/services.c

index 3d55707..f237e15 100644 (file)
--- a/src/log.h
+++ b/src/log.h
@@ -73,27 +73,26 @@ void sdb_qemu_trace(const char* fmt, ...);
 #  define  D(...)                                      \
         do {                                           \
             if (SDB_TRACING) {                         \
-                int save_errno = errno;                \
                 sdb_mutex_lock(&D_lock);               \
+                int save_errno = errno;                \
                 fprintf(stderr, "%s::%s():",           \
                         __FILE__, __FUNCTION__);       \
                 errno = save_errno;                    \
                 fprintf(stderr, __VA_ARGS__ );         \
                 fflush(stderr);                        \
-                sdb_mutex_unlock(&D_lock);             \
                 errno = save_errno;                    \
+                sdb_mutex_unlock(&D_lock);             \
            }                                           \
         } while (0)
 #  define  DR(...)                                     \
         do {                                           \
             if (SDB_TRACING) {                         \
-                int save_errno = errno;                \
                 sdb_mutex_lock(&D_lock);               \
-                errno = save_errno;                    \
+                int save_errno = errno;                \
                 fprintf(stderr, __VA_ARGS__ );         \
                 fflush(stderr);                        \
-                sdb_mutex_unlock(&D_lock);             \
                 errno = save_errno;                    \
+                sdb_mutex_unlock(&D_lock);             \
            }                                           \
         } while (0)
 #else
index d2d1500..4395a1d 100644 (file)
@@ -338,12 +338,13 @@ void inoti_service(int fd, void *arg)
                 if (event->mask & IN_CREATE) {
                     if (!(event->mask & IN_ISDIR)) {
                         char *cspath = NULL;
-                        int len = asprintf(&cspath, "%s/%s", CS_PATH,
-                                event->name);
-                        D( "The file %s was created.\n", cspath);
-                        writex(fd, cspath, len);
-                        if (cspath != NULL) {
+                        int len = asprintf(&cspath, "%s/%s", CS_PATH, event->name);
+                        if (len >= 0) {
+                            D( "The file %s was created.\n", cspath);
+                            writex(fd, cspath, len);
                             free(cspath);
+                        } else {
+                            D( "asprintf was failed\n" );
                         }
                     }
                 }