Gentoo Logo
Gentoo Spaceship




Note: Due to technical difficulties, the Archives are currently not up to date. GMANE provides an alternative service for most mailing lists.
c.f. bug 424647
List Archive: gentoo-commits
Navigation:
Lists: gentoo-commits: < Prev By Thread Next > < Prev By Date Next >
Headers:
To: gentoo-commits@g.o
From: "Anthony G. Basile" <blueness@g.o>
Subject: proj/elfix:master commit in: src/, scripts/
Date: Thu, 20 Oct 2011 18:12:39 +0000 (UTC)
commit:     1efd8ec798c7ae81e19d1b781fa119e07552d538
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Thu Oct 20 18:12:31 2011 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Thu Oct 20 18:12:31 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=1efd8ec7

src/paxctl-ng.c: clean up error handling

---
 scripts/paxmodule.c |   50 ++++++------------------------------------
 src/paxctl-ng.c     |   60 +++++++++-----------------------------------------
 2 files changed, 18 insertions(+), 92 deletions(-)

diff --git a/scripts/paxmodule.c b/scripts/paxmodule.c
index c5a7aa6..ed74430 100644
--- a/scripts/paxmodule.c
+++ b/scripts/paxmodule.c
@@ -65,9 +65,7 @@ get_pt_flags(int fd)
 	GElf_Phdr phdr;
 	size_t i, phnum;
 
-	uint16_t pt_flags;
-
-	pt_flags = UINT16_MAX;
+	uint16_t pt_flags = UINT16_MAX;
 
 	if(elf_version(EV_CURRENT) == EV_NONE)
 	{
@@ -93,7 +91,10 @@ get_pt_flags(int fd)
 	for(i=0; i<phnum; i++)
 	{
 		if(gelf_getphdr(elf, i, &phdr) != &phdr)
+		{
 			PyErr_SetString(PaxError, "get_pt_flags: gelf_getphdr() failed: could not get phdr.");
+			return pt_flags;
+		}
 
 		if(phdr.p_type == PT_PAX_FLAGS)
 			pt_flags = phdr.p_flags;
@@ -108,38 +109,9 @@ get_pt_flags(int fd)
 uint16_t
 get_xt_flags(int fd)
 {
-	uint16_t xt_flags;
-
-	xt_flags = UINT16_MAX;
-
-	if(fgetxattr(fd, PAX_NAMESPACE, &xt_flags, sizeof(uint16_t)) == -1)
-	{
-		/*
-		// ERANGE  = xattrs supported, PAX_NAMESPACE present, but wrong size
-		// ENOATTR = xattrs supported, PAX_NAMESPACE not present
-		if(errno == ERANGE || errno == ENOATTR)
-		{
-			//XT_PAX: not present or corrupted
+	uint16_t xt_flags = UINT16_MAX;
 
-			//BEGIN: create flags
-			PyErr_SetString(PaxError, "XT_PAX: creating/repairing flags");
-			xt_flags = PF_NOEMUTRAMP | PF_NORANDEXEC;
-			if(fsetxattr(fd, PAX_NAMESPACE, &xt_flags, sizeof(uint16_t), 0) == -1)
-			{
-				xt_flags = UINT16_MAX;
-				if(errno == ENOSPC || errno == EDQUOT)
-					PyErr_SetString(PaxError, "XT_PAX: access error");
-				if(errno == ENOTSUP)
-					PyErr_SetString(PaxError, "XT_PAX: not supported");
-			}
-			// END: create flags
-		}
-
-		// ENOTSUP = xattrs not supported
-		if(errno == ENOTSUP)
-			PyErr_SetString(PaxError, "XT_PAX: not supported\n");
-		*/
-	}
+	fgetxattr(fd, PAX_NAMESPACE, &xt_flags, sizeof(uint16_t));
 
 	return xt_flags;
 }
@@ -269,15 +241,7 @@ set_pt_flags(int fd, uint16_t pt_flags)
 void
 set_xt_flags(int fd, uint16_t xt_flags)
 {
-	if(fsetxattr(fd, PAX_NAMESPACE, &xt_flags, sizeof(uint16_t), 0) == -1)
-	{
-		/*
-		if(errno == ENOSPC || errno == EDQUOT)
-			 PyErr_SetString(PaxError, "XT_PAX: access error");
-		if(errno == ENOTSUP)
-			 PyErr_SetString(PaxError, "XT_PAX: not supported\n");
-		*/
-	}
+	fsetxattr(fd, PAX_NAMESPACE, &xt_flags, sizeof(uint16_t), 0);
 }
 
 

diff --git a/src/paxctl-ng.c b/src/paxctl-ng.c
index aaeadaf..8d9bf55 100644
--- a/src/paxctl-ng.c
+++ b/src/paxctl-ng.c
@@ -163,27 +163,18 @@ get_pt_flags(int fd)
 	GElf_Phdr phdr;
 	size_t i, phnum;
 
-	uint16_t pt_flags;
-
-	pt_flags = UINT16_MAX;
+	uint16_t pt_flags = UINT16_MAX;
 
 	if(elf_version(EV_CURRENT) == EV_NONE)
-	{
 		error(EXIT_FAILURE, 0, "Library out of date.");
-		return;
-	}
 
 	if((elf = elf_begin(fd, ELF_C_READ_MMAP, NULL)) == NULL)
-	{
 		error(EXIT_FAILURE, 0, "elf_begin() fail: %s", elf_errmsg(elf_errno()));
-		return;
-	}
 
 	if(elf_kind(elf) != ELF_K_ELF)
 	{
 		elf_end(elf);
 		error(EXIT_FAILURE, 0, "elf_kind() fail: this is not an elf file.");
-		return;
 	}
 
 	elf_getphdrnum(elf, &phnum);
@@ -191,14 +182,16 @@ get_pt_flags(int fd)
 	for(i=0; i<phnum; i++)
 	{
 		if(gelf_getphdr(elf, i, &phdr) != &phdr)
+		{
+			elf_end(elf);
 			error(EXIT_FAILURE, 0, "gelf_getphdr(): %s", elf_errmsg(elf_errno()));
+		}
 
 		if(phdr.p_type == PT_PAX_FLAGS)
 			pt_flags = phdr.p_flags;
 	}
 
 	elf_end(elf);
-
 	return pt_flags;
 }
 
@@ -206,32 +199,16 @@ get_pt_flags(int fd)
 uint16_t
 get_xt_flags(int fd)
 {
-	uint16_t xt_flags;
-
-	xt_flags = UINT16_MAX;
+	uint16_t xt_flags = UINT16_MAX;
 
 	if(fgetxattr(fd, PAX_NAMESPACE, &xt_flags, sizeof(uint16_t)) == -1)
 	{
-		// ERANGE  = xattrs supported, PAX_NAMESPACE present, but wrong size
-		// ENOATTR = xattrs supported, PAX_NAMESPACE not present
-		if(errno == ERANGE || errno == ENOATTR)
-		{
-			printf("XT_PAX: not present or corrupted\n");
-			/*
-			printf("XT_PAX: creating/repairing flags\n");
-			xt_flags = PF_NOEMUTRAMP | PF_NORANDEXEC;
-			if(fsetxattr(fd, PAX_NAMESPACE, &xt_flags, sizeof(uint16_t), 0) == -1)
-			{
-				xt_flags = UINT16_MAX;
-				if(errno == ENOSPC || errno == EDQUOT)
-					printf("XT_PAX: access error\n");
-				if(errno == ENOTSUP)
-					printf("XT_PAX: not supported\n");
-			}
-			*/
-		}
+		if(errno == ERANGE )
+			printf("XT_PAX: corrupted\n");
+
+		if( errno == ENOATTR)
+			printf("XT_PAX: not present\n");
 
-		// ENOTSUP = xattrs not supported
 		if(errno == ENOTSUP)
 			printf("XT_PAX: not supported\n");
 	}
@@ -271,9 +248,7 @@ print_flags(int fd)
 
 	flags = get_pt_flags(fd);
 	if( flags == UINT16_MAX )
-	{
 		printf("PT_PAX: not found\n");
-	}
 	else
 	{
 		memset(buf, 0, BUF_SIZE);
@@ -283,9 +258,7 @@ print_flags(int fd)
 
 	flags = get_xt_flags(fd);
 	if( flags == UINT16_MAX )
-	{
 		printf("XT_PAX: not found\n");
-	}
 	else
 	{
 		memset(buf, 0, BUF_SIZE);
@@ -413,22 +386,15 @@ set_pt_flags(int fd, uint16_t pt_flags)
 	size_t i, phnum;
 
 	if(elf_version(EV_CURRENT) == EV_NONE)
-	{
 		error(EXIT_FAILURE, 0, "Library out of date.");
-		return;
-	}
 
 	if((elf = elf_begin(fd, ELF_C_RDWR_MMAP, NULL)) == NULL)
-	{
 		error(EXIT_FAILURE, 0, "elf_begin() fail: %s", elf_errmsg(elf_errno()));
-		return;
 	}
-
 	if(elf_kind(elf) != ELF_K_ELF)
 	{
 		elf_end(elf);
 		error(EXIT_FAILURE, 0, "elf_kind() fail: this is not an elf file.");
-		return;
 	}
 
 	elf_getphdrnum(elf, &phnum);
@@ -439,7 +405,6 @@ set_pt_flags(int fd, uint16_t pt_flags)
 		{
 			elf_end(elf);
 			error(EXIT_FAILURE, 0, "gelf_getphdr(): %s", elf_errmsg(elf_errno()));
-			return;
 		}
 
 		if(phdr.p_type == PT_PAX_FLAGS)
@@ -450,7 +415,6 @@ set_pt_flags(int fd, uint16_t pt_flags)
 			{
 				elf_end(elf);
 				error(EXIT_FAILURE, 0, "gelf_update_phdr(): %s", elf_errmsg(elf_errno()));
-				return;
 			}
 		}
 	}
@@ -465,7 +429,7 @@ set_xt_flags(int fd, uint16_t xt_flags)
 	if(fsetxattr(fd, PAX_NAMESPACE, &xt_flags, sizeof(uint16_t), 0) == -1)
 	{
 		if(errno == ENOSPC || errno == EDQUOT)
-			printf("XT_PAX: access error\n");
+			printf("XT_PAX: insufficient space\n");
 		if(errno == ENOTSUP)
 			printf("XT_PAX: not supported\n");
 	}
@@ -501,8 +465,6 @@ main( int argc, char *argv[])
 	uint16_t flags;
 	int view_flags;
 
-	Elf *elf;
-
 	f_name = parse_cmd_args(argc, argv, &flags, &view_flags);
 
 	if((fd = open(f_name, O_RDWR)) < 0)


Navigation:
Lists: gentoo-commits: < Prev By Thread Next > < Prev By Date Next >
Previous by thread:
proj/elfix:master commit in: src/, scripts/
Next by thread:
gentoo-x86 commit in dev-embedded/libftdi: libftdi-0.19.ebuild ChangeLog
Previous by date:
gentoo-x86 commit in sys-devel/make: ChangeLog make-3.82-r1.ebuild
Next by date:
gentoo-x86 commit in net-irc/ii: ii-1.6.ebuild ChangeLog ii-1.4.ebuild


Updated Jun 26, 2012

Summary: Archive of the gentoo-commits mailing list.

Donate to support our development efforts.

Copyright 2001-2013 Gentoo Foundation, Inc. Questions, Comments? Contact us.