Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dereferencing of potential null pointers #5111

Merged
merged 4 commits into from Dec 27, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 15 additions & 3 deletions src/libImaging/Histo.c
Expand Up @@ -29,10 +29,12 @@
void
ImagingHistogramDelete(ImagingHistogram h)
{
if (h->histogram) {
free(h->histogram);
if (h) {
if (h->histogram) {
free(h->histogram);
}
free(h);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose this change is just to help in theory - but I'll still point out that in practice, with the other changes from this PR, ImagingHistogramDelete never receives a NULL argument.

}
free(h);
}

ImagingHistogram
Expand All @@ -42,11 +44,18 @@ ImagingHistogramNew(Imaging im)

/* Create histogram descriptor */
h = calloc(1, sizeof(struct ImagingHistogramInstance));
if (h == NULL) {
radarhere marked this conversation as resolved.
Show resolved Hide resolved
return NULL;
radarhere marked this conversation as resolved.
Show resolved Hide resolved
}
strncpy(h->mode, im->mode, IMAGING_MODE_LENGTH-1);
h->mode[IMAGING_MODE_LENGTH-1] = 0;

h->bands = im->bands;
h->histogram = calloc(im->pixelsize, 256 * sizeof(long));
if (h->histogram == NULL) {
radarhere marked this conversation as resolved.
Show resolved Hide resolved
free(h);
return NULL;
}

return h;
}
Expand Down Expand Up @@ -75,6 +84,9 @@ ImagingGetHistogram(Imaging im, Imaging imMask, void* minmax)
}

h = ImagingHistogramNew(im);
if (h == NULL) {
radarhere marked this conversation as resolved.
Show resolved Hide resolved
return NULL;
}

if (imMask) {
/* mask */
Expand Down