From patchwork Sat Jul 2 14:32:29 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luk Claes X-Patchwork-Id: 940412 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p62EWqfx004952 for ; Sat, 2 Jul 2011 14:32:53 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754744Ab1GBOcv (ORCPT ); Sat, 2 Jul 2011 10:32:51 -0400 Received: from jacques.telenet-ops.be ([195.130.132.50]:36378 "EHLO jacques.telenet-ops.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752003Ab1GBOcu (ORCPT ); Sat, 2 Jul 2011 10:32:50 -0400 Received: from station.luk.local ([78.20.68.195]) by jacques.telenet-ops.be with bizsmtp id 32Yo1h00S4CmlCm0J2Yovc; Sat, 02 Jul 2011 16:32:49 +0200 Received: from luk by station.luk.local with local (Exim 4.76) (envelope-from ) id 1Qd1Fb-00012z-Gt; Sat, 02 Jul 2011 16:32:51 +0200 From: Luk Claes To: Steve Dickson , linux-nfs@vger.kernel.org Cc: Luk Claes Subject: [PATCH] Do not segfault because of kernel version Date: Sat, 2 Jul 2011 16:32:29 +0200 Message-Id: <1309617149-3993-1-git-send-email-luk@debian.org> X-Mailer: git-send-email 1.7.5.4 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Sat, 02 Jul 2011 14:32:53 +0000 (UTC) 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 --- 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 -#include +#include #include @@ -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); }