EnableDisableExtensionError: Use ARRAY_SIZE rather than sentinel

Submitted by Alan Coopersmith on Dec. 18, 2012, 8:58 a.m.

Details

Message ID 1355821096-189-1-git-send-email-alan.coopersmith@oracle.com
State Accepted
Commit 9ff2e831517875f96477862f979abff394e8d551
Headers show

Not browsing as part of any series.

Commit Message

Alan Coopersmith Dec. 18, 2012, 8:58 a.m.
d785368e0e converted the other miinitext functions to use ARRAY_SIZE,
and removed the sentinel, but missed EnableDisableExtensionError so
passing an invalid extension name could cause the server to walk off
the end off the list looking for a sentinel that wasn't there.

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
---
 mi/miinitext.c |    9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

Patch hide | download patch | download mbox

diff --git a/mi/miinitext.c b/mi/miinitext.c
index 369da5e..81c663a 100644
--- a/mi/miinitext.c
+++ b/mi/miinitext.c
@@ -212,10 +212,12 @@  EnableDisableExtension(const char *name, Bool enable)
 void
 EnableDisableExtensionError(const char *name, Bool enable)
 {
-    ExtensionToggle *ext = &ExtensionToggleList[0];
+    ExtensionToggle *ext;
+    int i;
     Bool found = FALSE;
 
-    for (ext = &ExtensionToggleList[0]; ext->name != NULL; ext++) {
+    for (i = 0; i < ARRAY_SIZE(ExtensionToggleList); i++) {
+        ext = &ExtensionToggleList[i];
         if ((strcmp(name, ext->name) == 0) && (ext->disablePtr == NULL)) {
             ErrorF("[mi] Extension \"%s\" can not be disabled\n", name);
             found = TRUE;
@@ -226,7 +228,8 @@  EnableDisableExtensionError(const char *name, Bool enable)
         ErrorF("[mi] Extension \"%s\" is not recognized\n", name);
     ErrorF("[mi] Only the following extensions can be run-time %s:\n",
            enable ? "enabled" : "disabled");
-    for (ext = &ExtensionToggleList[0]; ext->name != NULL; ext++) {
+    for (i = 0; i < ARRAY_SIZE(ExtensionToggleList); i++) {
+        ext = &ExtensionToggleList[i];
         if (ext->disablePtr != NULL) {
             ErrorF("[mi]    %s\n", ext->name);
         }

Comments

On Tue, Dec 18, 2012 at 12:58:16AM -0800, Alan Coopersmith wrote:
> d785368e0e converted the other miinitext functions to use ARRAY_SIZE,
> and removed the sentinel, but missed EnableDisableExtensionError so
> passing an invalid extension name could cause the server to walk off
> the end off the list looking for a sentinel that wasn't there.
> 
> Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>

Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>

Cheers,
   Peter


> ---
>  mi/miinitext.c |    9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/mi/miinitext.c b/mi/miinitext.c
> index 369da5e..81c663a 100644
> --- a/mi/miinitext.c
> +++ b/mi/miinitext.c
> @@ -212,10 +212,12 @@ EnableDisableExtension(const char *name, Bool enable)
>  void
>  EnableDisableExtensionError(const char *name, Bool enable)
>  {
> -    ExtensionToggle *ext = &ExtensionToggleList[0];
> +    ExtensionToggle *ext;
> +    int i;
>      Bool found = FALSE;
>  
> -    for (ext = &ExtensionToggleList[0]; ext->name != NULL; ext++) {
> +    for (i = 0; i < ARRAY_SIZE(ExtensionToggleList); i++) {
> +        ext = &ExtensionToggleList[i];
>          if ((strcmp(name, ext->name) == 0) && (ext->disablePtr == NULL)) {
>              ErrorF("[mi] Extension \"%s\" can not be disabled\n", name);
>              found = TRUE;
> @@ -226,7 +228,8 @@ EnableDisableExtensionError(const char *name, Bool enable)
>          ErrorF("[mi] Extension \"%s\" is not recognized\n", name);
>      ErrorF("[mi] Only the following extensions can be run-time %s:\n",
>             enable ? "enabled" : "disabled");
> -    for (ext = &ExtensionToggleList[0]; ext->name != NULL; ext++) {
> +    for (i = 0; i < ARRAY_SIZE(ExtensionToggleList); i++) {
> +        ext = &ExtensionToggleList[i];
>          if (ext->disablePtr != NULL) {
>              ErrorF("[mi]    %s\n", ext->name);
>          }
> -- 
> 1.7.9.2
> 
> _______________________________________________
> xorg-devel@lists.x.org: X.Org development
> Archives: http://lists.x.org/archives/xorg-devel
> Info: http://lists.x.org/mailman/listinfo/xorg-devel
>