Calling sysconf(_SC_PAGESIZE) could return -1
on error. This patch adds check after calling
sysconf() instead of directly using the value
Test-Parameters: trivial testlist=sanity-flr
CoverityID: 397578 ("Argument cannot be negative")
CoverityID: 397246 ("Argument cannot be negative")
CoverityID: 397320 ("Argument cannot be negative")
CoverityID: 397671 ("Argument cannot be negative")
CoverityID: 397826 ("Argument cannot be negative")
CoverityID: 397898 ("Argument cannot be negative")
CoverityID: 397917 ("Argument cannot be negative")
CoverityID: 399702 ("Argument cannot be negative")
Fixes:
0561c144 (LU-13397 lfs: mirror extend/copy keeps sparseness)
Fixes:
a5905b2a (LU-11245 flr: lfs mirror dump command)
Fixes:
f1daa8fc (LU-10287 flr: lfs mirror verify command)
Fixes:
0e5c12ac (LU-10916 lfs: improve lfs mirror resync)
Fixes:
5d7c4fa6 (LU-9771 flr: mirror read and write)
Fixes:
5999c0b8 (LU-9771 flr: resync support and test tool)
Fixes:
9b44cf70 (LU-13224 utils: expose llapi_param* functions)
Signed-off-by: Arshad Hussain <arshad.hussain@aeoncomputing.com>
Change-Id: I19d13528f63d4586a17aaa9d15313872f8c40c94
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/53693
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Timothy Day <timday@amazon.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
void *buf = NULL;
off_t pos = 0;
off_t data_end = 0;
- size_t page_size = sysconf(_SC_PAGESIZE);
+ size_t page_size;
bool sparse;
int rc;
size_t write_bytes = 0;
buf_size = (bandwidth_bytes_sec + stripe_size - 1) &
~(stripe_size - 1);
+ page_size = sysconf(_SC_PAGESIZE);
+ if (page_size < 0) {
+ rc = -errno;
+ return rc;
+ }
+
/* Use a page-aligned buffer for direct I/O */
rc = posix_memalign(&buf, page_size, buf_size);
if (rc != 0)
int c;
void *buf;
const size_t buflen = 4 << 20;
+ size_t page_size;
off_t pos;
struct option long_opts[] = {
{ .val = 'h', .name = "help", .has_arg = no_argument },
outfd = STDOUT_FILENO;
}
+ page_size = sysconf(_SC_PAGESIZE);
+ if (page_size < 0) {
+ rc = -errno;
+ goto close_fd;
+ }
+
/* allocate buffer */
- rc = posix_memalign(&buf, sysconf(_SC_PAGESIZE), buflen);
+ rc = posix_memalign(&buf, page_size, buflen);
if (rc) {
fprintf(stderr, "%s %s: posix_memalign returns %d\n",
progname, argv[0], rc);
{
const size_t buflen = 4 * 1024 * 1024; /* 4M */
void *buf;
- size_t page_size = sysconf(_SC_PAGESIZE);
+ size_t page_size;
ssize_t bytes_read;
ssize_t bytes_done;
size_t count;
if (file_size == 0)
return 0;
+ page_size = sysconf(_SC_PAGESIZE);
+ if (page_size < 0) {
+ rc = -errno;
+ return rc;
+ }
+
rc = posix_memalign(&buf, page_size, buflen);
if (rc) /* error code is returned directly */
return -rc;
unsigned long stats_interval_sec,
unsigned long bandwidth_bytes_sec)
{
- size_t page_size = sysconf(_SC_PAGESIZE);
size_t buflen = 64 << 20; /* 64M */
+ size_t page_size;
void *buf;
uint64_t pos = start;
uint64_t data_off = pos, data_end = pos;
/* limit transfer size to what can be sent in one second */
if (bandwidth_bytes_sec && bandwidth_bytes_sec < buflen)
buflen = (bandwidth_bytes_sec + ONE_MB - 1) & ~(ONE_MB - 1);
+
+ page_size = sysconf(_SC_PAGESIZE);
+ if (page_size < 0) {
+ rc = -errno;
+ return rc;
+ }
+
rc = posix_memalign(&buf, page_size, buflen);
if (rc)
return -rc;
ssize_t llapi_mirror_read(int fd, unsigned int id, void *buf, size_t count,
off_t pos)
{
- size_t page_size = sysconf(_SC_PAGESIZE);
ssize_t result = 0;
+ size_t page_size;
int rc;
+ page_size = sysconf(_SC_PAGESIZE);
+ if (page_size < 0) {
+ rc = -errno;
+ return rc;
+ }
+
rc = llapi_mirror_set(fd, id);
if (rc < 0)
return rc;
ssize_t llapi_mirror_write(int fd, unsigned int id, const void *buf,
size_t count, off_t pos)
{
- size_t page_size = sysconf(_SC_PAGESIZE);
ssize_t result = 0;
+ size_t page_size;
int rc;
+ page_size = sysconf(_SC_PAGESIZE);
+ if (page_size < 0)
+ return -EINVAL;
+
if (((unsigned long)buf & (page_size - 1)) || pos & (page_size - 1))
return -EINVAL;
void *buf;
off_t pos = 0;
off_t data_end = 0;
- size_t page_size = sysconf(_SC_PAGESIZE);
+ size_t page_size;
ssize_t result = 0;
bool eof = false;
bool sparse;
if (!count)
return 0;
+ page_size = sysconf(_SC_PAGESIZE);
+ if (page_size < 0) {
+ rc = -errno;
+ return rc;
+ }
+
rc = posix_memalign(&buf, page_size, buflen);
if (rc) /* error code is returned directly */
return -rc;
size_t count)
{
const size_t buflen = 4 * 1024 * 1024; /* 4M */
- void *buf;
- size_t page_size = sysconf(_SC_PAGESIZE);
ssize_t result = 0;
+ size_t page_size;
+ void *buf;
int rc;
if (!count)
return 0;
+ page_size = sysconf(_SC_PAGESIZE);
+ if (page_size < 0)
+ return -EINVAL;
+
if (pos & (page_size - 1) || !dst)
return -EINVAL;
*/
static int bytes_remaining(int fd, size_t *file_size)
{
- int rc = 0;
size_t bytes_read = 0;
- long page_size = sysconf(_SC_PAGESIZE);
+ long page_size;
char *temp_buf;
+ int rc = 0;
+
+ page_size = sysconf(_SC_PAGESIZE);
+ if (page_size < 0)
+ return -EINVAL;
temp_buf = malloc(page_size);
if (temp_buf == NULL)
static
int copy_file_expandable(const char *path, char **buf, size_t *file_size)
{
- long page_size = sysconf(_SC_PAGESIZE);
- int rc = 0;
+ long page_size;
char *temp_buf;
- int fd;
+ int rc = 0, fd;
FILE *fp;
+ page_size = sysconf(_SC_PAGESIZE);
+ if (page_size < 0) {
+ rc = -errno;
+ goto out;
+ }
+
fp = open_memstream(buf, file_size);
if (fp == NULL) {
rc = -errno;