Patchwork [v2,06/11] virtfs-proxy-helper: Fix unchecked strdup() by conv. to g_strdup()

login
register
mail settings
Submitter Markus Armbruster
Date Jan. 16, 2013, 5:32 p.m.
Message ID <1358357540-29862-7-git-send-email-armbru@redhat.com>
Download mbox | patch
Permalink /patch/213034/
State New
Headers show

Comments

Markus Armbruster - Jan. 16, 2013, 5:32 p.m.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
---
 fsdev/virtfs-proxy-helper.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Stefan Hajnoczi - Jan. 17, 2013, 11:22 a.m.
On Wed, Jan 16, 2013 at 06:32:15PM +0100, Markus Armbruster wrote:
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> Reviewed-by: Eric Blake <eblake@redhat.com>
> ---
>  fsdev/virtfs-proxy-helper.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/fsdev/virtfs-proxy-helper.c b/fsdev/virtfs-proxy-helper.c
> index 6b9afd3..36f6616 100644
> --- a/fsdev/virtfs-proxy-helper.c
> +++ b/fsdev/virtfs-proxy-helper.c
> @@ -1039,7 +1039,7 @@ int main(int argc, char **argv)
>          }
>          switch (c) {
>          case 'p':
> -            rpath = strdup(optarg);
> +            rpath = g_strdup(optarg);
>              break;
>          case 'n':
>              is_daemon = false;
> @@ -1048,7 +1048,7 @@ int main(int argc, char **argv)
>              sock = atoi(optarg);
>              break;
>          case 's':
> -            sock_name = strdup(optarg);
> +            sock_name = g_strdup(optarg);

rpath and sock_name are leaked.  Not important though because they are
in main().

Stefan
Markus Armbruster - Jan. 17, 2013, 1:10 p.m.
Stefan Hajnoczi <stefanha@gmail.com> writes:

> On Wed, Jan 16, 2013 at 06:32:15PM +0100, Markus Armbruster wrote:
>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>> Reviewed-by: Eric Blake <eblake@redhat.com>
>> ---
>>  fsdev/virtfs-proxy-helper.c | 4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>> 
>> diff --git a/fsdev/virtfs-proxy-helper.c b/fsdev/virtfs-proxy-helper.c
>> index 6b9afd3..36f6616 100644
>> --- a/fsdev/virtfs-proxy-helper.c
>> +++ b/fsdev/virtfs-proxy-helper.c
>> @@ -1039,7 +1039,7 @@ int main(int argc, char **argv)
>>          }
>>          switch (c) {
>>          case 'p':
>> -            rpath = strdup(optarg);
>> +            rpath = g_strdup(optarg);
>>              break;
>>          case 'n':
>>              is_daemon = false;
>> @@ -1048,7 +1048,7 @@ int main(int argc, char **argv)
>>              sock = atoi(optarg);
>>              break;
>>          case 's':
>> -            sock_name = strdup(optarg);
>> +            sock_name = g_strdup(optarg);
>
> rpath and sock_name are leaked.  Not important though because they are
> in main().

Yup.  Freeing stuff before main returns isn't worth your while or mine
:)

Patch

diff --git a/fsdev/virtfs-proxy-helper.c b/fsdev/virtfs-proxy-helper.c
index 6b9afd3..36f6616 100644
--- a/fsdev/virtfs-proxy-helper.c
+++ b/fsdev/virtfs-proxy-helper.c
@@ -1039,7 +1039,7 @@  int main(int argc, char **argv)
         }
         switch (c) {
         case 'p':
-            rpath = strdup(optarg);
+            rpath = g_strdup(optarg);
             break;
         case 'n':
             is_daemon = false;
@@ -1048,7 +1048,7 @@  int main(int argc, char **argv)
             sock = atoi(optarg);
             break;
         case 's':
-            sock_name = strdup(optarg);
+            sock_name = g_strdup(optarg);
             break;
         case 'u':
             own_u = atoi(optarg);