public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Anthony G. Basile" <blueness@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/elfix:master commit in: scripts/
Date: Thu,  6 Oct 2011 04:19:13 +0000 (UTC)	[thread overview]
Message-ID: <4e8f465fd70faffada1f99f0096c269080fa967a.blueness@gentoo> (raw)

commit:     4e8f465fd70faffada1f99f0096c269080fa967a
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Thu Oct  6 04:19:08 2011 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Thu Oct  6 04:19:08 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=4e8f465f

scripts/paxmodule.c: return pax flags as string

---
 scripts/paxmodule.c |   46 ++++++++++++++++++++++++----------------------
 1 files changed, 24 insertions(+), 22 deletions(-)

diff --git a/scripts/paxmodule.c b/scripts/paxmodule.c
index 1b3e1eb..927bb50 100644
--- a/scripts/paxmodule.c
+++ b/scripts/paxmodule.c
@@ -54,17 +54,16 @@ pax_getflags(PyObject *self, PyObject *args)
 	int fd, sts;
 	Elf *elf;
 
+	char pax_buf[BUF_SIZE];
+
 	GElf_Ehdr ehdr;
-	char ei_buf[BUF_SIZE];
 	uint16_t ei_flags;
 
 	GElf_Phdr phdr;
-	char pt_buf[BUF_SIZE];
 	char found_pt_pax;
 	size_t i, phnum;
 
-	memset(ei_buf, 0, BUF_SIZE);
-	memset(pt_buf, 0, BUF_SIZE);
+	memset(pax_buf, 0, BUF_SIZE);
 
 	if (!PyArg_ParseTuple(args, "s", &f_name))
 	{
@@ -86,12 +85,15 @@ pax_getflags(PyObject *self, PyObject *args)
 
 	if((elf = elf_begin(fd, ELF_C_READ_MMAP, NULL)) == NULL)
 	{
+		close(fd);
 		PyErr_SetString(PaxError, "pax_getflags: elf_begin() failed");
 		return NULL;
 	}
 
 	if(elf_kind(elf) != ELF_K_ELF)
 	{
+		elf_end(elf);
+		close(fd);
 		PyErr_SetString(PaxError, "pax_getflags: elf_kind() failed: this is not an elf file.");
 		return NULL;
 	}
@@ -103,6 +105,8 @@ pax_getflags(PyObject *self, PyObject *args)
 	{
 		if(gelf_getphdr(elf, i, &phdr) != &phdr)
 		{
+			elf_end(elf);
+			close(fd);
 			PyErr_SetString(PaxError, "pax_getflags: gelf_getphdr() failed");
 			return NULL;
 		}
@@ -111,50 +115,48 @@ pax_getflags(PyObject *self, PyObject *args)
 		{
 			found_pt_pax = 1;
 
-			pt_buf[0] = phdr.p_flags & PF_PAGEEXEC ? 'P' :
+			pax_buf[0] = phdr.p_flags & PF_PAGEEXEC ? 'P' :
 				phdr.p_flags & PF_NOPAGEEXEC ? 'p' : '-' ;
 
-			pt_buf[1] = phdr.p_flags & PF_SEGMEXEC   ? 'S' : 
+			pax_buf[1] = phdr.p_flags & PF_SEGMEXEC   ? 'S' : 
 				phdr.p_flags & PF_NOSEGMEXEC ? 's' : '-';
 
-			pt_buf[2] = phdr.p_flags & PF_MPROTECT   ? 'M' :
+			pax_buf[2] = phdr.p_flags & PF_MPROTECT   ? 'M' :
 				phdr.p_flags & PF_NOMPROTECT ? 'm' : '-';
 
-			pt_buf[3] = phdr.p_flags & PF_EMUTRAMP   ? 'E' :
+			pax_buf[3] = phdr.p_flags & PF_EMUTRAMP   ? 'E' :
 				phdr.p_flags & PF_NOEMUTRAMP ? 'e' : '-';
 
-			pt_buf[4] = phdr.p_flags & PF_RANDMMAP   ? 'R' :
+			pax_buf[4] = phdr.p_flags & PF_RANDMMAP   ? 'R' :
 				phdr.p_flags & PF_NORANDMMAP ? 'r' : '-';
 
-			pt_buf[5] = phdr.p_flags & PF_RANDEXEC   ? 'X' :
+			pax_buf[5] = phdr.p_flags & PF_RANDEXEC   ? 'X' :
 				phdr.p_flags & PF_NORANDEXEC ? 'x' : '-';
 		}
 	}
 
-	if(found_pt_pax)
-		printf("PT_PAX: %s\n", pt_buf);
-	else
+	if(!found_pt_pax)
 	{
 		if(gelf_getehdr(elf, &ehdr) != &ehdr)
 		{
+			elf_end(elf);
+			close(fd);
 			PyErr_SetString(PaxError, "pax_getflags: gelf_getehdr() failed");
 			return NULL;
 		}
 
 		ei_flags = ehdr.e_ident[EI_PAX] + (ehdr.e_ident[EI_PAX + 1] << 8);
 
-  		ei_buf[0] = ei_flags & HF_PAX_PAGEEXEC ? 'p' : 'P';
-		ei_buf[1] = ei_flags & HF_PAX_SEGMEXEC ? 's' : 'S';
-		ei_buf[2] = ei_flags & HF_PAX_MPROTECT ? 'm' : 'M';
-		ei_buf[3] = ei_flags & HF_PAX_EMUTRAMP ? 'E' : 'e';
-		ei_buf[4] = ei_flags & HF_PAX_RANDMMAP ? 'r' : 'R';
-		ei_buf[5] = ei_flags & HF_PAX_RANDEXEC ? 'X' : 'x';
-
-		printf("EI_PAX: %s\n", ei_buf);
+  		pax_buf[0] = ei_flags & HF_PAX_PAGEEXEC ? 'p' : 'P';
+		pax_buf[1] = ei_flags & HF_PAX_SEGMEXEC ? 's' : 'S';
+		pax_buf[2] = ei_flags & HF_PAX_MPROTECT ? 'm' : 'M';
+		pax_buf[3] = ei_flags & HF_PAX_EMUTRAMP ? 'E' : 'e';
+		pax_buf[4] = ei_flags & HF_PAX_RANDMMAP ? 'r' : 'R';
+		pax_buf[5] = ei_flags & HF_PAX_RANDEXEC ? 'X' : 'x';
 	}
 
 	elf_end(elf);
 	close(fd);
 
-	return Py_BuildValue("i", sts);
+	return Py_BuildValue("s", pax_buf);
 }



             reply	other threads:[~2011-10-06  4:19 UTC|newest]

Thread overview: 89+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-06  4:19 Anthony G. Basile [this message]
  -- strict thread matches above, loose matches on Subject: below --
2019-11-18 18:21 [gentoo-commits] proj/elfix:master commit in: scripts/ Anthony G. Basile
2019-04-22 22:14 Anthony G. Basile
2015-10-27 19:37 Anthony G. Basile
2015-01-04 15:42 Anthony G. Basile
2014-12-22 17:29 Anthony G. Basile
2014-10-17 20:02 Anthony G. Basile
2014-01-23 16:22 Anthony G. Basile
2014-01-20 22:44 Anthony G. Basile
2013-05-20 19:47 Anthony G. Basile
2013-03-14  2:39 Anthony G. Basile
2013-01-06 17:19 Anthony G. Basile
2012-12-28 19:34 Anthony G. Basile
2012-12-23  3:49 Anthony G. Basile
2012-12-23  2:36 Anthony G. Basile
2012-12-23  1:04 Anthony G. Basile
2012-12-22 22:20 Anthony G. Basile
2012-12-22 20:17 Anthony G. Basile
2012-12-22 19:42 Anthony G. Basile
2012-12-22 19:29 Anthony G. Basile
2012-12-22 19:02 Anthony G. Basile
2012-12-22 18:31 Anthony G. Basile
2012-12-22 16:36 Anthony G. Basile
2012-12-22  1:04 Anthony G. Basile
2012-12-20  4:26 Anthony G. Basile
2012-12-19  4:09 Anthony G. Basile
2012-12-19  3:51 Anthony G. Basile
2012-12-15 20:03 Anthony G. Basile
2012-12-14  2:19 Anthony G. Basile
2012-12-14  2:16 Anthony G. Basile
2012-12-14  2:04 Anthony G. Basile
2012-12-14  1:59 Anthony G. Basile
2012-12-14  1:26 Anthony G. Basile
2012-12-14  1:20 Anthony G. Basile
2012-07-27 22:01 Anthony G. Basile
2012-07-23 19:18 Anthony G. Basile
2012-07-23 15:46 Anthony G. Basile
2012-07-23 15:27 Anthony G. Basile
2012-07-23 14:58 Anthony G. Basile
2012-07-23 14:15 Anthony G. Basile
2012-07-23 13:06 Anthony G. Basile
2012-07-23 11:47 Anthony G. Basile
2012-07-22 23:11 Anthony G. Basile
2012-07-22 22:22 Anthony G. Basile
2012-07-21 16:28 Anthony G. Basile
2012-07-21 15:44 Anthony G. Basile
2012-07-21 15:41 Anthony G. Basile
2012-07-21 13:53 Anthony G. Basile
2011-12-28 23:19 Anthony G. Basile
2011-12-28 23:18 Anthony G. Basile
2011-12-28 16:37 Anthony G. Basile
2011-12-28 15:39 Anthony G. Basile
2011-12-28 15:31 Anthony G. Basile
2011-12-26 22:24 Anthony G. Basile
2011-12-26 20:25 Anthony G. Basile
2011-12-04 21:43 Anthony G. Basile
2011-11-27  0:17 Anthony G. Basile
2011-11-26 22:08 Anthony G. Basile
2011-11-26 21:15 Anthony G. Basile
2011-11-26 19:08 Anthony G. Basile
2011-11-26 19:07 Anthony G. Basile
2011-10-17 20:55 Anthony G. Basile
2011-10-17 20:15 Anthony G. Basile
2011-10-17 19:28 Anthony G. Basile
2011-10-16 18:27 Anthony G. Basile
2011-10-16 18:27 Anthony G. Basile
2011-10-16 18:04 Anthony G. Basile
2011-10-13  4:36 Anthony G. Basile
2011-10-13  2:27 Anthony G. Basile
2011-10-13  0:36 Anthony G. Basile
2011-10-11  0:50 Anthony G. Basile
2011-10-10 23:42 Anthony G. Basile
2011-10-10 23:21 Anthony G. Basile
2011-10-10 17:30 Anthony G. Basile
2011-10-10 17:29 Anthony G. Basile
2011-10-08 18:35 Anthony G. Basile
2011-10-08  2:03 Anthony G. Basile
2011-10-08  0:46 Anthony G. Basile
2011-10-07 22:14 Anthony G. Basile
2011-10-07 19:58 Anthony G. Basile
2011-10-07  1:56 Anthony G. Basile
2011-10-06 23:39 Anthony G. Basile
2011-10-06 20:14 Anthony G. Basile
2011-10-06 19:46 Anthony G. Basile
2011-10-06  4:07 Anthony G. Basile
2011-10-06  3:14 Anthony G. Basile
2011-10-06  3:13 Anthony G. Basile
2011-10-06  2:20 Anthony G. Basile
2011-09-08 23:50 Anthony G. Basile

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4e8f465fd70faffada1f99f0096c269080fa967a.blueness@gentoo \
    --to=blueness@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox