linux-nfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Do not segfault because of kernel version
@ 2011-07-02 14:32 Luk Claes
  2011-07-03  5:04 ` NeilBrown
  0 siblings, 1 reply; 13+ messages in thread
From: Luk Claes @ 2011-07-02 14:32 UTC (permalink / raw)
  To: Steve Dickson, linux-nfs; +Cc: Luk Claes

mount.nfs segfaults if kernel version number does not contain
at least 3 components delimited with a dot.

Avoid this by matching up to three unsigned integers inialised
to zero, separated by dots.

Signed-off-by: Luk Claes <luk@debian.org>
---
 utils/mount/version.h |   11 +++++------
 1 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/utils/mount/version.h b/utils/mount/version.h
index af61a6f..2642eab 100644
--- a/utils/mount/version.h
+++ b/utils/mount/version.h
@@ -23,8 +23,7 @@
 #ifndef _NFS_UTILS_MOUNT_VERSION_H
 #define _NFS_UTILS_MOUNT_VERSION_H
 
-#include <stdlib.h>
-#include <string.h>
+#include <stdio.h>
 
 #include <sys/utsname.h>
 
@@ -37,14 +36,14 @@ static inline unsigned int MAKE_VERSION(unsigned int p, unsigned int q,
 static inline unsigned int linux_version_code(void)
 {
 	struct utsname my_utsname;
-	unsigned int p, q, r;
+	unsigned int p, q = 0, r = 0;
 
 	if (uname(&my_utsname))
 		return 0;
 
-	p = (unsigned int)atoi(strtok(my_utsname.release, "."));
-	q = (unsigned int)atoi(strtok(NULL, "."));
-	r = (unsigned int)atoi(strtok(NULL, "."));
+	if (sscanf(my_utsname.release, "%u.%u.%u", &p, &q, &r) < 1)
+		return 0;
+	
 	return MAKE_VERSION(p, q, r);
 }
 
-- 
1.7.5.4


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

end of thread, other threads:[~2011-07-12 14:42 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-07-02 14:32 [PATCH] Do not segfault because of kernel version Luk Claes
2011-07-03  5:04 ` NeilBrown
2011-07-03  6:37   ` Luk Claes
2011-07-03 13:02     ` Jim Rees
2011-07-03 13:10       ` Luk Claes
2011-07-03 13:26         ` Jim Rees
2011-07-03 13:28           ` Luk Claes
2011-07-03 14:11             ` Jim Rees
2011-07-04 16:28               ` Luk Claes
2011-07-04 19:00                 ` Jim Rees
2011-07-05  5:42                   ` Luk Claes
2011-07-05  5:42                     ` Luk Claes
2011-07-12 14:42                       ` Steve Dickson

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).