Whamcloud - gitweb
LU-17000 utils: Add check after calling sysconf(_SC_PAGESIZE)
[fs/lustre-release.git] / lustre / utils / liblustreapi_param.c
index a027850..49b0773 100644 (file)
@@ -202,10 +202,14 @@ int llapi_param_get_paths(const char *pattern, glob_t *paths)
  */
 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)
@@ -252,12 +256,17 @@ static int required_size(const char *path, size_t *file_size)
 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;
@@ -505,8 +514,8 @@ static int print_out_devices(yaml_parser_t *reply, enum lctl_param_flags flags)
        return rc;
 }
 
-int lcfg_param_get_yaml(yaml_parser_t *reply, struct nl_sock *sk,
-                       int version, char *pattern)
+static int lcfg_param_get_yaml(yaml_parser_t *reply, struct nl_sock *sk,
+                              int version, char *pattern)
 {
        char source[PATH_MAX / 2], group[GENL_NAMSIZ + 1];
        char *family = "lustre", *tmp;