Fix: handle sysconf errors
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 21 Feb 2014 16:01:01 +0000 (11:01 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 21 Feb 2014 16:01:01 +0000 (11:01 -0500)
CID 1021261 (#1 of 1): Argument cannot be negative (NEGATIVE_RETURNS)10.
negative_returns: "sysconf(30)" is passed to a parameter that cannot be
negative.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
liblttng-ust/lttng-ust-comm.c
tests/ust-basic-tracing/ust-basic-tracing.c
tests/ust-multi-test/ust-multi-test.c

index 74d805aefb06c23e42c048498cf2861183d29dfd..77cde295b7beae3c0a47a99fcbe486532e3680c3 100644 (file)
@@ -819,9 +819,14 @@ void cleanup_sock_info(struct sock_info *sock_info, int exiting)
                sock_info->notify_socket = -1;
        }
        if (sock_info->wait_shm_mmap) {
-               ret = munmap(sock_info->wait_shm_mmap, sysconf(_SC_PAGE_SIZE));
-               if (ret) {
-                       ERR("Error unmapping wait shm");
+               long page_size;
+
+               page_size = sysconf(_SC_PAGE_SIZE);
+               if (page_size > 0) {
+                       ret = munmap(sock_info->wait_shm_mmap, page_size);
+                       if (ret) {
+                               ERR("Error unmapping wait shm");
+                       }
                }
                sock_info->wait_shm_mmap = NULL;
        }
@@ -994,15 +999,20 @@ error_close:
 static
 char *get_map_shm(struct sock_info *sock_info)
 {
-       size_t mmap_size = sysconf(_SC_PAGE_SIZE);
+       long page_size;
        int wait_shm_fd, ret;
        char *wait_shm_mmap;
 
-       wait_shm_fd = get_wait_shm(sock_info, mmap_size);
+       page_size = sysconf(_SC_PAGE_SIZE);
+       if (page_size < 0) {
+               goto error;
+       }
+
+       wait_shm_fd = get_wait_shm(sock_info, page_size);
        if (wait_shm_fd < 0) {
                goto error;
        }
-       wait_shm_mmap = mmap(NULL, mmap_size, PROT_READ,
+       wait_shm_mmap = mmap(NULL, page_size, PROT_READ,
                  MAP_SHARED, wait_shm_fd, 0);
        /* close shm fd immediately after taking the mmap reference */
        ret = close(wait_shm_fd);
index 18fb08789f637b58ac06b6b04acf84bf9cc2455e..7bfeb5bc540f7037a15a8a61976f0a2ebbfcc2ef 100644 (file)
@@ -642,11 +642,15 @@ error:
 
 int update_futex(int fd, int active)
 {
-       size_t mmap_size = sysconf(_SC_PAGE_SIZE);
+       long page_size;
        char *wait_shm_mmap;
        int ret;
 
-       wait_shm_mmap = mmap(NULL, mmap_size, PROT_READ | PROT_WRITE,
+       page_size = sysconf(_SC_PAGE_SIZE);
+       if (page_size < 0) {
+               goto error;
+       }
+       wait_shm_mmap = mmap(NULL, page_size, PROT_READ | PROT_WRITE,
                  MAP_SHARED, fd, 0);
        if (wait_shm_mmap == MAP_FAILED) {
                perror("mmap");
@@ -660,7 +664,7 @@ int update_futex(int fd, int active)
        } else {
                uatomic_set((int32_t *) wait_shm_mmap, 0);
        }
-       ret = munmap(wait_shm_mmap, mmap_size);
+       ret = munmap(wait_shm_mmap, page_size);
        if (ret) {
                perror("Error unmapping wait shm");
                goto error;
index 6f277a2176f28e016be2588c875ea8065e1e7829..7771154014376b79b92ae063601355fd3113ee51 100644 (file)
@@ -638,11 +638,15 @@ error:
 
 int update_futex(int fd, int active)
 {
-       size_t mmap_size = sysconf(_SC_PAGE_SIZE);
+       long page_size;
        char *wait_shm_mmap;
        int ret;
 
-       wait_shm_mmap = mmap(NULL, mmap_size, PROT_READ | PROT_WRITE,
+       page_size = sysconf(_SC_PAGE_SIZE);
+       if (page_size < 0) {
+               goto error;
+       }
+       wait_shm_mmap = mmap(NULL, page_size, PROT_READ | PROT_WRITE,
                  MAP_SHARED, fd, 0);
        if (wait_shm_mmap == MAP_FAILED) {
                perror("mmap");
@@ -656,7 +660,7 @@ int update_futex(int fd, int active)
        } else {
                uatomic_set((int32_t *) wait_shm_mmap, 0);
        }
-       ret = munmap(wait_shm_mmap, mmap_size);
+       ret = munmap(wait_shm_mmap, page_size);
        if (ret) {
                perror("Error unmapping wait shm");
                goto error;
This page took 0.028115 seconds and 4 git commands to generate.