Print this page
rm code review
*** 33,42 ****
--- 33,50 ----
#include <sys/mman.h>
#include <ctf_impl.h>
#include <sys/debug.h>
/*
+ * SSIZE_MAX is not available in the kernel, so we define it here rather than
+ * accidentally inject into headers where it's not wanted.
+ */
+ #ifndef SSIZE_MAX
+ #define SSIZE_MAX (LONG_MAX)
+ #endif
+
+ /*
* This static string is used as the template for initially populating a
* dynamic container's string table. We always store \0 in the first byte,
* and we use the generic string "PARENT" to mark this container's parent
* if one is associated with the container using ctf_import().
*/
*** 1256,1265 ****
--- 1264,1277 ----
ctf_hash_t *hp = &fp->ctf_enums;
ctf_helem_t *hep = NULL;
ctf_dtdef_t *dtd = NULL;
ctf_id_t type = CTF_ERR;
+ /* Check we could return something valid in ctf_type_size. */
+ if (size > SSIZE_MAX)
+ return (ctf_set_errno(fp, EINVAL));
+
if (name != NULL)
hep = ctf_hash_lookup(hp, fp, name, strlen(name));
if (hep != NULL && ctf_type_kind(fp, hep->h_type) == CTF_K_FORWARD) {
type = hep->h_type;
*** 1275,1294 ****
}
VERIFY(type != CTF_ERR);
dtd->dtd_data.ctt_info = CTF_TYPE_INFO(CTF_K_ENUM, flag, 0);
! if (size == 0) {
! dtd->dtd_data.ctt_size = fp->ctf_dmodel->ctd_int;
! } else {
! if (size > CTF_MAX_SIZE) {
! dtd->dtd_data.ctt_size = CTF_LSIZE_SENT;
! dtd->dtd_data.ctt_lsizehi = CTF_SIZE_TO_LSIZE_HI(size);
! dtd->dtd_data.ctt_lsizelo = CTF_SIZE_TO_LSIZE_LO(size);
! } else
! dtd->dtd_data.ctt_size = size;
! }
/*
* Always dirty in case we modified a forward.
*/
fp->ctf_flags |= LCTF_DIRTY;
--- 1287,1298 ----
}
VERIFY(type != CTF_ERR);
dtd->dtd_data.ctt_info = CTF_TYPE_INFO(CTF_K_ENUM, flag, 0);
! ctf_set_ctt_size(&dtd->dtd_data, size == 0 ?
! fp->ctf_dmodel->ctd_int : size);
/*
* Always dirty in case we modified a forward.
*/
fp->ctf_flags |= LCTF_DIRTY;
*** 1563,1578 ****
dmd->dmd_offset = 0;
ssize = ctf_get_ctt_size(fp, &dtd->dtd_data, NULL, NULL);
ssize = MAX(ssize, msize);
}
! if (ssize > CTF_MAX_SIZE) {
! dtd->dtd_data.ctt_size = CTF_LSIZE_SENT;
! dtd->dtd_data.ctt_lsizehi = CTF_SIZE_TO_LSIZE_HI(ssize);
! dtd->dtd_data.ctt_lsizelo = CTF_SIZE_TO_LSIZE_LO(ssize);
! } else
! dtd->dtd_data.ctt_size = (ushort_t)ssize;
dtd->dtd_data.ctt_info = CTF_TYPE_INFO(kind, root, vlen + 1);
ctf_list_append(&dtd->dtd_u.dtu_members, dmd);
if (s != NULL)
--- 1567,1577 ----
dmd->dmd_offset = 0;
ssize = ctf_get_ctt_size(fp, &dtd->dtd_data, NULL, NULL);
ssize = MAX(ssize, msize);
}
! ctf_set_ctt_size(&dtd->dtd_data, ssize);
dtd->dtd_data.ctt_info = CTF_TYPE_INFO(kind, root, vlen + 1);
ctf_list_append(&dtd->dtd_u.dtu_members, dmd);
if (s != NULL)
*** 1705,1715 ****
ctf_encoding_t src_en, dst_en;
ctf_arinfo_t src_ar, dst_ar;
ctf_dtdef_t *dtd;
ctf_funcinfo_t ctc;
- ssize_t size;
ctf_hash_t *hp;
ctf_helem_t *hep;
if (dst_fp == src_fp)
--- 1704,1713 ----
*** 1900,1915 ****
dst.ctb_dtd = dtd;
if (ctf_member_iter(src_fp, src_type, membadd, &dst) != 0)
errs++; /* increment errs and fail at bottom of case */
! if ((size = ctf_type_size(src_fp, src_type)) > CTF_MAX_SIZE) {
! dtd->dtd_data.ctt_size = CTF_LSIZE_SENT;
! dtd->dtd_data.ctt_lsizehi = CTF_SIZE_TO_LSIZE_HI(size);
! dtd->dtd_data.ctt_lsizelo = CTF_SIZE_TO_LSIZE_LO(size);
! } else
! dtd->dtd_data.ctt_size = (ushort_t)size;
dtd->dtd_data.ctt_info = CTF_TYPE_INFO(kind, flag, vlen);
/*
* Make a final pass through the members changing each dmd_type
--- 1898,1909 ----
dst.ctb_dtd = dtd;
if (ctf_member_iter(src_fp, src_type, membadd, &dst) != 0)
errs++; /* increment errs and fail at bottom of case */
! ctf_set_ctt_size(&dtd->dtd_data,
! ctf_type_size(src_fp, src_type));
dtd->dtd_data.ctt_info = CTF_TYPE_INFO(kind, flag, vlen);
/*
* Make a final pass through the members changing each dmd_type
*** 1940,1950 ****
if (dst_type != CTF_ERR && dst_kind != CTF_K_FORWARD) {
if (ctf_enum_iter(src_fp, src_type, enumcmp, &dst) ||
ctf_enum_iter(dst_fp, dst_type, enumcmp, &src))
return (ctf_set_errno(dst_fp, ECTF_CONFLICT));
} else {
! size_t size = ctf_type_size(src_fp, src_type);
dst_type = ctf_add_enum(dst_fp, flag, name, size);
if ((dst.ctb_type = dst_type) == CTF_ERR ||
ctf_enum_iter(src_fp, src_type, enumadd, &dst))
return (CTF_ERR); /* errno is set for us */
}
--- 1934,1948 ----
if (dst_type != CTF_ERR && dst_kind != CTF_K_FORWARD) {
if (ctf_enum_iter(src_fp, src_type, enumcmp, &dst) ||
ctf_enum_iter(dst_fp, dst_type, enumcmp, &src))
return (ctf_set_errno(dst_fp, ECTF_CONFLICT));
} else {
! ssize_t size = ctf_type_size(src_fp, src_type);
!
! if (size == CTF_ERR)
! return (CTF_ERR); /* errno is set for us */
!
dst_type = ctf_add_enum(dst_fp, flag, name, size);
if ((dst.ctb_type = dst_type) == CTF_ERR ||
ctf_enum_iter(src_fp, src_type, enumadd, &dst))
return (CTF_ERR); /* errno is set for us */
}
*** 2178,2194 ****
oldsz = CTF_TYPE_LSIZE(&dtd->dtd_data);
if (newsz < oldsz)
return (ctf_set_errno(fp, EINVAL));
! if (newsz > CTF_MAX_SIZE) {
! dtd->dtd_data.ctt_size = CTF_LSIZE_SENT;
! dtd->dtd_data.ctt_lsizehi = CTF_SIZE_TO_LSIZE_HI(newsz);
! dtd->dtd_data.ctt_lsizelo = CTF_SIZE_TO_LSIZE_LO(newsz);
! } else {
! dtd->dtd_data.ctt_size = (ushort_t)newsz;
! }
fp->ctf_flags |= LCTF_DIRTY;
return (0);
}
--- 2176,2186 ----
oldsz = CTF_TYPE_LSIZE(&dtd->dtd_data);
if (newsz < oldsz)
return (ctf_set_errno(fp, EINVAL));
! ctf_set_ctt_size(&dtd->dtd_data, newsz);
fp->ctf_flags |= LCTF_DIRTY;
return (0);
}