This patch fixes Svace TAINTED_INT defect.
Change-Id: I88e06bbdb020ee2cae621decb1560d6cb1e4d95a
Signed-off-by: YoungJun Cho <yj44.cho@samsung.com>
#include "tbm_bufmgr_backend.h"
#include "list.h"
+#include <sys/resource.h>
+
#ifdef DEBUG
int bDebug;
#endif
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;
+}
+
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_ */
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;
}
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;
}