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

Safer checking pointers before use, as well check malloc result #19036

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 14 additions & 0 deletions Common/Data/Format/PNGLoad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ int pngLoad(const char *file, int *pwidth, int *pheight, unsigned char **image_d

int stride = PNG_IMAGE_ROW_STRIDE(png);
*image_data_ptr = (unsigned char *)malloc(PNG_IMAGE_SIZE(png));
if (!image_data_ptr)
{
WARN_LOG(IO, "pngLoad: %s (%s)", png.message, file);
*image_data_ptr = nullptr;
Copy link
Owner

Choose a reason for hiding this comment

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

What's this supposed to do? This seems to be a write to null.

return 0;
}

png_image_finish_read(&png, NULL, *image_data_ptr, stride, NULL);
return 1;
}
Expand Down Expand Up @@ -56,6 +63,13 @@ int pngLoadPtr(const unsigned char *input_ptr, size_t input_len, int *pwidth, in
}

*image_data_ptr = (unsigned char *)malloc(size);
if (!image_data_ptr)
{
ERROR_LOG(IO, "pngLoad: malloc image_data_ptr failed");
*image_data_ptr = nullptr;
Copy link
Owner

Choose a reason for hiding this comment

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

This too. will crash.

return 0;
}

png_image_finish_read(&png, NULL, *image_data_ptr, stride, NULL);
return 1;
}
Expand Down
3 changes: 3 additions & 0 deletions Common/UI/Screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ void ScreenManager::switchToNext() {
Layer temp = {nullptr, 0};
if (!stack_.empty()) {
temp = stack_.back();
if (!temp.screen) {
ERROR_LOG(SYSTEM, "switchToNext: No temp.screen!");
}
temp.screen->focusChanged(ScreenFocusChange::FOCUS_LOST_TOP);
stack_.pop_back();
}
Expand Down
2 changes: 1 addition & 1 deletion Core/HLE/__sceAudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ void __AudioUpdate(bool resetRecording) {
auto read = [&](size_t i) {
if (i < sz1)
return buf1[i];
if (i < sz1 + sz2)
if (buf2 && (i < sz1 + sz2))
return buf2[i - sz1];
if (buf2)
return buf2[sz2 - 1];
Expand Down