tbm_drm_helper: fix Svace TAINTED_INT defect 32/132432/1
authorYoungJun Cho <yj44.cho@samsung.com>
Mon, 5 Jun 2017 06:42:00 +0000 (15:42 +0900)
committerYoungJun Cho <yj44.cho@samsung.com>
Mon, 5 Jun 2017 06:42:00 +0000 (15:42 +0900)
This patch fixes Svace TAINTED_INT defect.

Change-Id: I88e06bbdb020ee2cae621decb1560d6cb1e4d95a
Signed-off-by: YoungJun Cho <yj44.cho@samsung.com>
src/tbm_bufmgr.c
src/tbm_bufmgr_int.h
src/tbm_drm_helper_client.c
src/tbm_drm_helper_server.c

index 7d6f36a..bef7660 100644 (file)
@@ -36,6 +36,8 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "tbm_bufmgr_backend.h"
 #include "list.h"
 
+#include <sys/resource.h>
+
 #ifdef DEBUG
 int bDebug;
 #endif
@@ -1710,3 +1712,14 @@ tbm_bufmgr_bind_native_display(tbm_bufmgr bufmgr, void *NativeDisplay)
        return 1;
 }
 /* LCOV_EXCL_STOP */
+
+int tbm_bufmgr_get_fd_limit(void)
+{
+       struct rlimit lim;
+
+       if (getrlimit(RLIMIT_NOFILE, &lim))
+               return 1024;
+
+       return (int)lim.rlim_cur;
+}
+
index b6fcf7d..57b73bc 100644 (file)
@@ -336,4 +336,5 @@ tbm_user_data *user_data_create(unsigned long key,
                                tbm_data_free data_free_func);
 void user_data_delete(tbm_user_data *user_data);
 
+int tbm_bufmgr_get_fd_limit(void);
 #endif                                                 /* _TBM_BUFMGR_INT_H_ */
index 10828be..7980e1e 100644 (file)
@@ -247,8 +247,9 @@ tbm_drm_helper_get_fd(void)
                TBM_LOG_E("%ld less than INT_MIN\n", sl);
                return -1;
        } else {
+               int fd_max = tbm_bufmgr_get_fd_limit();
                fd = (int)sl;
-               if (fd < 0) {
+               if (fd < 0 || fd > fd_max) {
                        TBM_LOG_E("%d out of fd range\n", fd);
                        return -1;
                }
index baa18d1..c96d6a7 100644 (file)
@@ -325,8 +325,9 @@ tbm_drm_helper_get_master_fd(void)
                TBM_LOG_E("%ld less than INT_MIN\n", sl);
                return -1;
        } else {
+               int fd_max = tbm_bufmgr_get_fd_limit();
                fd = (int)sl;
-               if (fd < 0) {
+               if (fd < 0 || fd > fd_max) {
                        TBM_LOG_E("%d out of fd range\n", fd);
                        return -1;
                }