Fix possible endless loops on cleanup.
authorBernhard Miklautz <bernhard.miklautz@thincast.com>
Wed, 24 Jun 2015 10:26:13 +0000 (12:26 +0200)
committerBernhard Miklautz <bernhard.miklautz@thincast.com>
Wed, 24 Jun 2015 10:26:13 +0000 (12:26 +0200)
Some cleanup code possibly create endless loops because an unsigned
type was used as run variable but the check was >= 0 in the for loop.

libfreerdp/core/message.c
libfreerdp/core/settings.c
winpr/libwinpr/clipboard/clipboard.c

index dd70027..2c8f8e8 100644 (file)
@@ -107,10 +107,10 @@ static BOOL update_message_BitmapUpdate(rdpContext* context, BITMAP_UPDATE* bitm
                wParam->rectangles[index].bitmapDataStream = (BYTE*) malloc(wParam->rectangles[index].bitmapLength);
                if (!wParam->rectangles[index].bitmapDataStream)
                {
-                       for (index -= 1; index >= 0; --index)
-                       {
-                               free(wParam->rectangles[index].bitmapDataStream);
-                       }
+                       UINT32 i;
+                       for (i = 0; i < index; ++i)
+                               free(wParam->rectangles[i].bitmapDataStream);
+
                        free(wParam->rectangles);
                        free(wParam);
                        return FALSE;
index 38b5a3f..f038efe 100644 (file)
@@ -755,8 +755,9 @@ rdpSettings* freerdp_settings_clone(rdpSettings* settings)
                                _settings->TargetNetAddresses[index] = _strdup(settings->TargetNetAddresses[index]);
                                if (!_settings->TargetNetAddresses[index])
                                {
-                                       for (--index; index >= 0; --index)
-                                               free(_settings->TargetNetAddresses[index]);
+                                       UINT32 i;
+                                       for (i = 0; i < index; ++i)
+                                               free(_settings->TargetNetAddresses[i]);
                                        free(_settings->TargetNetAddresses);
                                        _settings->TargetNetAddresses = NULL;
                                        _settings->TargetNetAddressCount = 0;
index 3e6a524..585c987 100644 (file)
@@ -374,9 +374,12 @@ BOOL ClipboardInitFormats(wClipboard* clipboard)
 
                if (!format->formatName)
                {
-                       for (--formatId; formatId >= 0; --formatId)
+                       int i;
+                       for(i = formatId-1; i >= 0; --i)
+                       {
+                               format = &(clipboard->formats[--clipboard->numFormats]);
                                free((void *)format->formatName);
-                       clipboard->numFormats = 0;
+                       }
                        return FALSE;
                }
        }