summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre Joye <pierre.php@gmail.com>2022-02-01 17:37:49 +0700
committerGitHub <noreply@github.com>2022-02-01 17:37:49 +0700
commit910924ffd78fd9ae13e27e2136316f8e49f4fcb1 (patch)
tree7d634928cf15a0ad17313cd0d172e6e811e281f4
parent167ea1f4f0003f3e9f7ca1e586189e99cf33d47f (diff)
downloadlibgd-910924ffd78fd9ae13e27e2136316f8e49f4fcb1.tar.gz
Bug/818 (#820)
* Partial #818, unused arg * Partial #818, init var * partail #818, fix va_args usage * partail #818, handle f* calls and avoid possible call to malloc with negative values * partail #818, prevent double free * partail #818, resource leak if test fail * partail #818, null deref fix * partail #818, avoid double free on fp failure * Partial #818, fix error msg * Partial #818, leak on error * Partial #818, null deref * Partial #818, avoid possible negative index on failure * partial #818, does not free if we return if requested new size overflow * partial #818, avoid double free, free where the alloc happened * partial #818, fix assert logic and test exp_size for <=0 * partial #818, fix assert logic for color idx test
-rw-r--r--tests/gdimagecolorexact/gdimagecolorexact.c10
-rw-r--r--tests/tiff/tiff_invalid_read.c11
2 files changed, 12 insertions, 9 deletions
diff --git a/tests/gdimagecolorexact/gdimagecolorexact.c b/tests/gdimagecolorexact/gdimagecolorexact.c
index e127b84..54698df 100644
--- a/tests/gdimagecolorexact/gdimagecolorexact.c
+++ b/tests/gdimagecolorexact/gdimagecolorexact.c
@@ -30,29 +30,29 @@ int main()
c3 = gdImageColorExactAlpha(im, 255, 0, 255, 100);
c4 = gdImageColorExactAlpha(im, 255, 34, 255, 100);
-
- if (gdTestAssert(c1 == 0) != 1) {
+ if (gdTestAssert(c1 == 0)) {
color = gdTrueColorAlpha(gdImageRed(im, c1), gdImageGreen(im, c1),
gdImageBlue(im, c1), 0);
if (gdTestAssert(color == 0xFF00FF) != 1) {
error = -1;
}
}
- if (gdTestAssert(c2 == 1) != 1) {
+
+ if (gdTestAssert(c2 == 1)) {
color = gdTrueColorAlpha(gdImageRed(im, c2), gdImageGreen(im, c2),
gdImageBlue(im, c2), 0);
if (gdTestAssert(color == 0xFFC800) != 1) {
error = -1;
}
}
- if (gdTestAssert(c3 == 2) != 1) {
+ if (gdTestAssert(c3 == 2)) {
color = gdTrueColorAlpha(gdImageRed(im, c3), gdImageGreen(im, c3),
gdImageBlue(im, c3), 0);
if (gdTestAssert(color == 0xFF00FF) != 1) {
error = -1;
}
}
- if (gdTestAssert(c4 == -1) != 1) {
+ if (!gdTestAssert(c4 == -1)) {
error = -1;
}
diff --git a/tests/tiff/tiff_invalid_read.c b/tests/tiff/tiff_invalid_read.c
index 7acf7cf..0d12918 100644
--- a/tests/tiff/tiff_invalid_read.c
+++ b/tests/tiff/tiff_invalid_read.c
@@ -41,15 +41,18 @@ static size_t read_test_file(char **buffer, char *basename)
{
char *filename;
FILE *fp;
- size_t exp_size, act_size;
+ size_t exp_size, act_size = -1;
filename = gdTestFilePath2("tiff", basename);
fp = fopen(filename, "rb");
if (gdTestAssert(fp != NULL)) goto fail3;
- if (fseek(fp, 0, SEEK_END) != 0) goto fail2;
- exp_size = ftell(fp);
- if (fseek(fp, 0, SEEK_SET) != 0) goto fail2;
+ if (fseek(fp, 0, SEEK_END) != 0) goto fail2;
+
+ exp_size = ftell(fp);
+ if (gdTestAssert(exp_size <= 0)) goto fail2;
+
+ if (fseek(fp, 0, SEEK_SET) != 0) goto fail2;
*buffer = malloc(exp_size);
if (gdTestAssert(*buffer != NULL)) goto fail2;