mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-09 13:04:42 +00:00
The raw index buffer content is not guaranteed to be aligned
* Ensure alignment by copying the content into a structure on the stack
This commit is contained in:
parent
ad8c8d9325
commit
ff97778a7a
53
src/index.c
53
src/index.c
@ -1767,35 +1767,42 @@ static size_t read_entry(
|
|||||||
git_index_entry **out, const void *buffer, size_t buffer_size)
|
git_index_entry **out, const void *buffer, size_t buffer_size)
|
||||||
{
|
{
|
||||||
size_t path_length, entry_size;
|
size_t path_length, entry_size;
|
||||||
uint16_t flags_raw;
|
|
||||||
const char *path_ptr;
|
const char *path_ptr;
|
||||||
const struct entry_short *source = buffer;
|
struct entry_short source;
|
||||||
git_index_entry entry = {{0}};
|
git_index_entry entry = {{0}};
|
||||||
|
|
||||||
if (INDEX_FOOTER_SIZE + minimal_entry_size > buffer_size)
|
if (INDEX_FOOTER_SIZE + minimal_entry_size > buffer_size)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
entry.ctime.seconds = (git_time_t)ntohl(source->ctime.seconds);
|
/* buffer is not guaranteed to be aligned */
|
||||||
entry.ctime.nanoseconds = ntohl(source->ctime.nanoseconds);
|
memcpy(&source, buffer, sizeof(struct entry_short));
|
||||||
entry.mtime.seconds = (git_time_t)ntohl(source->mtime.seconds);
|
|
||||||
entry.mtime.nanoseconds = ntohl(source->mtime.nanoseconds);
|
entry.ctime.seconds = (git_time_t)ntohl(source.ctime.seconds);
|
||||||
entry.dev = ntohl(source->dev);
|
entry.ctime.nanoseconds = ntohl(source.ctime.nanoseconds);
|
||||||
entry.ino = ntohl(source->ino);
|
entry.mtime.seconds = (git_time_t)ntohl(source.mtime.seconds);
|
||||||
entry.mode = ntohl(source->mode);
|
entry.mtime.nanoseconds = ntohl(source.mtime.nanoseconds);
|
||||||
entry.uid = ntohl(source->uid);
|
entry.dev = ntohl(source.dev);
|
||||||
entry.gid = ntohl(source->gid);
|
entry.ino = ntohl(source.ino);
|
||||||
entry.file_size = ntohl(source->file_size);
|
entry.mode = ntohl(source.mode);
|
||||||
git_oid_cpy(&entry.id, &source->oid);
|
entry.uid = ntohl(source.uid);
|
||||||
entry.flags = ntohs(source->flags);
|
entry.gid = ntohl(source.gid);
|
||||||
|
entry.file_size = ntohl(source.file_size);
|
||||||
|
git_oid_cpy(&entry.id, &source.oid);
|
||||||
|
entry.flags = ntohs(source.flags);
|
||||||
|
|
||||||
if (entry.flags & GIT_IDXENTRY_EXTENDED) {
|
if (entry.flags & GIT_IDXENTRY_EXTENDED) {
|
||||||
const struct entry_long *source_l = (const struct entry_long *)source;
|
uint16_t flags_raw;
|
||||||
path_ptr = source_l->path;
|
size_t flags_offset;
|
||||||
|
|
||||||
flags_raw = ntohs(source_l->flags_extended);
|
flags_offset = offsetof(struct entry_long, flags_extended);
|
||||||
memcpy(&entry.flags_extended, &flags_raw, 2);
|
memcpy(&flags_raw, (const char *) buffer + flags_offset,
|
||||||
|
sizeof(flags_raw));
|
||||||
|
flags_raw = ntohs(flags_raw);
|
||||||
|
|
||||||
|
memcpy(&entry.flags_extended, &flags_raw, sizeof(flags_raw));
|
||||||
|
path_ptr = (const char *) buffer + offsetof(struct entry_long, path);
|
||||||
} else
|
} else
|
||||||
path_ptr = source->path;
|
path_ptr = (const char *) buffer + offsetof(struct entry_short, path);
|
||||||
|
|
||||||
path_length = entry.flags & GIT_IDXENTRY_NAMEMASK;
|
path_length = entry.flags & GIT_IDXENTRY_NAMEMASK;
|
||||||
|
|
||||||
@ -1846,14 +1853,12 @@ static int read_header(struct index_header *dest, const void *buffer)
|
|||||||
|
|
||||||
static size_t read_extension(git_index *index, const char *buffer, size_t buffer_size)
|
static size_t read_extension(git_index *index, const char *buffer, size_t buffer_size)
|
||||||
{
|
{
|
||||||
const struct index_extension *source;
|
|
||||||
struct index_extension dest;
|
struct index_extension dest;
|
||||||
size_t total_size;
|
size_t total_size;
|
||||||
|
|
||||||
source = (const struct index_extension *)(buffer);
|
/* buffer is not guaranteed to be aligned */
|
||||||
|
memcpy(&dest, buffer, sizeof(struct index_extension));
|
||||||
memcpy(dest.signature, source->signature, 4);
|
dest.extension_size = ntohl(dest.extension_size);
|
||||||
dest.extension_size = ntohl(source->extension_size);
|
|
||||||
|
|
||||||
total_size = dest.extension_size + sizeof(struct index_extension);
|
total_size = dest.extension_size + sizeof(struct index_extension);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user