Util-Linux package development
 help / color / mirror / Atom feed
* [PATCH v2] dmesg: fix segfault
@ 2011-07-18 17:37 Marc-Antoine Perennou
  2011-07-18 21:47 ` Karel Zak
  0 siblings, 1 reply; 2+ messages in thread
From: Marc-Antoine Perennou @ 2011-07-18 17:37 UTC (permalink / raw)
  To: util-linux

An element declared as size_t cannot be detected as negative (len < 0)
is always false.
This can lead to an infinite loop causing a segmentation fault.
Check if len is equal to -1 or -2 instead

Signed-off-by: Marc-Antoine Perennou <Marc-Antoine@Perennou.com>
---
 sys-utils/dmesg.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/sys-utils/dmesg.c b/sys-utils/dmesg.c
index 867581d..d7cf95b 100644
--- a/sys-utils/dmesg.c
+++ b/sys-utils/dmesg.c
@@ -367,7 +367,7 @@ static void safe_fwrite(const char *buf, size_t
size, FILE *out)
 		if (len == 0)				/* L'\0' */
 			return;

-		if (len < 0) {				/* invalid sequence */
+		if (len == (size_t)-1 || len == (size_t)-2) {		/* invalid sequence */
 			memset(&s, 0, sizeof (s));
 			len = hex = 1;

-- 
1.7.6.134.gcf13f6.dirty

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-07-18 21:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-07-18 17:37 [PATCH v2] dmesg: fix segfault Marc-Antoine Perennou
2011-07-18 21:47 ` Karel Zak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox