* [PATCH libdrm] xf86drm: Fix error handling for drmGetDevices()
@ 2015-09-30 16:30 Matt Roper
2015-10-01 10:12 ` Emil Velikov
0 siblings, 1 reply; 4+ messages in thread
From: Matt Roper @ 2015-09-30 16:30 UTC (permalink / raw)
To: dri-devel; +Cc: Emil Velikov
If the opendir() call in drmGetDevices() returns failure, we jump to an
error label that calls closedir() and then returns. However this means
that we're calling closedir(NULL) which may not be safe on all
implementations. We are also leaking the local_devices array that was
allocated before the opendir() call.
Fix both of these issues by jumping to an earlier error label (to free
local_devices) and guarding the closedir() call with a NULL test.
Cc: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Matt Roper <matthew.d.roper@intel.com>
---
xf86drm.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/xf86drm.c b/xf86drm.c
index c1cab1b..763d710 100644
--- a/xf86drm.c
+++ b/xf86drm.c
@@ -3209,7 +3209,7 @@ int drmGetDevices(drmDevicePtr devices[], int max_devices)
sysdir = opendir(DRM_DIR_NAME);
if (!sysdir) {
ret = -errno;
- goto close_sysdir;
+ goto free_locals;
}
i = 0;
@@ -3280,9 +3280,10 @@ int drmGetDevices(drmDevicePtr devices[], int max_devices)
free_devices:
drmFreeDevices(local_devices, i);
+free_locals:
free(local_devices);
-close_sysdir:
- closedir(sysdir);
+ if (sysdir)
+ closedir(sysdir);
return ret;
}
--
2.1.4
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH libdrm] xf86drm: Fix error handling for drmGetDevices()
2015-09-30 16:30 [PATCH libdrm] xf86drm: Fix error handling for drmGetDevices() Matt Roper
@ 2015-10-01 10:12 ` Emil Velikov
2015-10-01 15:59 ` Matt Roper
0 siblings, 1 reply; 4+ messages in thread
From: Emil Velikov @ 2015-10-01 10:12 UTC (permalink / raw)
To: Matt Roper; +Cc: ML dri-devel
Hi Matt,
On 30 September 2015 at 17:30, Matt Roper <matthew.d.roper@intel.com> wrote:
> If the opendir() call in drmGetDevices() returns failure, we jump to an
> error label that calls closedir() and then returns. However this means
> that we're calling closedir(NULL) which may not be safe on all
> implementations. We are also leaking the local_devices array that was
> allocated before the opendir() call.
>
> Fix both of these issues by jumping to an earlier error label (to free
> local_devices) and guarding the closedir() call with a NULL test.
>
> Cc: Emil Velikov <emil.l.velikov@gmail.com>
> Signed-off-by: Matt Roper <matthew.d.roper@intel.com>
> ---
> xf86drm.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/xf86drm.c b/xf86drm.c
> index c1cab1b..763d710 100644
> --- a/xf86drm.c
> +++ b/xf86drm.c
> @@ -3209,7 +3209,7 @@ int drmGetDevices(drmDevicePtr devices[], int max_devices)
> sysdir = opendir(DRM_DIR_NAME);
> if (!sysdir) {
> ret = -errno;
> - goto close_sysdir;
> + goto free_locals;
> }
>
> i = 0;
> @@ -3280,9 +3280,10 @@ int drmGetDevices(drmDevicePtr devices[], int max_devices)
>
> free_devices:
> drmFreeDevices(local_devices, i);
> +free_locals:
> free(local_devices);
>
> -close_sysdir:
> - closedir(sysdir);
> + if (sysdir)
> + closedir(sysdir);
Any objections if we move the new label & free() here and drop the if
check above? I can do that before pushing if that's ok with you.
Thanks for catching this.
Emil
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH libdrm] xf86drm: Fix error handling for drmGetDevices()
2015-10-01 10:12 ` Emil Velikov
@ 2015-10-01 15:59 ` Matt Roper
2015-10-02 12:23 ` Emil Velikov
0 siblings, 1 reply; 4+ messages in thread
From: Matt Roper @ 2015-10-01 15:59 UTC (permalink / raw)
To: Emil Velikov; +Cc: ML dri-devel
On Thu, Oct 01, 2015 at 11:12:34AM +0100, Emil Velikov wrote:
> Hi Matt,
>
> On 30 September 2015 at 17:30, Matt Roper <matthew.d.roper@intel.com> wrote:
> > If the opendir() call in drmGetDevices() returns failure, we jump to an
> > error label that calls closedir() and then returns. However this means
> > that we're calling closedir(NULL) which may not be safe on all
> > implementations. We are also leaking the local_devices array that was
> > allocated before the opendir() call.
> >
> > Fix both of these issues by jumping to an earlier error label (to free
> > local_devices) and guarding the closedir() call with a NULL test.
> >
> > Cc: Emil Velikov <emil.l.velikov@gmail.com>
> > Signed-off-by: Matt Roper <matthew.d.roper@intel.com>
> > ---
> > xf86drm.c | 7 ++++---
> > 1 file changed, 4 insertions(+), 3 deletions(-)
> >
> > diff --git a/xf86drm.c b/xf86drm.c
> > index c1cab1b..763d710 100644
> > --- a/xf86drm.c
> > +++ b/xf86drm.c
> > @@ -3209,7 +3209,7 @@ int drmGetDevices(drmDevicePtr devices[], int max_devices)
> > sysdir = opendir(DRM_DIR_NAME);
> > if (!sysdir) {
> > ret = -errno;
> > - goto close_sysdir;
> > + goto free_locals;
> > }
> >
> > i = 0;
> > @@ -3280,9 +3280,10 @@ int drmGetDevices(drmDevicePtr devices[], int max_devices)
> >
> > free_devices:
> > drmFreeDevices(local_devices, i);
> > +free_locals:
> > free(local_devices);
> >
> > -close_sysdir:
> > - closedir(sysdir);
> > + if (sysdir)
> > + closedir(sysdir);
> Any objections if we move the new label & free() here and drop the if
> check above? I can do that before pushing if that's ok with you.
>
> Thanks for catching this.
> Emil
Sure, that sounds fine too. Thanks!
Matt
--
Matt Roper
Graphics Software Engineer
IoTG Platform Enabling & Development
Intel Corporation
(916) 356-2795
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH libdrm] xf86drm: Fix error handling for drmGetDevices()
2015-10-01 15:59 ` Matt Roper
@ 2015-10-02 12:23 ` Emil Velikov
0 siblings, 0 replies; 4+ messages in thread
From: Emil Velikov @ 2015-10-02 12:23 UTC (permalink / raw)
To: Matt Roper; +Cc: ML dri-devel
On 1 October 2015 at 16:59, Matt Roper <matthew.d.roper@intel.com> wrote:
> On Thu, Oct 01, 2015 at 11:12:34AM +0100, Emil Velikov wrote:
>> Hi Matt,
>>
>> On 30 September 2015 at 17:30, Matt Roper <matthew.d.roper@intel.com> wrote:
>> > If the opendir() call in drmGetDevices() returns failure, we jump to an
>> > error label that calls closedir() and then returns. However this means
>> > that we're calling closedir(NULL) which may not be safe on all
>> > implementations. We are also leaking the local_devices array that was
>> > allocated before the opendir() call.
>> >
>> > Fix both of these issues by jumping to an earlier error label (to free
>> > local_devices) and guarding the closedir() call with a NULL test.
>> >
>> > Cc: Emil Velikov <emil.l.velikov@gmail.com>
>> > Signed-off-by: Matt Roper <matthew.d.roper@intel.com>
>> > ---
>> > xf86drm.c | 7 ++++---
>> > 1 file changed, 4 insertions(+), 3 deletions(-)
>> >
>> > diff --git a/xf86drm.c b/xf86drm.c
>> > index c1cab1b..763d710 100644
>> > --- a/xf86drm.c
>> > +++ b/xf86drm.c
>> > @@ -3209,7 +3209,7 @@ int drmGetDevices(drmDevicePtr devices[], int max_devices)
>> > sysdir = opendir(DRM_DIR_NAME);
>> > if (!sysdir) {
>> > ret = -errno;
>> > - goto close_sysdir;
>> > + goto free_locals;
>> > }
>> >
>> > i = 0;
>> > @@ -3280,9 +3280,10 @@ int drmGetDevices(drmDevicePtr devices[], int max_devices)
>> >
>> > free_devices:
>> > drmFreeDevices(local_devices, i);
>> > +free_locals:
>> > free(local_devices);
>> >
>> > -close_sysdir:
>> > - closedir(sysdir);
>> > + if (sysdir)
>> > + closedir(sysdir);
>> Any objections if we move the new label & free() here and drop the if
>> check above? I can do that before pushing if that's ok with you.
>>
>> Thanks for catching this.
>> Emil
>
> Sure, that sounds fine too. Thanks!
>
Ack. Amended and pushed to master.
-Emil
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-10-02 12:23 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-30 16:30 [PATCH libdrm] xf86drm: Fix error handling for drmGetDevices() Matt Roper
2015-10-01 10:12 ` Emil Velikov
2015-10-01 15:59 ` Matt Roper
2015-10-02 12:23 ` Emil Velikov
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.