util-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nick Black <nick.black@sprezzatech.com>
To: Karel Zak <kzak@redhat.com>
Cc: util-linux@vger.kernel.org, nick black <nick.black@sprezzatech.com>
Subject: [PATCH 1/4] use GCC format __attribute__ on sprinf
Date: Sat,  7 Jul 2012 11:51:40 -0400	[thread overview]
Message-ID: <1341676300-27932-1-git-send-email-nick.black@sprezzatech.com> (raw)

From: nick black <nick.black@sprezzatech.com>

---
 libblkid/src/blkidP.h |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libblkid/src/blkidP.h b/libblkid/src/blkidP.h
index 604de3d..bceda33 100644
--- a/libblkid/src/blkidP.h
+++ b/libblkid/src/blkidP.h
@@ -435,8 +435,10 @@ extern int blkid_probe_set_value(blkid_probe pr, const char *name,
                 unsigned char *data, size_t len);
 extern int blkid_probe_vsprintf_value(blkid_probe pr, const char *name,
                 const char *fmt, va_list ap);
+	;
 extern int blkid_probe_sprintf_value(blkid_probe pr, const char *name,
-                const char *fmt, ...);
+                const char *fmt, ...) __attribute__ ((format (printf,3,4)));
+
 extern int blkid_probe_set_magic(blkid_probe pr, blkid_loff_t offset,
 		size_t len, unsigned char *magic);
 
-- 
1.7.10.4


>From d8a5b55012c2e01bff78a9c1237f4f2a93bd9c3a Mon Sep 17 00:00:00 2001
From: nick black <nick.black@sprezzatech.com>
Date: Sat, 7 Jul 2012 11:41:15 -0400
Subject: [PATCH 2/4] properly check for ansi c99 vsnprint truncation

---
 libblkid/src/probe.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libblkid/src/probe.c b/libblkid/src/probe.c
index ce14526..33220df 100644
--- a/libblkid/src/probe.c
+++ b/libblkid/src/probe.c
@@ -1219,7 +1219,7 @@ int blkid_probe_vsprintf_value(blkid_probe pr, const char *name,
 
 	len = vsnprintf((char *) v->data, sizeof(v->data), fmt, ap);
 
-	if (len <= 0) {
+	if (len <= 0 || len >= sizeof(v->data)) {
 		blkid_probe_reset_last_value(pr);
 		return -1;
 	}
-- 
1.7.10.4


>From 330ff7edc480b4e897f946c30a2afa38c916b9d0 Mon Sep 17 00:00:00 2001
From: nick black <nick.black@sprezzatech.com>
Date: Sat, 7 Jul 2012 11:42:17 -0400
Subject: [PATCH 3/4] use memcpy() to cope with possible misalignment

---
 libblkid/src/topology/topology.c |    5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/libblkid/src/topology/topology.c b/libblkid/src/topology/topology.c
index 5cde187..02476e5 100644
--- a/libblkid/src/topology/topology.c
+++ b/libblkid/src/topology/topology.c
@@ -222,14 +222,13 @@ static int topology_set_value(blkid_probe pr, const char *name,
 		return 0;	/* ignore zeros */
 
 	if (chn->binary) {
-		unsigned long *v =
-			(unsigned long *) (chn->data + structoff);
-		*v = data;
+		memcpy(chn->data + structoff, &data, sizeof(data));
 		return 0;
 	}
 	return blkid_probe_sprintf_value(pr, name, "%llu", data);
 }
 
+
 /* the topology info is complete when we have at least "minimum_io_size" which
  * is provided by all blkid topology drivers */
 static int topology_is_complete(blkid_probe pr)
-- 
1.7.10.4


>From ffab21e12846dd9b9403c881721e415493805bd1 Mon Sep 17 00:00:00 2001
From: nick black <nick.black@sprezzatech.com>
Date: Sat, 7 Jul 2012 11:42:35 -0400
Subject: [PATCH 4/4] use proper printf format spec %lu

---
 libblkid/src/topology/topology.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libblkid/src/topology/topology.c b/libblkid/src/topology/topology.c
index 02476e5..73a397a 100644
--- a/libblkid/src/topology/topology.c
+++ b/libblkid/src/topology/topology.c
@@ -225,7 +225,7 @@ static int topology_set_value(blkid_probe pr, const char *name,
 		memcpy(chn->data + structoff, &data, sizeof(data));
 		return 0;
 	}
-	return blkid_probe_sprintf_value(pr, name, "%llu", data);
+	return blkid_probe_sprintf_value(pr, name, "%lu", data);
 }
 
 
-- 
1.7.10.4


                 reply	other threads:[~2012-07-07 16:02 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=1341676300-27932-1-git-send-email-nick.black@sprezzatech.com \
    --to=nick.black@sprezzatech.com \
    --cc=kzak@redhat.com \
    --cc=util-linux@vger.kernel.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;
as well as URLs for NNTP newsgroup(s).