Fix: Another instance of indexing array with negative index 43/190543/1
authorKarol Lewandowski <k.lewandowsk@samsung.com>
Wed, 3 Oct 2018 13:43:16 +0000 (15:43 +0200)
committerKarol Lewandowski <k.lewandowsk@samsung.com>
Wed, 3 Oct 2018 13:45:32 +0000 (15:45 +0200)
Issue reported by Coverity.

Change-Id: Ida7f3106d650f48d5fff7e976f1bbc0df0fdc308

src/shared/util.c

index e6a2cff..b83dbaa 100644 (file)
@@ -768,12 +768,12 @@ char* get_exe_path(pid_t pid)
                "/proc/%d/exe", pid);
 
        ssize_t ret = readlink(exe_link, buffer, sizeof(buffer) - 1);
-       buffer[ret] = '\0';
 
        if (ret <= 0) {
                _E("Failed to read link %s: %m", exe_link);
                return NULL;
        }
+       buffer[ret] = '\0';
 
        if (access(buffer, F_OK) == -1) {
                _E("Invalid path %s", buffer);