]> git.pld-linux.org Git - packages/gd.git/blob - gd-2.2.5-null-pointer.patch
- rel 5; fixes from FC
[packages/gd.git] / gd-2.2.5-null-pointer.patch
1 From a93eac0e843148dc2d631c3ba80af17e9c8c860f Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?F=C3=A1bio=20Cabral=20Pacheco?= <fcabralpacheco@gmail.com>
3 Date: Fri, 20 Dec 2019 12:03:33 -0300
4 Subject: [PATCH] Fix potential NULL pointer dereference in gdImageClone()
5
6 ---
7  src/gd.c                          |  9 +--------
8  tests/gdimageclone/style.c        | 30 ++++++++++++++++++++++++++++++
9  5 files changed, 35 insertions(+), 9 deletions(-)
10  create mode 100644 tests/gdimageclone/style.c
11
12 diff --git a/src/gd.c b/src/gd.c
13 index 592a0286..d564d1f9 100644
14 --- a/src/gd.c
15 +++ b/src/gd.c
16 @@ -2865,14 +2865,6 @@ BGD_DECLARE(gdImagePtr) gdImageClone (gdImagePtr src) {
17                 }
18         }
19  
20 -       if (src->styleLength > 0) {
21 -               dst->styleLength = src->styleLength;
22 -               dst->stylePos    = src->stylePos;
23 -               for (i = 0; i < src->styleLength; i++) {
24 -                       dst->style[i] = src->style[i];
25 -               }
26 -       }
27 -
28         dst->interlace   = src->interlace;
29  
30         dst->alphaBlendingFlag = src->alphaBlendingFlag;
31 @@ -2907,6 +2899,7 @@ BGD_DECLARE(gdImagePtr) gdImageClone (gdImagePtr src) {
32  
33         if (src->style) {
34                 gdImageSetStyle(dst, src->style, src->styleLength);
35 +               dst->stylePos = src->stylePos;
36         }
37  
38         for (i = 0; i < gdMaxColors; i++) {
39 diff --git a/tests/gdimageclone/style.c b/tests/gdimageclone/style.c
40 new file mode 100644
41 index 00000000..c2b246ed
42 --- /dev/null
43 +++ b/tests/gdimageclone/style.c
44 @@ -0,0 +1,30 @@
45 +/**
46 + * Cloning an image should exactly reproduce all style related data
47 + */
48 +
49 +
50 +#include <string.h>
51 +#include "gd.h"
52 +#include "gdtest.h"
53 +
54 +
55 +int main()
56 +{
57 +    gdImagePtr im, clone;
58 +    int style[] = {0, 0, 0};
59 +
60 +    im = gdImageCreate(8, 8);
61 +    gdImageSetStyle(im, style, sizeof(style)/sizeof(style[0]));
62 +
63 +    clone = gdImageClone(im);
64 +    gdTestAssert(clone != NULL);
65 +
66 +    gdTestAssert(clone->styleLength == im->styleLength);
67 +    gdTestAssert(clone->stylePos == im->stylePos);
68 +    gdTestAssert(!memcmp(clone->style, im->style, sizeof(style)/sizeof(style[0])));
69 +
70 +    gdImageDestroy(clone);
71 +    gdImageDestroy(im);
72 +
73 +    return gdNumFailures();
74 +}
This page took 0.071169 seconds and 3 git commands to generate.