Patchwork Unitialized variable in mount.cifs error path

login
register
mail settings
Submitter Steve French
Date May 7, 2010, 5:47 p.m.
Message ID <o2y524f69651005071047recbdd46haf5f346cadd1f2df@mail.gmail.com>
Download mbox | patch
Permalink /patch/51940/
State New
Headers show

Comments

Steve French - May 7, 2010, 5:47 p.m.

Jeff Layton - May 11, 2010, 1:13 p.m.
On Fri, 7 May 2010 12:47:11 -0500
Steve French <smfrench@gmail.com> wrote:

> diff --git a/mount.cifs.c b/mount.cifs.c
> index c4eb59a..124be27 100644
> --- a/mount.cifs.c
> +++ b/mount.cifs.c
> @@ -559,7 +606,7 @@ static int open_cred_file(char *file_name,
>  			struct parsed_mount_info *parsed_info)
>  {
>  	char *line_buf;
> -	char *temp_val;
> +	char *temp_val = NULL;
>  	FILE *fs = NULL;
>  	int i;
>  	const int line_buf_size = 4096;
> @@ -622,9 +669,10 @@ static int open_cred_file(char *file_name,
>  			break;
>  		case CRED_UNPARSEABLE:
>  			if (parsed_info->verboseflag)
> -				fprintf(stderr,
> -					"Credential formatted incorrectly: %s",
> -					temp_val);
> +				if (temp_val)
> +					fprintf(stderr,
> +						"Credential formatted incorrectly: %s",
> +						temp_val);

How about instead of the above, we do something like:

fprintf(stderr, "Credential formatted incorrectly: %s\n",
	temp_val ? temp_val : "(null)");

...that way we get an error message even if temp_val is NULL. If that
sounds ok, I'll fix it and commit or you can just send a respun patch...

>  			break;
>  		}
>  	}

Thanks,
Steve French - May 11, 2010, 3:09 p.m.
Your suggestion is fine with me.

On Tue, May 11, 2010 at 8:13 AM, Jeff Layton <jlayton@redhat.com> wrote:
> On Fri, 7 May 2010 12:47:11 -0500
> Steve French <smfrench@gmail.com> wrote:
>
>> diff --git a/mount.cifs.c b/mount.cifs.c
>> index c4eb59a..124be27 100644
>> --- a/mount.cifs.c
>> +++ b/mount.cifs.c
>> @@ -559,7 +606,7 @@ static int open_cred_file(char *file_name,
>>                       struct parsed_mount_info *parsed_info)
>>  {
>>       char *line_buf;
>> -     char *temp_val;
>> +     char *temp_val = NULL;
>>       FILE *fs = NULL;
>>       int i;
>>       const int line_buf_size = 4096;
>> @@ -622,9 +669,10 @@ static int open_cred_file(char *file_name,
>>                       break;
>>               case CRED_UNPARSEABLE:
>>                       if (parsed_info->verboseflag)
>> -                             fprintf(stderr,
>> -                                     "Credential formatted incorrectly: %s",
>> -                                     temp_val);
>> +                             if (temp_val)
>> +                                     fprintf(stderr,
>> +                                             "Credential formatted incorrectly: %s",
>> +                                             temp_val);
>
> How about instead of the above, we do something like:
>
> fprintf(stderr, "Credential formatted incorrectly: %s\n",
>        temp_val ? temp_val : "(null)");
>
> ...that way we get an error message even if temp_val is NULL. If that
> sounds ok, I'll fix it and commit or you can just send a respun patch...
>
>>                       break;
>>               }
>>       }
>
> Thanks,
> --
> Jeff Layton <jlayton@redhat.com>
>
Scott Lovenberg - May 13, 2010, 1:35 p.m.
I think this bug was mine; sorry about that.  Good catch, good solution.
Jeff Layton - May 13, 2010, 5:51 p.m.
On Thu, 13 May 2010 09:35:02 -0400
Scott Lovenberg <scott.lovenberg@gmail.com> wrote:

> I think this bug was mine; sorry about that.  Good catch, good solution.
> -- 
> Peace and Blessings,
> -Scott.

No worries. These things happen. It's always ideal to correct bugs
before they become a problem though :)
Jeff Layton - May 14, 2010, 7:40 p.m.
On Fri, 7 May 2010 12:47:11 -0500
Steve French <smfrench@gmail.com> wrote:

Committed (with small change to error message we discussed)

Patch

diff --git a/mount.cifs.c b/mount.cifs.c
index c4eb59a..124be27 100644
--- a/mount.cifs.c
+++ b/mount.cifs.c
@@ -559,7 +606,7 @@  static int open_cred_file(char *file_name,
 			struct parsed_mount_info *parsed_info)
 {
 	char *line_buf;
-	char *temp_val;
+	char *temp_val = NULL;
 	FILE *fs = NULL;
 	int i;
 	const int line_buf_size = 4096;
@@ -622,9 +669,10 @@  static int open_cred_file(char *file_name,
 			break;
 		case CRED_UNPARSEABLE:
 			if (parsed_info->verboseflag)
-				fprintf(stderr,
-					"Credential formatted incorrectly: %s",
-					temp_val);
+				if (temp_val)
+					fprintf(stderr,
+						"Credential formatted incorrectly: %s",
+						temp_val);
 			break;
 		}
 	}