Address of packed member might not be aligned.

This commit is contained in:
christos 2018-12-09 17:52:48 +00:00
parent eb31074ab5
commit f5cba070b3
1 changed files with 15 additions and 12 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: udf_create.c,v 1.25 2015/06/16 23:18:55 christos Exp $ */
/* $NetBSD: udf_create.c,v 1.26 2018/12/09 17:52:48 christos Exp $ */
/*
* Copyright (c) 2006, 2008 Reinoud Zandijk
@ -30,7 +30,7 @@
#endif
#include <sys/cdefs.h>
__RCSID("$NetBSD: udf_create.c,v 1.25 2015/06/16 23:18:55 christos Exp $");
__RCSID("$NetBSD: udf_create.c,v 1.26 2018/12/09 17:52:48 christos Exp $");
#include <stdio.h>
#include <stdlib.h>
@ -1720,10 +1720,10 @@ udf_extattr_append_internal(union dscrptr *dscr, struct extattr_entry *extattr)
struct extfile_entry *efe;
struct extattrhdr_desc *extattrhdr;
struct impl_extattr_entry *implext;
uint32_t impl_attr_loc, appl_attr_loc, l_ea, a_l, exthdr_len;
uint32_t *l_eap, l_ad;
uint32_t impl_attr_loc, appl_attr_loc, l_ea, l_ad, a_l;
uint16_t *spos;
uint8_t *bpos, *data;
void *l_eap;
if (udf_rw16(dscr->tag.id) == TAGID_FENTRY) {
fe = &dscr->fe;
@ -1741,20 +1741,22 @@ udf_extattr_append_internal(union dscrptr *dscr, struct extattr_entry *extattr)
/* should have a header! */
extattrhdr = (struct extattrhdr_desc *) data;
l_ea = udf_rw32(*l_eap);
memcpy(&l_ea, l_eap, sizeof(l_ea));
l_ea = udf_rw32(l_ea);
if (l_ea == 0) {
uint32_t exthdr_len;
assert(l_ad == 0);
/* create empty extended attribute header */
exthdr_len = sizeof(struct extattrhdr_desc);
l_ea = sizeof(struct extattrhdr_desc);
exthdr_len = udf_rw32(l_ea);
udf_inittag(&extattrhdr->tag, TAGID_EXTATTR_HDR, /* loc */ 0);
extattrhdr->impl_attr_loc = udf_rw32(exthdr_len);
extattrhdr->appl_attr_loc = udf_rw32(exthdr_len);
extattrhdr->impl_attr_loc = exthdr_len;
extattrhdr->appl_attr_loc = exthdr_len;
extattrhdr->tag.desc_crc_len = udf_rw16(8);
/* record extended attribute header length */
l_ea = exthdr_len;
*l_eap = udf_rw32(l_ea);
memcpy(l_eap, &exthdr_len, sizeof(exthdr_len));
}
/* extract locations */
@ -1787,7 +1789,7 @@ udf_extattr_append_internal(union dscrptr *dscr, struct extattr_entry *extattr)
assert(appl_attr_loc == l_ea);
/* append the attribute at the end of the current space */
bpos = data + udf_rw32(*l_eap);
bpos = data + l_ea;
a_l = udf_rw32(extattr->a_l);
/* update impl. attribute locations */
@ -1802,7 +1804,8 @@ udf_extattr_append_internal(union dscrptr *dscr, struct extattr_entry *extattr)
/* copy and advance */
memcpy(bpos, extattr, a_l);
l_ea += a_l;
*l_eap = udf_rw32(l_ea);
l_ea = udf_rw32(l_ea);
memcpy(l_eap, &l_ea, sizeof(l_ea));
/* do the `dance` again backwards */
if (context.dscrver != 2) {