Patchwork [24/25] e4defrag: Check error return of sysconf()

login
register
mail settings
Submitter Eric Sandeen
Date Sept. 16, 2011, 8:49 p.m.
Message ID <1316206180-6375-25-git-send-email-sandeen@redhat.com>
Download mbox | patch
Permalink /patch/115038/
State Accepted
Headers show

Comments

Eric Sandeen - Sept. 16, 2011, 8:49 p.m.
In theory sysconf() can fail, so check for an error return.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---
 misc/e4defrag.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
Theodore Ts'o - Sept. 16, 2011, 11:57 p.m.
On Fri, Sep 16, 2011 at 03:49:39PM -0500, Eric Sandeen wrote:
> In theory sysconf() can fail, so check for an error return.
> 
> Signed-off-by: Eric Sandeen <sandeen@redhat.com>

Applied, thanks.

					- Ted
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch

diff --git a/misc/e4defrag.c b/misc/e4defrag.c
index eea3057..4ade180 100644
--- a/misc/e4defrag.c
+++ b/misc/e4defrag.c
@@ -399,13 +399,16 @@  static int calc_entry_counts(const char *file EXT2FS_ATTR((unused)),
 static int page_in_core(int fd, struct move_extent defrag_data,
 			unsigned char **vec, unsigned int *page_num)
 {
-	long	pagesize = sysconf(_SC_PAGESIZE);
+	long	pagesize;
 	void	*page = NULL;
 	loff_t	offset, end_offset, length;
 
 	if (vec == NULL || *vec != NULL)
 		return -1;
 
+ 	pagesize = sysconf(_SC_PAGESIZE);
+	if (pagesize < 0)
+		return -1;
 	/* In mmap, offset should be a multiple of the page size */
 	offset = (loff_t)defrag_data.orig_start * block_size;
 	length = (loff_t)defrag_data.len * block_size;