Skip to content

Conversation

@igoropaniuk
Copy link
Contributor

No description provided.

The original `part_entry_lba` field in `struct gpt_header` is uint64_t.
A 64-bit unsigned integer can be up to 18446744073709551615 -> 20
digits, so lba_buf should be at least 21 bytes(including '\0').

Redefine local `lba` as uint64_t, increase lba_buf size, and
use snprintf() instead of sprintf().

Signed-off-by: Igor Opaniuk <[email protected]>
Check malloc() return value for a sector buffer.

Signed-off-by: Igor Opaniuk <[email protected]>
Check malloc() return value in load_sahara_image() implementation.

Signed-off-by: Igor Opaniuk <[email protected]>
Properly free all allocated resources in decode_programmer_archive()
if failure occurs.

Signed-off-by: Igor Opaniuk <[email protected]>
@igoropaniuk
Copy link
Contributor Author

@lumag @andersson @konradybcio could you take a look please

* even if some images aren't initialized, it's safe to enumerate over each
* image and try to free, as otherwise image[i] will be filled with zeros.
*
* first image isn't freed if error occurred
Copy link
Contributor

Choose a reason for hiding this comment

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

Why?

Copy link
Collaborator

Choose a reason for hiding this comment

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

The kernel-doc answers this question... making this comment a bit weird.

Copy link
Collaborator

@andersson andersson left a comment

Choose a reason for hiding this comment

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

None of the three malloc/free patches contains motivation to why we should fix it up. Please include your motivation, so that others know why these changes matters and why they should do the same.

}
}

free(buf);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think replacing the malloc() with alloca() would be cleaner, then we don't have to explicitly free the memory (and we don't need the NULL check...)

continue;

return 1;
if (images[i].ptr)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Calling free(NULL) is valid, so no need for the extra conditionals.

blob->len = 0;
/*
* even if some images aren't initialized, it's safe to enumerate over each
* image and try to free, as otherwise image[i] will be filled with zeros.
Copy link
Collaborator

Choose a reason for hiding this comment

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

If needed, this would better be added to the comment above the function, stating that the images array must be zero-initialized (but I don't think it's necessary to document that).

* even if some images aren't initialized, it's safe to enumerate over each
* image and try to free, as otherwise image[i] will be filled with zeros.
*
* first image isn't freed if error occurred
Copy link
Collaborator

Choose a reason for hiding this comment

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

The kernel-doc answers this question... making this comment a bit weird.

* first image isn't freed if error occurred
*/
for (size_t i = 0; i < MAPPING_SZ; i++) {
if (ret != 1 && i == 0)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please see if you can write this in a less clever way, or perhaps add the comment here.

if (images[i].ptr)
free(images[i].ptr);
if (images[i].name)
free((void *)images[i].name);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Perhaps drop the const instead of type casting here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants