crash: change strcmp() to strncmp() 80/55480/2 accepted/tizen/mobile/20151228.063717 accepted/tizen/tv/20151228.063744 accepted/tizen/wearable/20151228.063821 submit/tizen/20151228.041818 submit/tizen_common/20151229.142028 submit/tizen_common/20151229.144031 submit/tizen_common/20151229.154718
authorTaeyoung Kim <ty317.kim@samsung.com>
Thu, 24 Dec 2015 03:04:48 +0000 (12:04 +0900)
committerTaeyoung Kim <ty317.kim@samsung.com>
Mon, 28 Dec 2015 04:17:11 +0000 (13:17 +0900)
- overflow issues can be occurred by strcmp()
  thus strcmp()s are changed to strncmp()

Change-Id: Icc1d3b22bffa56680f6d9b3e54c1661ffe75a8eb
Signed-off-by: Taeyoung Kim <ty317.kim@samsung.com>
src/shared/util.c

index 3797f174ce137cb08a29faf33ce7c9092bc4c861..969a97808e0d8bef429037440af6a919db03d074 100644 (file)
@@ -301,7 +301,7 @@ static int remove_dir_internal(int fd)
                return -1;
        while ((de = readdir(dir))) {
                if (de->d_type == DT_DIR) {
-                       if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, ".."))
+                       if (!strncmp(de->d_name, ".", 2) || !strncmp(de->d_name, "..", 3))
                                continue;
                        subfd = openat(fd, de->d_name, O_RDONLY | O_DIRECTORY);
                        if (subfd < 0) {
@@ -385,6 +385,7 @@ int get_exec_pid(const char *execpath)
        int ret;
        char buf[PATH_MAX];
        char buf2[PATH_MAX];
+       int len;
 
        dp = opendir("/proc");
        if (!dp) {
@@ -392,6 +393,7 @@ int get_exec_pid(const char *execpath)
                return -1;
        }
 
+       len = strlen(execpath) + 1;
        while ((dentry = readdir(dp)) != NULL) {
                if (!isdigit(dentry->d_name[0]))
                        continue;
@@ -410,7 +412,7 @@ int get_exec_pid(const char *execpath)
 
                buf2[ret] = '\0';
 
-               if (!strcmp(buf2, execpath)) {
+               if (!strncmp(buf2, execpath, len)) {
                        closedir(dp);
                        return pid;
                }
@@ -462,7 +464,7 @@ int get_directory_usage(char *path)
                return -1;
        }
        while ((de = readdir(dir))) {
-               if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, ".."))
+               if (!strncmp(de->d_name, ".", 2) || !strncmp(de->d_name, "..", 3))
                        continue;
                if (fstatat(fd, de->d_name, &st, AT_SYMLINK_NOFOLLOW) < 0) {
                        _SE("Failed to fstatat  %s: %s\n", de->d_name, strerror(errno));