Fixed argument checks, now NULL pointer are no longer dereferenced
authorArmin Novak <anovak@thinstuff.com>
Fri, 30 Aug 2013 12:47:00 +0000 (14:47 +0200)
committerArmin Novak <anovak@thinstuff.com>
Thu, 5 Sep 2013 10:14:34 +0000 (12:14 +0200)
in functions.

libfreerdp/codec/color.c
libfreerdp/gdi/16bpp.c
libfreerdp/gdi/32bpp.c
libfreerdp/gdi/8bpp.c

index 69a2375..8c9499c 100644 (file)
@@ -909,7 +909,11 @@ BYTE* freerdp_icon_convert(BYTE* srcData, BYTE* dstData, BYTE* mask, int width,
                                
                                for (bit = 0; bit < 8; bit++)
                                        if ((bmask & (0x80 >> bit)) == 0)
-                                               *(icon + (height - y - 1) * width + x + bit) |= 0xFF000000;
+                                       {
+                                               UINT32 *tmp = (icon + (height - y - 1) * width + x + bit);
+                                               if (tmp)
+                                                       *tmp |= 0xFF000000;
+                                       }
                        }
                        
                        if ((width % 8) != 0)
@@ -918,7 +922,11 @@ BYTE* freerdp_icon_convert(BYTE* srcData, BYTE* dstData, BYTE* mask, int width,
                                
                                for (bit = 0; bit < width % 8; bit++)
                                        if ((bmask & (0x80 >> bit)) == 0)
-                                               *(icon + (height - y - 1) * width + x + bit) |= 0xFF000000;
+                                       {
+                                               UINT32 *tmp = (icon + (height - y - 1) * width + x + bit);
+                                               if (tmp)
+                                                       *tmp |= 0xFF000000;
+                                       }
                        }
                
                        /* Skip padding */
index 9437ea6..c634ae6 100644 (file)
@@ -143,6 +143,9 @@ static int BitBlt_SRCCOPY_16bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWi
        BYTE* srcp;
        BYTE* dstp;
 
+       if (!hdcSrc || !hdcDest)
+               return 1;
+
        if ((hdcDest->selectedObject != hdcSrc->selectedObject) ||
            gdi_CopyOverlap(nXDest, nYDest, nWidth, nHeight, nXSrc, nYSrc) == 0)
        {
@@ -204,6 +207,9 @@ static int BitBlt_NOTSRCCOPY_16bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int
        UINT16* srcp;
        UINT16* dstp;
        
+       if (!hdcSrc || !hdcDest)
+               return 1;
+
        for (y = 0; y < nHeight; y++)
        {
                srcp = (UINT16*) gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y);
@@ -251,6 +257,9 @@ static int BitBlt_SRCERASE_16bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nW
        UINT16* srcp;
        UINT16* dstp;
                
+       if (!hdcSrc || !hdcDest)
+               return 1;
+
        for (y = 0; y < nHeight; y++)
        {
                srcp = (UINT16*) gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y);
@@ -276,6 +285,9 @@ static int BitBlt_NOTSRCERASE_16bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int
        UINT16* srcp;
        UINT16* dstp;
                
+       if (!hdcSrc || !hdcDest)
+               return 1;
+
        for (y = 0; y < nHeight; y++)
        {
                srcp = (UINT16*) gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y);
@@ -301,6 +313,9 @@ static int BitBlt_SRCINVERT_16bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int n
        UINT16* srcp;
        UINT16* dstp;
                
+       if (!hdcSrc || !hdcDest)
+               return 1;
+
        for (y = 0; y < nHeight; y++)
        {
                srcp = (UINT16*) gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y);
@@ -326,6 +341,9 @@ static int BitBlt_SRCAND_16bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWid
        UINT16* srcp;
        UINT16* dstp;
                
+       if (!hdcSrc || !hdcDest)
+               return 1;
+
        for (y = 0; y < nHeight; y++)
        {
                srcp = (UINT16*) gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y);
@@ -351,6 +369,9 @@ static int BitBlt_SRCPAINT_16bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nW
        UINT16* srcp;
        UINT16* dstp;
                
+       if (!hdcSrc || !hdcDest)
+               return 1;
+
        for (y = 0; y < nHeight; y++)
        {
                srcp = (UINT16*) gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y);
@@ -379,6 +400,9 @@ static int BitBlt_DSPDxax_16bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWi
        UINT16 color16;
        HGDI_BITMAP hSrcBmp;
 
+       if (!hdcDst || !hdcSrc)
+               return 1;
+
        /* D = (S & P) | (~S & D) */
        /* DSPDxax, used to draw glyphs */
 
@@ -420,6 +444,9 @@ static int BitBlt_PSDPxax_16bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWi
        UINT16* patp;
        UINT16 color16;
 
+       if (!hdcSrc || !hdcDest)
+               return 1;
+
        /* D = (S & D) | (~S & P) */
 
        if (hdcDest->brush->style == GDI_BS_SOLID)
@@ -473,6 +500,9 @@ static int BitBlt_SPna_16bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth
        UINT16* dstp;
        UINT16* patp;
        
+       if (!hdcSrc || !hdcDest)
+               return 1;
+
        for (y = 0; y < nHeight; y++)
        {
                srcp = (UINT16*) gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y);
@@ -548,6 +578,9 @@ static int BitBlt_DSna_16bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth
        UINT16* srcp;
        UINT16* dstp;
 
+       if (!hdcSrc || !hdcDest)
+               return 1;
+
        for (y = 0; y < nHeight; y++)
        {
                srcp = (UINT16*) gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y);
@@ -575,6 +608,9 @@ static int BitBlt_MERGECOPY_16bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int n
        UINT16* dstp;
        UINT16* patp;
        
+       if (!hdcSrc || !hdcDest)
+               return 1;
+
        for (y = 0; y < nHeight; y++)
        {
                srcp = (UINT16*) gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y);
@@ -601,6 +637,9 @@ static int BitBlt_MERGEPAINT_16bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int
        UINT16* srcp;
        UINT16* dstp;
        
+       if (!hdcSrc || !hdcDest)
+               return 1;
+
        for (y = 0; y < nHeight; y++)
        {
                srcp = (UINT16*) gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y);
@@ -732,6 +771,9 @@ static int BitBlt_PATPAINT_16bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nW
        UINT16* dstp;
        UINT16* patp;
        
+       if (!hdcSrc || !hdcDest)
+               return 1;
+
        for (y = 0; y < nHeight; y++)
        {
                srcp = (UINT16*) gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y);
@@ -769,7 +811,10 @@ int BitBlt_16bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeigh
        }
        
        gdi_InvalidateRegion(hdcDest, nXDest, nYDest, nWidth, nHeight);
-       
+
+       if (!hdcDest)
+               return 1;
+
        switch (rop)
        {
                case GDI_BLACKNESS:
index d3d91c0..39803f2 100644 (file)
@@ -160,6 +160,9 @@ static int BitBlt_SRCCOPY_32bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWi
        BYTE* srcp;
        BYTE* dstp;
 
+       if (!hdcDst || !hdcSrc)
+               return 1;
+
        if ((hdcDest->selectedObject != hdcSrc->selectedObject) ||
            gdi_CopyOverlap(nXDest, nYDest, nWidth, nHeight, nXSrc, nYSrc) == 0)
        {
@@ -220,7 +223,10 @@ static int BitBlt_NOTSRCCOPY_32bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int
        int x, y;
        UINT32* srcp;
        UINT32* dstp;
-       
+
+       if (!hdcDst || !hdcSrc)
+               return 1;
+
        for (y = 0; y < nHeight; y++)
        {
                srcp = (UINT32*) gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y);
@@ -267,7 +273,10 @@ static int BitBlt_SRCERASE_32bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nW
        int x, y;
        UINT32* srcp;
        UINT32* dstp;
-               
+
+       if (!hdcDst || !hdcSrc)
+               return 1;
+
        for (y = 0; y < nHeight; y++)
        {
                srcp = (UINT32*) gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y);
@@ -292,7 +301,10 @@ static int BitBlt_NOTSRCERASE_32bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int
        int x, y;
        UINT32* srcp;
        UINT32* dstp;
-               
+
+       if (!hdcDst || !hdcSrc)
+               return 1;
+
        for (y = 0; y < nHeight; y++)
        {
                srcp = (UINT32*) gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y);
@@ -317,7 +329,10 @@ static int BitBlt_SRCINVERT_32bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int n
        int x, y;
        UINT32* srcp;
        UINT32* dstp;
-               
+
+       if (!hdcDst || !hdcSrc)
+               return 1;
+
        for (y = 0; y < nHeight; y++)
        {
                srcp = (UINT32*) gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y);
@@ -342,7 +357,10 @@ static int BitBlt_SRCAND_32bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWid
        int x, y;
        UINT32* srcp;
        UINT32* dstp;
-               
+
+       if (!hdcDst || !hdcSrc)
+               return 1;
+
        for (y = 0; y < nHeight; y++)
        {
                srcp = (UINT32*) gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y);
@@ -368,6 +386,9 @@ static int BitBlt_SRCPAINT_32bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nW
        UINT32* srcp;
        UINT32* dstp;
                
+       if (!hdcDst || !hdcSrc)
+               return 1;
+
        for (y = 0; y < nHeight; y++)
        {
                srcp = (UINT32*) gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y);
@@ -398,6 +419,9 @@ static int BitBlt_DSPDxax_32bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWi
        UINT32 color32;
        HGDI_BITMAP hSrcBmp;
 
+       if (!hdcDst || !hdcSrc)
+               return 1;
+
        /* D = (S & P) | (~S & D) */
 
        color32 = gdi_get_color_32bpp(hdcDest, hdcDest->textColor);
@@ -460,6 +484,9 @@ static int BitBlt_PSDPxax_32bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWi
        UINT32* patp;
        UINT32 color32;
 
+       if (!hdcDst || !hdcSrc)
+               return 1;
+
        /* D = (S & D) | (~S & P) */
 
        if (hdcDest->brush->style == GDI_BS_SOLID)
@@ -514,6 +541,9 @@ static int BitBlt_SPDSxax_32bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWi
        UINT32* patp;
        UINT32 color32;
 
+       if (!hdcDst || !hdcSrc)
+               return 1;
+
        /* D = S ^ (P & (D ^ S)) */
 
        if (hdcDest->brush->style == GDI_BS_SOLID)
@@ -566,7 +596,10 @@ static int BitBlt_SPna_32bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth
        UINT32* srcp;
        UINT32* dstp;
        UINT32* patp;
-       
+
+       if (!hdcDst || !hdcSrc)
+               return 1;
+
        for (y = 0; y < nHeight; y++)
        {
                srcp = (UINT32*) gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y);
@@ -594,6 +627,9 @@ static int BitBlt_DSna_32bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth
        UINT32* srcp;
        UINT32* dstp;
 
+       if (!hdcDst || !hdcSrc)
+               return 1;
+
        for (y = 0; y < nHeight; y++)
        {
                srcp = (UINT32*) gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y);
@@ -670,6 +706,9 @@ static int BitBlt_MERGECOPY_32bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int n
        UINT32* dstp;
        UINT32* patp;
        
+       if (!hdcDst || !hdcSrc)
+               return 1;
+
        for (y = 0; y < nHeight; y++)
        {
                srcp = (UINT32*) gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y);
@@ -697,6 +736,9 @@ static int BitBlt_MERGEPAINT_32bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int
        UINT32* srcp;
        UINT32* dstp;
        
+       if (!hdcDst || !hdcSrc)
+               return 1;
+
        for (y = 0; y < nHeight; y++)
        {
                srcp = (UINT32*) gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y);
@@ -827,7 +869,10 @@ static int BitBlt_PATPAINT_32bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nW
        UINT32* srcp;
        UINT32* dstp;
        UINT32* patp;
-       
+
+       if (!hdcDst || !hdcSrc)
+               return 1;
+
        for (y = 0; y < nHeight; y++)
        {
                srcp = (UINT32*) gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y);
@@ -865,7 +910,10 @@ int BitBlt_32bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeigh
        }
        
        gdi_InvalidateRegion(hdcDest, nXDest, nYDest, nWidth, nHeight);
-       
+
+       if (!hdcDest)
+               return 1;
+
        switch (rop)
        {
                case GDI_BLACKNESS:
index c4966ce..0999ced 100644 (file)
@@ -88,6 +88,9 @@ static int BitBlt_SRCCOPY_8bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWid
        BYTE* srcp;
        BYTE* dstp;
 
+       if (!hdcSrc || !hdcDest)
+               return 1;
+
        if ((hdcDest->selectedObject != hdcSrc->selectedObject) ||
            gdi_CopyOverlap(nXDest, nYDest, nWidth, nHeight, nXSrc, nYSrc) == 0)
        {
@@ -149,6 +152,9 @@ static int BitBlt_NOTSRCCOPY_8bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int n
        BYTE* srcp;
        BYTE* dstp;
        
+       if (!hdcSrc || !hdcDest)
+               return 1;
+
        for (y = 0; y < nHeight; y++)
        {
                srcp = gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y);
@@ -196,6 +202,9 @@ static int BitBlt_SRCERASE_8bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWi
        BYTE* srcp;
        BYTE* dstp;
                
+       if (!hdcSrc || !hdcDest)
+               return 1;
+
        for (y = 0; y < nHeight; y++)
        {
                srcp = gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y);
@@ -221,6 +230,9 @@ static int BitBlt_NOTSRCERASE_8bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int
        BYTE* srcp;
        BYTE* dstp;
                
+       if (!hdcSrc || !hdcDest)
+               return 1;
+
        for (y = 0; y < nHeight; y++)
        {
                srcp = gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y);
@@ -246,6 +258,9 @@ static int BitBlt_SRCINVERT_8bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nW
        BYTE* srcp;
        BYTE* dstp;
                
+       if (!hdcSrc || !hdcDest)
+               return 1;
+
        for (y = 0; y < nHeight; y++)
        {
                srcp = gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y);
@@ -271,6 +286,9 @@ static int BitBlt_SRCAND_8bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidt
        BYTE* srcp;
        BYTE* dstp;
                
+       if (!hdcSrc || !hdcDest)
+               return 1;
+
        for (y = 0; y < nHeight; y++)
        {
                srcp = gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y);
@@ -296,6 +314,9 @@ static int BitBlt_SRCPAINT_8bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWi
        BYTE* srcp;
        BYTE* dstp;
                
+       if (!hdcSrc || !hdcDest)
+               return 1;
+
        for (y = 0; y < nHeight; y++)
        {
                srcp = gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y);
@@ -317,6 +338,9 @@ static int BitBlt_SRCPAINT_8bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWi
 
 static int BitBlt_DSPDxax_8bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HGDI_DC hdcSrc, int nXSrc, int nYSrc)
 {
+       if (!hdcSrc || !hdcDest)
+               return 1;
+
        /* TODO: Implement 8bpp DSPDxax BitBlt */
        return 0;
 }
@@ -329,6 +353,9 @@ static int BitBlt_PSDPxax_8bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWid
        BYTE* patp;
        BYTE color8;
 
+       if (!hdcSrc || !hdcDest)
+               return 1;
+
        /* D = (S & D) | (~S & P) */
 
        if (hdcDest->brush->style == GDI_BS_SOLID)
@@ -382,6 +409,9 @@ static int BitBlt_SPna_8bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth,
        BYTE* dstp;
        BYTE* patp;
        
+       if (!hdcSrc || !hdcDest)
+               return 1;
+
        for (y = 0; y < nHeight; y++)
        {
                srcp = gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y);
@@ -461,6 +491,9 @@ static int BitBlt_DSna_8bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth,
        BYTE* srcp;
        BYTE* dstp;
 
+       if (!hdcSrc || !hdcDest)
+               return 1;
+
        for (y = 0; y < nHeight; y++)
        {
                srcp = gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y);
@@ -487,6 +520,9 @@ static int BitBlt_MERGECOPY_8bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nW
        BYTE* dstp;
        BYTE* patp;
        
+       if (!hdcSrc || !hdcDest)
+               return 1;
+
        for (y = 0; y < nHeight; y++)
        {
                srcp = gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y);
@@ -515,6 +551,9 @@ static int BitBlt_MERGEPAINT_8bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int n
        BYTE* srcp;
        BYTE* dstp;
        
+       if (!hdcSrc || !hdcDest)
+               return 1;
+
        for (y = 0; y < nHeight; y++)
        {
                srcp = gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y);
@@ -646,6 +685,9 @@ static int BitBlt_PATPAINT_8bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWi
        BYTE* dstp;
        BYTE* patp;
        
+       if (!hdcSrc || !hdcDest)
+               return 1;
+
        for (y = 0; y < nHeight; y++)
        {
                srcp = gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y);
@@ -682,7 +724,10 @@ int BitBlt_8bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight
        }
        
        gdi_InvalidateRegion(hdcDest, nXDest, nYDest, nWidth, nHeight);
-       
+
+       if (!hdcDest)
+               return 1;
+
        switch (rop)
        {
                case GDI_BLACKNESS: