Patchwork [07/10] mount.cifs: fix error handling when duplicating options string

login
register
mail settings
Submitter Jeff Layton
Date March 21, 2010, 7:20 p.m.
Message ID <1269199227-21446-8-git-send-email-jlayton@redhat.com>
Download mbox | patch
Permalink /patch/48232/
State New
Headers show

Comments

Jeff Layton - March 21, 2010, 7:20 p.m.
Signed-off-by: Jeff Layton <jlayton@redhat.com>
---
 mount.cifs.c |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)

Patch

diff --git a/mount.cifs.c b/mount.cifs.c
index 4631310..76cf851 100644
--- a/mount.cifs.c
+++ b/mount.cifs.c
@@ -57,6 +57,9 @@ 
 
 #define MAX_UNC_LEN 1024
 
+/* I believe that the kernel limits options data to a page */
+#define MAX_OPTIONS_LEN	4096
+
 #ifndef SAFE_FREE
 #define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
 #endif
@@ -1225,8 +1228,10 @@  int main(int argc, char ** argv)
 #endif
 			break;
 		case 'o':
-			orgoptions = strdup(optarg);
-		    break;
+			orgoptions = strndup(optarg, MAX_OPTIONS_LEN);
+			if (!orgoptions)
+				exit(EX_SYSERR);
+			break;
 		case 'r':  /* mount readonly */
 			flags |= MS_RDONLY;
 			break;