idx int64 | func_before string | Vulnerability Classification string | vul int64 | func_after string | patch string | CWE ID string | lines_before string | lines_after string |
|---|---|---|---|---|---|---|---|---|
12,700 | static void virtio_net_guest_notifier_mask(VirtIODevice *vdev, int idx,
bool mask)
{
VirtIONet *n = VIRTIO_NET(vdev);
NetClientState *nc = qemu_get_subqueue(n->nic, vq2q(idx));
assert(n->vhost_started);
vhost_net_virtqueue_mask(tap_get_vhost_net(nc->peer),
vdev, idx, mask);
}
| DoS Exec Code Overflow | 0 | static void virtio_net_guest_notifier_mask(VirtIODevice *vdev, int idx,
bool mask)
{
VirtIONet *n = VIRTIO_NET(vdev);
NetClientState *nc = qemu_get_subqueue(n->nic, vq2q(idx));
assert(n->vhost_started);
vhost_net_virtqueue_mask(tap_get_vhost_net(nc->peer),
vdev, idx, mask);
}
| @@ -1407,6 +1407,11 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int version_id)
}
n->curr_queues = qemu_get_be16(f);
+ if (n->curr_queues > n->max_queues) {
+ error_report("virtio-net: curr_queues %x > max_queues %x",
+ n->curr_queues, n->max_queues);
+ return -1;
+ }
for (i = 1; i < n->curr_queues; i++) {
n->vqs[i].tx_waiting = qemu_get_be32(f);
} | CWE-119 | null | null |
12,701 | static bool virtio_net_guest_notifier_pending(VirtIODevice *vdev, int idx)
{
VirtIONet *n = VIRTIO_NET(vdev);
NetClientState *nc = qemu_get_subqueue(n->nic, vq2q(idx));
assert(n->vhost_started);
return vhost_net_virtqueue_pending(tap_get_vhost_net(nc->peer), idx);
}
| DoS Exec Code Overflow | 0 | static bool virtio_net_guest_notifier_pending(VirtIODevice *vdev, int idx)
{
VirtIONet *n = VIRTIO_NET(vdev);
NetClientState *nc = qemu_get_subqueue(n->nic, vq2q(idx));
assert(n->vhost_started);
return vhost_net_virtqueue_pending(tap_get_vhost_net(nc->peer), idx);
}
| @@ -1407,6 +1407,11 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int version_id)
}
n->curr_queues = qemu_get_be16(f);
+ if (n->curr_queues > n->max_queues) {
+ error_report("virtio-net: curr_queues %x > max_queues %x",
+ n->curr_queues, n->max_queues);
+ return -1;
+ }
for (i = 1; i < n->curr_queues; i++) {
n->vqs[i].tx_waiting = qemu_get_be32(f);
} | CWE-119 | null | null |
12,702 | static uint64_t virtio_net_guest_offloads_by_features(uint32_t features)
{
static const uint64_t guest_offloads_mask =
(1ULL << VIRTIO_NET_F_GUEST_CSUM) |
(1ULL << VIRTIO_NET_F_GUEST_TSO4) |
(1ULL << VIRTIO_NET_F_GUEST_TSO6) |
(1ULL << VIRTIO_NET_F_GUEST_ECN) |
(1ULL << VIRTIO_NET_F_GUEST_UFO);
return guest_offloads_mask & features;
}
| DoS Exec Code Overflow | 0 | static uint64_t virtio_net_guest_offloads_by_features(uint32_t features)
{
static const uint64_t guest_offloads_mask =
(1ULL << VIRTIO_NET_F_GUEST_CSUM) |
(1ULL << VIRTIO_NET_F_GUEST_TSO4) |
(1ULL << VIRTIO_NET_F_GUEST_TSO6) |
(1ULL << VIRTIO_NET_F_GUEST_ECN) |
(1ULL << VIRTIO_NET_F_GUEST_UFO);
return guest_offloads_mask & features;
}
| @@ -1407,6 +1407,11 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int version_id)
}
n->curr_queues = qemu_get_be16(f);
+ if (n->curr_queues > n->max_queues) {
+ error_report("virtio-net: curr_queues %x > max_queues %x",
+ n->curr_queues, n->max_queues);
+ return -1;
+ }
for (i = 1; i < n->curr_queues; i++) {
n->vqs[i].tx_waiting = qemu_get_be32(f);
} | CWE-119 | null | null |
12,703 | static void virtio_net_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq)
{
VirtIONet *n = VIRTIO_NET(vdev);
struct virtio_net_ctrl_hdr ctrl;
virtio_net_ctrl_ack status = VIRTIO_NET_ERR;
VirtQueueElement elem;
size_t s;
struct iovec *iov;
unsigned int iov_cnt;
while (virtqueue_pop(vq, &elem)) {
if (iov_size(elem.in_sg, elem.in_num) < sizeof(status) ||
iov_size(elem.out_sg, elem.out_num) < sizeof(ctrl)) {
error_report("virtio-net ctrl missing headers");
exit(1);
}
iov = elem.out_sg;
iov_cnt = elem.out_num;
s = iov_to_buf(iov, iov_cnt, 0, &ctrl, sizeof(ctrl));
iov_discard_front(&iov, &iov_cnt, sizeof(ctrl));
if (s != sizeof(ctrl)) {
status = VIRTIO_NET_ERR;
} else if (ctrl.class == VIRTIO_NET_CTRL_RX) {
status = virtio_net_handle_rx_mode(n, ctrl.cmd, iov, iov_cnt);
} else if (ctrl.class == VIRTIO_NET_CTRL_MAC) {
status = virtio_net_handle_mac(n, ctrl.cmd, iov, iov_cnt);
} else if (ctrl.class == VIRTIO_NET_CTRL_VLAN) {
status = virtio_net_handle_vlan_table(n, ctrl.cmd, iov, iov_cnt);
} else if (ctrl.class == VIRTIO_NET_CTRL_MQ) {
status = virtio_net_handle_mq(n, ctrl.cmd, iov, iov_cnt);
} else if (ctrl.class == VIRTIO_NET_CTRL_GUEST_OFFLOADS) {
status = virtio_net_handle_offloads(n, ctrl.cmd, iov, iov_cnt);
}
s = iov_from_buf(elem.in_sg, elem.in_num, 0, &status, sizeof(status));
assert(s == sizeof(status));
virtqueue_push(vq, &elem, sizeof(status));
virtio_notify(vdev, vq);
}
}
| DoS Exec Code Overflow | 0 | static void virtio_net_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq)
{
VirtIONet *n = VIRTIO_NET(vdev);
struct virtio_net_ctrl_hdr ctrl;
virtio_net_ctrl_ack status = VIRTIO_NET_ERR;
VirtQueueElement elem;
size_t s;
struct iovec *iov;
unsigned int iov_cnt;
while (virtqueue_pop(vq, &elem)) {
if (iov_size(elem.in_sg, elem.in_num) < sizeof(status) ||
iov_size(elem.out_sg, elem.out_num) < sizeof(ctrl)) {
error_report("virtio-net ctrl missing headers");
exit(1);
}
iov = elem.out_sg;
iov_cnt = elem.out_num;
s = iov_to_buf(iov, iov_cnt, 0, &ctrl, sizeof(ctrl));
iov_discard_front(&iov, &iov_cnt, sizeof(ctrl));
if (s != sizeof(ctrl)) {
status = VIRTIO_NET_ERR;
} else if (ctrl.class == VIRTIO_NET_CTRL_RX) {
status = virtio_net_handle_rx_mode(n, ctrl.cmd, iov, iov_cnt);
} else if (ctrl.class == VIRTIO_NET_CTRL_MAC) {
status = virtio_net_handle_mac(n, ctrl.cmd, iov, iov_cnt);
} else if (ctrl.class == VIRTIO_NET_CTRL_VLAN) {
status = virtio_net_handle_vlan_table(n, ctrl.cmd, iov, iov_cnt);
} else if (ctrl.class == VIRTIO_NET_CTRL_MQ) {
status = virtio_net_handle_mq(n, ctrl.cmd, iov, iov_cnt);
} else if (ctrl.class == VIRTIO_NET_CTRL_GUEST_OFFLOADS) {
status = virtio_net_handle_offloads(n, ctrl.cmd, iov, iov_cnt);
}
s = iov_from_buf(elem.in_sg, elem.in_num, 0, &status, sizeof(status));
assert(s == sizeof(status));
virtqueue_push(vq, &elem, sizeof(status));
virtio_notify(vdev, vq);
}
}
| @@ -1407,6 +1407,11 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int version_id)
}
n->curr_queues = qemu_get_be16(f);
+ if (n->curr_queues > n->max_queues) {
+ error_report("virtio-net: curr_queues %x > max_queues %x",
+ n->curr_queues, n->max_queues);
+ return -1;
+ }
for (i = 1; i < n->curr_queues; i++) {
n->vqs[i].tx_waiting = qemu_get_be32(f);
} | CWE-119 | null | null |
12,704 | static int virtio_net_handle_mac(VirtIONet *n, uint8_t cmd,
struct iovec *iov, unsigned int iov_cnt)
{
struct virtio_net_ctrl_mac mac_data;
size_t s;
NetClientState *nc = qemu_get_queue(n->nic);
if (cmd == VIRTIO_NET_CTRL_MAC_ADDR_SET) {
if (iov_size(iov, iov_cnt) != sizeof(n->mac)) {
return VIRTIO_NET_ERR;
}
s = iov_to_buf(iov, iov_cnt, 0, &n->mac, sizeof(n->mac));
assert(s == sizeof(n->mac));
qemu_format_nic_info_str(qemu_get_queue(n->nic), n->mac);
rxfilter_notify(nc);
return VIRTIO_NET_OK;
}
if (cmd != VIRTIO_NET_CTRL_MAC_TABLE_SET) {
return VIRTIO_NET_ERR;
}
int in_use = 0;
int first_multi = 0;
uint8_t uni_overflow = 0;
uint8_t multi_overflow = 0;
uint8_t *macs = g_malloc0(MAC_TABLE_ENTRIES * ETH_ALEN);
s = iov_to_buf(iov, iov_cnt, 0, &mac_data.entries,
sizeof(mac_data.entries));
mac_data.entries = ldl_p(&mac_data.entries);
if (s != sizeof(mac_data.entries)) {
goto error;
}
iov_discard_front(&iov, &iov_cnt, s);
if (mac_data.entries * ETH_ALEN > iov_size(iov, iov_cnt)) {
goto error;
}
if (mac_data.entries <= MAC_TABLE_ENTRIES) {
s = iov_to_buf(iov, iov_cnt, 0, macs,
mac_data.entries * ETH_ALEN);
if (s != mac_data.entries * ETH_ALEN) {
goto error;
}
in_use += mac_data.entries;
} else {
uni_overflow = 1;
}
iov_discard_front(&iov, &iov_cnt, mac_data.entries * ETH_ALEN);
first_multi = in_use;
s = iov_to_buf(iov, iov_cnt, 0, &mac_data.entries,
sizeof(mac_data.entries));
mac_data.entries = ldl_p(&mac_data.entries);
if (s != sizeof(mac_data.entries)) {
goto error;
}
iov_discard_front(&iov, &iov_cnt, s);
if (mac_data.entries * ETH_ALEN != iov_size(iov, iov_cnt)) {
goto error;
}
if (mac_data.entries <= MAC_TABLE_ENTRIES - in_use) {
s = iov_to_buf(iov, iov_cnt, 0, &macs[in_use * ETH_ALEN],
mac_data.entries * ETH_ALEN);
if (s != mac_data.entries * ETH_ALEN) {
goto error;
}
in_use += mac_data.entries;
} else {
multi_overflow = 1;
}
n->mac_table.in_use = in_use;
n->mac_table.first_multi = first_multi;
n->mac_table.uni_overflow = uni_overflow;
n->mac_table.multi_overflow = multi_overflow;
memcpy(n->mac_table.macs, macs, MAC_TABLE_ENTRIES * ETH_ALEN);
g_free(macs);
rxfilter_notify(nc);
return VIRTIO_NET_OK;
error:
g_free(macs);
return VIRTIO_NET_ERR;
}
| DoS Exec Code Overflow | 0 | static int virtio_net_handle_mac(VirtIONet *n, uint8_t cmd,
struct iovec *iov, unsigned int iov_cnt)
{
struct virtio_net_ctrl_mac mac_data;
size_t s;
NetClientState *nc = qemu_get_queue(n->nic);
if (cmd == VIRTIO_NET_CTRL_MAC_ADDR_SET) {
if (iov_size(iov, iov_cnt) != sizeof(n->mac)) {
return VIRTIO_NET_ERR;
}
s = iov_to_buf(iov, iov_cnt, 0, &n->mac, sizeof(n->mac));
assert(s == sizeof(n->mac));
qemu_format_nic_info_str(qemu_get_queue(n->nic), n->mac);
rxfilter_notify(nc);
return VIRTIO_NET_OK;
}
if (cmd != VIRTIO_NET_CTRL_MAC_TABLE_SET) {
return VIRTIO_NET_ERR;
}
int in_use = 0;
int first_multi = 0;
uint8_t uni_overflow = 0;
uint8_t multi_overflow = 0;
uint8_t *macs = g_malloc0(MAC_TABLE_ENTRIES * ETH_ALEN);
s = iov_to_buf(iov, iov_cnt, 0, &mac_data.entries,
sizeof(mac_data.entries));
mac_data.entries = ldl_p(&mac_data.entries);
if (s != sizeof(mac_data.entries)) {
goto error;
}
iov_discard_front(&iov, &iov_cnt, s);
if (mac_data.entries * ETH_ALEN > iov_size(iov, iov_cnt)) {
goto error;
}
if (mac_data.entries <= MAC_TABLE_ENTRIES) {
s = iov_to_buf(iov, iov_cnt, 0, macs,
mac_data.entries * ETH_ALEN);
if (s != mac_data.entries * ETH_ALEN) {
goto error;
}
in_use += mac_data.entries;
} else {
uni_overflow = 1;
}
iov_discard_front(&iov, &iov_cnt, mac_data.entries * ETH_ALEN);
first_multi = in_use;
s = iov_to_buf(iov, iov_cnt, 0, &mac_data.entries,
sizeof(mac_data.entries));
mac_data.entries = ldl_p(&mac_data.entries);
if (s != sizeof(mac_data.entries)) {
goto error;
}
iov_discard_front(&iov, &iov_cnt, s);
if (mac_data.entries * ETH_ALEN != iov_size(iov, iov_cnt)) {
goto error;
}
if (mac_data.entries <= MAC_TABLE_ENTRIES - in_use) {
s = iov_to_buf(iov, iov_cnt, 0, &macs[in_use * ETH_ALEN],
mac_data.entries * ETH_ALEN);
if (s != mac_data.entries * ETH_ALEN) {
goto error;
}
in_use += mac_data.entries;
} else {
multi_overflow = 1;
}
n->mac_table.in_use = in_use;
n->mac_table.first_multi = first_multi;
n->mac_table.uni_overflow = uni_overflow;
n->mac_table.multi_overflow = multi_overflow;
memcpy(n->mac_table.macs, macs, MAC_TABLE_ENTRIES * ETH_ALEN);
g_free(macs);
rxfilter_notify(nc);
return VIRTIO_NET_OK;
error:
g_free(macs);
return VIRTIO_NET_ERR;
}
| @@ -1407,6 +1407,11 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int version_id)
}
n->curr_queues = qemu_get_be16(f);
+ if (n->curr_queues > n->max_queues) {
+ error_report("virtio-net: curr_queues %x > max_queues %x",
+ n->curr_queues, n->max_queues);
+ return -1;
+ }
for (i = 1; i < n->curr_queues; i++) {
n->vqs[i].tx_waiting = qemu_get_be32(f);
} | CWE-119 | null | null |
12,705 | static void virtio_net_handle_rx(VirtIODevice *vdev, VirtQueue *vq)
{
VirtIONet *n = VIRTIO_NET(vdev);
int queue_index = vq2q(virtio_get_queue_index(vq));
qemu_flush_queued_packets(qemu_get_subqueue(n->nic, queue_index));
}
| DoS Exec Code Overflow | 0 | static void virtio_net_handle_rx(VirtIODevice *vdev, VirtQueue *vq)
{
VirtIONet *n = VIRTIO_NET(vdev);
int queue_index = vq2q(virtio_get_queue_index(vq));
qemu_flush_queued_packets(qemu_get_subqueue(n->nic, queue_index));
}
| @@ -1407,6 +1407,11 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int version_id)
}
n->curr_queues = qemu_get_be16(f);
+ if (n->curr_queues > n->max_queues) {
+ error_report("virtio-net: curr_queues %x > max_queues %x",
+ n->curr_queues, n->max_queues);
+ return -1;
+ }
for (i = 1; i < n->curr_queues; i++) {
n->vqs[i].tx_waiting = qemu_get_be32(f);
} | CWE-119 | null | null |
12,706 | static int virtio_net_handle_rx_mode(VirtIONet *n, uint8_t cmd,
struct iovec *iov, unsigned int iov_cnt)
{
uint8_t on;
size_t s;
NetClientState *nc = qemu_get_queue(n->nic);
s = iov_to_buf(iov, iov_cnt, 0, &on, sizeof(on));
if (s != sizeof(on)) {
return VIRTIO_NET_ERR;
}
if (cmd == VIRTIO_NET_CTRL_RX_PROMISC) {
n->promisc = on;
} else if (cmd == VIRTIO_NET_CTRL_RX_ALLMULTI) {
n->allmulti = on;
} else if (cmd == VIRTIO_NET_CTRL_RX_ALLUNI) {
n->alluni = on;
} else if (cmd == VIRTIO_NET_CTRL_RX_NOMULTI) {
n->nomulti = on;
} else if (cmd == VIRTIO_NET_CTRL_RX_NOUNI) {
n->nouni = on;
} else if (cmd == VIRTIO_NET_CTRL_RX_NOBCAST) {
n->nobcast = on;
} else {
return VIRTIO_NET_ERR;
}
rxfilter_notify(nc);
return VIRTIO_NET_OK;
}
| DoS Exec Code Overflow | 0 | static int virtio_net_handle_rx_mode(VirtIONet *n, uint8_t cmd,
struct iovec *iov, unsigned int iov_cnt)
{
uint8_t on;
size_t s;
NetClientState *nc = qemu_get_queue(n->nic);
s = iov_to_buf(iov, iov_cnt, 0, &on, sizeof(on));
if (s != sizeof(on)) {
return VIRTIO_NET_ERR;
}
if (cmd == VIRTIO_NET_CTRL_RX_PROMISC) {
n->promisc = on;
} else if (cmd == VIRTIO_NET_CTRL_RX_ALLMULTI) {
n->allmulti = on;
} else if (cmd == VIRTIO_NET_CTRL_RX_ALLUNI) {
n->alluni = on;
} else if (cmd == VIRTIO_NET_CTRL_RX_NOMULTI) {
n->nomulti = on;
} else if (cmd == VIRTIO_NET_CTRL_RX_NOUNI) {
n->nouni = on;
} else if (cmd == VIRTIO_NET_CTRL_RX_NOBCAST) {
n->nobcast = on;
} else {
return VIRTIO_NET_ERR;
}
rxfilter_notify(nc);
return VIRTIO_NET_OK;
}
| @@ -1407,6 +1407,11 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int version_id)
}
n->curr_queues = qemu_get_be16(f);
+ if (n->curr_queues > n->max_queues) {
+ error_report("virtio-net: curr_queues %x > max_queues %x",
+ n->curr_queues, n->max_queues);
+ return -1;
+ }
for (i = 1; i < n->curr_queues; i++) {
n->vqs[i].tx_waiting = qemu_get_be32(f);
} | CWE-119 | null | null |
12,707 | static void virtio_net_handle_tx_timer(VirtIODevice *vdev, VirtQueue *vq)
{
VirtIONet *n = VIRTIO_NET(vdev);
VirtIONetQueue *q = &n->vqs[vq2q(virtio_get_queue_index(vq))];
/* This happens when device was stopped but VCPU wasn't. */
if (!vdev->vm_running) {
q->tx_waiting = 1;
return;
}
if (q->tx_waiting) {
virtio_queue_set_notification(vq, 1);
timer_del(q->tx_timer);
q->tx_waiting = 0;
virtio_net_flush_tx(q);
} else {
timer_mod(q->tx_timer,
qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + n->tx_timeout);
q->tx_waiting = 1;
virtio_queue_set_notification(vq, 0);
}
}
| DoS Exec Code Overflow | 0 | static void virtio_net_handle_tx_timer(VirtIODevice *vdev, VirtQueue *vq)
{
VirtIONet *n = VIRTIO_NET(vdev);
VirtIONetQueue *q = &n->vqs[vq2q(virtio_get_queue_index(vq))];
/* This happens when device was stopped but VCPU wasn't. */
if (!vdev->vm_running) {
q->tx_waiting = 1;
return;
}
if (q->tx_waiting) {
virtio_queue_set_notification(vq, 1);
timer_del(q->tx_timer);
q->tx_waiting = 0;
virtio_net_flush_tx(q);
} else {
timer_mod(q->tx_timer,
qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + n->tx_timeout);
q->tx_waiting = 1;
virtio_queue_set_notification(vq, 0);
}
}
| @@ -1407,6 +1407,11 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int version_id)
}
n->curr_queues = qemu_get_be16(f);
+ if (n->curr_queues > n->max_queues) {
+ error_report("virtio-net: curr_queues %x > max_queues %x",
+ n->curr_queues, n->max_queues);
+ return -1;
+ }
for (i = 1; i < n->curr_queues; i++) {
n->vqs[i].tx_waiting = qemu_get_be32(f);
} | CWE-119 | null | null |
12,708 | static int virtio_net_handle_vlan_table(VirtIONet *n, uint8_t cmd,
struct iovec *iov, unsigned int iov_cnt)
{
uint16_t vid;
size_t s;
NetClientState *nc = qemu_get_queue(n->nic);
s = iov_to_buf(iov, iov_cnt, 0, &vid, sizeof(vid));
vid = lduw_p(&vid);
if (s != sizeof(vid)) {
return VIRTIO_NET_ERR;
}
if (vid >= MAX_VLAN)
return VIRTIO_NET_ERR;
if (cmd == VIRTIO_NET_CTRL_VLAN_ADD)
n->vlans[vid >> 5] |= (1U << (vid & 0x1f));
else if (cmd == VIRTIO_NET_CTRL_VLAN_DEL)
n->vlans[vid >> 5] &= ~(1U << (vid & 0x1f));
else
return VIRTIO_NET_ERR;
rxfilter_notify(nc);
return VIRTIO_NET_OK;
}
| DoS Exec Code Overflow | 0 | static int virtio_net_handle_vlan_table(VirtIONet *n, uint8_t cmd,
struct iovec *iov, unsigned int iov_cnt)
{
uint16_t vid;
size_t s;
NetClientState *nc = qemu_get_queue(n->nic);
s = iov_to_buf(iov, iov_cnt, 0, &vid, sizeof(vid));
vid = lduw_p(&vid);
if (s != sizeof(vid)) {
return VIRTIO_NET_ERR;
}
if (vid >= MAX_VLAN)
return VIRTIO_NET_ERR;
if (cmd == VIRTIO_NET_CTRL_VLAN_ADD)
n->vlans[vid >> 5] |= (1U << (vid & 0x1f));
else if (cmd == VIRTIO_NET_CTRL_VLAN_DEL)
n->vlans[vid >> 5] &= ~(1U << (vid & 0x1f));
else
return VIRTIO_NET_ERR;
rxfilter_notify(nc);
return VIRTIO_NET_OK;
}
| @@ -1407,6 +1407,11 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int version_id)
}
n->curr_queues = qemu_get_be16(f);
+ if (n->curr_queues > n->max_queues) {
+ error_report("virtio-net: curr_queues %x > max_queues %x",
+ n->curr_queues, n->max_queues);
+ return -1;
+ }
for (i = 1; i < n->curr_queues; i++) {
n->vqs[i].tx_waiting = qemu_get_be32(f);
} | CWE-119 | null | null |
12,709 | static int virtio_net_has_buffers(VirtIONetQueue *q, int bufsize)
{
VirtIONet *n = q->n;
if (virtio_queue_empty(q->rx_vq) ||
(n->mergeable_rx_bufs &&
!virtqueue_avail_bytes(q->rx_vq, bufsize, 0))) {
virtio_queue_set_notification(q->rx_vq, 1);
/* To avoid a race condition where the guest has made some buffers
* available after the above check but before notification was
* enabled, check for available buffers again.
*/
if (virtio_queue_empty(q->rx_vq) ||
(n->mergeable_rx_bufs &&
!virtqueue_avail_bytes(q->rx_vq, bufsize, 0))) {
return 0;
}
}
virtio_queue_set_notification(q->rx_vq, 0);
return 1;
}
| DoS Exec Code Overflow | 0 | static int virtio_net_has_buffers(VirtIONetQueue *q, int bufsize)
{
VirtIONet *n = q->n;
if (virtio_queue_empty(q->rx_vq) ||
(n->mergeable_rx_bufs &&
!virtqueue_avail_bytes(q->rx_vq, bufsize, 0))) {
virtio_queue_set_notification(q->rx_vq, 1);
/* To avoid a race condition where the guest has made some buffers
* available after the above check but before notification was
* enabled, check for available buffers again.
*/
if (virtio_queue_empty(q->rx_vq) ||
(n->mergeable_rx_bufs &&
!virtqueue_avail_bytes(q->rx_vq, bufsize, 0))) {
return 0;
}
}
virtio_queue_set_notification(q->rx_vq, 0);
return 1;
}
| @@ -1407,6 +1407,11 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int version_id)
}
n->curr_queues = qemu_get_be16(f);
+ if (n->curr_queues > n->max_queues) {
+ error_report("virtio-net: curr_queues %x > max_queues %x",
+ n->curr_queues, n->max_queues);
+ return -1;
+ }
for (i = 1; i < n->curr_queues; i++) {
n->vqs[i].tx_waiting = qemu_get_be32(f);
} | CWE-119 | null | null |
12,710 | static void virtio_net_instance_init(Object *obj)
{
VirtIONet *n = VIRTIO_NET(obj);
/*
* The default config_size is sizeof(struct virtio_net_config).
* Can be overriden with virtio_net_set_config_size.
*/
n->config_size = sizeof(struct virtio_net_config);
}
| DoS Exec Code Overflow | 0 | static void virtio_net_instance_init(Object *obj)
{
VirtIONet *n = VIRTIO_NET(obj);
/*
* The default config_size is sizeof(struct virtio_net_config).
* Can be overriden with virtio_net_set_config_size.
*/
n->config_size = sizeof(struct virtio_net_config);
}
| @@ -1407,6 +1407,11 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int version_id)
}
n->curr_queues = qemu_get_be16(f);
+ if (n->curr_queues > n->max_queues) {
+ error_report("virtio-net: curr_queues %x > max_queues %x",
+ n->curr_queues, n->max_queues);
+ return -1;
+ }
for (i = 1; i < n->curr_queues; i++) {
n->vqs[i].tx_waiting = qemu_get_be32(f);
} | CWE-119 | null | null |
12,711 | static RxFilterInfo *virtio_net_query_rxfilter(NetClientState *nc)
{
VirtIONet *n = qemu_get_nic_opaque(nc);
VirtIODevice *vdev = VIRTIO_DEVICE(n);
RxFilterInfo *info;
strList *str_list, *entry;
int i;
info = g_malloc0(sizeof(*info));
info->name = g_strdup(nc->name);
info->promiscuous = n->promisc;
if (n->nouni) {
info->unicast = RX_STATE_NONE;
} else if (n->alluni) {
info->unicast = RX_STATE_ALL;
} else {
info->unicast = RX_STATE_NORMAL;
}
if (n->nomulti) {
info->multicast = RX_STATE_NONE;
} else if (n->allmulti) {
info->multicast = RX_STATE_ALL;
} else {
info->multicast = RX_STATE_NORMAL;
}
info->broadcast_allowed = n->nobcast;
info->multicast_overflow = n->mac_table.multi_overflow;
info->unicast_overflow = n->mac_table.uni_overflow;
info->main_mac = mac_strdup_printf(n->mac);
str_list = NULL;
for (i = 0; i < n->mac_table.first_multi; i++) {
entry = g_malloc0(sizeof(*entry));
entry->value = mac_strdup_printf(n->mac_table.macs + i * ETH_ALEN);
entry->next = str_list;
str_list = entry;
}
info->unicast_table = str_list;
str_list = NULL;
for (i = n->mac_table.first_multi; i < n->mac_table.in_use; i++) {
entry = g_malloc0(sizeof(*entry));
entry->value = mac_strdup_printf(n->mac_table.macs + i * ETH_ALEN);
entry->next = str_list;
str_list = entry;
}
info->multicast_table = str_list;
info->vlan_table = get_vlan_table(n);
if (!((1 << VIRTIO_NET_F_CTRL_VLAN) & vdev->guest_features)) {
info->vlan = RX_STATE_ALL;
} else if (!info->vlan_table) {
info->vlan = RX_STATE_NONE;
} else {
info->vlan = RX_STATE_NORMAL;
}
/* enable event notification after query */
nc->rxfilter_notify_enabled = 1;
return info;
}
| DoS Exec Code Overflow | 0 | static RxFilterInfo *virtio_net_query_rxfilter(NetClientState *nc)
{
VirtIONet *n = qemu_get_nic_opaque(nc);
VirtIODevice *vdev = VIRTIO_DEVICE(n);
RxFilterInfo *info;
strList *str_list, *entry;
int i;
info = g_malloc0(sizeof(*info));
info->name = g_strdup(nc->name);
info->promiscuous = n->promisc;
if (n->nouni) {
info->unicast = RX_STATE_NONE;
} else if (n->alluni) {
info->unicast = RX_STATE_ALL;
} else {
info->unicast = RX_STATE_NORMAL;
}
if (n->nomulti) {
info->multicast = RX_STATE_NONE;
} else if (n->allmulti) {
info->multicast = RX_STATE_ALL;
} else {
info->multicast = RX_STATE_NORMAL;
}
info->broadcast_allowed = n->nobcast;
info->multicast_overflow = n->mac_table.multi_overflow;
info->unicast_overflow = n->mac_table.uni_overflow;
info->main_mac = mac_strdup_printf(n->mac);
str_list = NULL;
for (i = 0; i < n->mac_table.first_multi; i++) {
entry = g_malloc0(sizeof(*entry));
entry->value = mac_strdup_printf(n->mac_table.macs + i * ETH_ALEN);
entry->next = str_list;
str_list = entry;
}
info->unicast_table = str_list;
str_list = NULL;
for (i = n->mac_table.first_multi; i < n->mac_table.in_use; i++) {
entry = g_malloc0(sizeof(*entry));
entry->value = mac_strdup_printf(n->mac_table.macs + i * ETH_ALEN);
entry->next = str_list;
str_list = entry;
}
info->multicast_table = str_list;
info->vlan_table = get_vlan_table(n);
if (!((1 << VIRTIO_NET_F_CTRL_VLAN) & vdev->guest_features)) {
info->vlan = RX_STATE_ALL;
} else if (!info->vlan_table) {
info->vlan = RX_STATE_NONE;
} else {
info->vlan = RX_STATE_NORMAL;
}
/* enable event notification after query */
nc->rxfilter_notify_enabled = 1;
return info;
}
| @@ -1407,6 +1407,11 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int version_id)
}
n->curr_queues = qemu_get_be16(f);
+ if (n->curr_queues > n->max_queues) {
+ error_report("virtio-net: curr_queues %x > max_queues %x",
+ n->curr_queues, n->max_queues);
+ return -1;
+ }
for (i = 1; i < n->curr_queues; i++) {
n->vqs[i].tx_waiting = qemu_get_be32(f);
} | CWE-119 | null | null |
12,712 | static ssize_t virtio_net_receive(NetClientState *nc, const uint8_t *buf, size_t size)
{
VirtIONet *n = qemu_get_nic_opaque(nc);
VirtIONetQueue *q = virtio_net_get_subqueue(nc);
VirtIODevice *vdev = VIRTIO_DEVICE(n);
struct iovec mhdr_sg[VIRTQUEUE_MAX_SIZE];
struct virtio_net_hdr_mrg_rxbuf mhdr;
unsigned mhdr_cnt = 0;
size_t offset, i, guest_offset;
if (!virtio_net_can_receive(nc)) {
return -1;
}
/* hdr_len refers to the header we supply to the guest */
if (!virtio_net_has_buffers(q, size + n->guest_hdr_len - n->host_hdr_len)) {
return 0;
}
if (!receive_filter(n, buf, size))
return size;
offset = i = 0;
while (offset < size) {
VirtQueueElement elem;
int len, total;
const struct iovec *sg = elem.in_sg;
total = 0;
if (virtqueue_pop(q->rx_vq, &elem) == 0) {
if (i == 0)
return -1;
error_report("virtio-net unexpected empty queue: "
"i %zd mergeable %d offset %zd, size %zd, "
"guest hdr len %zd, host hdr len %zd guest features 0x%x",
i, n->mergeable_rx_bufs, offset, size,
n->guest_hdr_len, n->host_hdr_len, vdev->guest_features);
exit(1);
}
if (elem.in_num < 1) {
error_report("virtio-net receive queue contains no in buffers");
exit(1);
}
if (i == 0) {
assert(offset == 0);
if (n->mergeable_rx_bufs) {
mhdr_cnt = iov_copy(mhdr_sg, ARRAY_SIZE(mhdr_sg),
sg, elem.in_num,
offsetof(typeof(mhdr), num_buffers),
sizeof(mhdr.num_buffers));
}
receive_header(n, sg, elem.in_num, buf, size);
offset = n->host_hdr_len;
total += n->guest_hdr_len;
guest_offset = n->guest_hdr_len;
} else {
guest_offset = 0;
}
/* copy in packet. ugh */
len = iov_from_buf(sg, elem.in_num, guest_offset,
buf + offset, size - offset);
total += len;
offset += len;
/* If buffers can't be merged, at this point we
* must have consumed the complete packet.
* Otherwise, drop it. */
if (!n->mergeable_rx_bufs && offset < size) {
#if 0
error_report("virtio-net truncated non-mergeable packet: "
"i %zd mergeable %d offset %zd, size %zd, "
"guest hdr len %zd, host hdr len %zd",
i, n->mergeable_rx_bufs,
offset, size, n->guest_hdr_len, n->host_hdr_len);
#endif
return size;
}
/* signal other side */
virtqueue_fill(q->rx_vq, &elem, total, i++);
}
if (mhdr_cnt) {
stw_p(&mhdr.num_buffers, i);
iov_from_buf(mhdr_sg, mhdr_cnt,
0,
&mhdr.num_buffers, sizeof mhdr.num_buffers);
}
virtqueue_flush(q->rx_vq, i);
virtio_notify(vdev, q->rx_vq);
return size;
}
| DoS Exec Code Overflow | 0 | static ssize_t virtio_net_receive(NetClientState *nc, const uint8_t *buf, size_t size)
{
VirtIONet *n = qemu_get_nic_opaque(nc);
VirtIONetQueue *q = virtio_net_get_subqueue(nc);
VirtIODevice *vdev = VIRTIO_DEVICE(n);
struct iovec mhdr_sg[VIRTQUEUE_MAX_SIZE];
struct virtio_net_hdr_mrg_rxbuf mhdr;
unsigned mhdr_cnt = 0;
size_t offset, i, guest_offset;
if (!virtio_net_can_receive(nc)) {
return -1;
}
/* hdr_len refers to the header we supply to the guest */
if (!virtio_net_has_buffers(q, size + n->guest_hdr_len - n->host_hdr_len)) {
return 0;
}
if (!receive_filter(n, buf, size))
return size;
offset = i = 0;
while (offset < size) {
VirtQueueElement elem;
int len, total;
const struct iovec *sg = elem.in_sg;
total = 0;
if (virtqueue_pop(q->rx_vq, &elem) == 0) {
if (i == 0)
return -1;
error_report("virtio-net unexpected empty queue: "
"i %zd mergeable %d offset %zd, size %zd, "
"guest hdr len %zd, host hdr len %zd guest features 0x%x",
i, n->mergeable_rx_bufs, offset, size,
n->guest_hdr_len, n->host_hdr_len, vdev->guest_features);
exit(1);
}
if (elem.in_num < 1) {
error_report("virtio-net receive queue contains no in buffers");
exit(1);
}
if (i == 0) {
assert(offset == 0);
if (n->mergeable_rx_bufs) {
mhdr_cnt = iov_copy(mhdr_sg, ARRAY_SIZE(mhdr_sg),
sg, elem.in_num,
offsetof(typeof(mhdr), num_buffers),
sizeof(mhdr.num_buffers));
}
receive_header(n, sg, elem.in_num, buf, size);
offset = n->host_hdr_len;
total += n->guest_hdr_len;
guest_offset = n->guest_hdr_len;
} else {
guest_offset = 0;
}
/* copy in packet. ugh */
len = iov_from_buf(sg, elem.in_num, guest_offset,
buf + offset, size - offset);
total += len;
offset += len;
/* If buffers can't be merged, at this point we
* must have consumed the complete packet.
* Otherwise, drop it. */
if (!n->mergeable_rx_bufs && offset < size) {
#if 0
error_report("virtio-net truncated non-mergeable packet: "
"i %zd mergeable %d offset %zd, size %zd, "
"guest hdr len %zd, host hdr len %zd",
i, n->mergeable_rx_bufs,
offset, size, n->guest_hdr_len, n->host_hdr_len);
#endif
return size;
}
/* signal other side */
virtqueue_fill(q->rx_vq, &elem, total, i++);
}
if (mhdr_cnt) {
stw_p(&mhdr.num_buffers, i);
iov_from_buf(mhdr_sg, mhdr_cnt,
0,
&mhdr.num_buffers, sizeof mhdr.num_buffers);
}
virtqueue_flush(q->rx_vq, i);
virtio_notify(vdev, q->rx_vq);
return size;
}
| @@ -1407,6 +1407,11 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int version_id)
}
n->curr_queues = qemu_get_be16(f);
+ if (n->curr_queues > n->max_queues) {
+ error_report("virtio-net: curr_queues %x > max_queues %x",
+ n->curr_queues, n->max_queues);
+ return -1;
+ }
for (i = 1; i < n->curr_queues; i++) {
n->vqs[i].tx_waiting = qemu_get_be32(f);
} | CWE-119 | null | null |
12,713 | static void virtio_net_reset(VirtIODevice *vdev)
{
VirtIONet *n = VIRTIO_NET(vdev);
/* Reset back to compatibility mode */
n->promisc = 1;
n->allmulti = 0;
n->alluni = 0;
n->nomulti = 0;
n->nouni = 0;
n->nobcast = 0;
/* multiqueue is disabled by default */
n->curr_queues = 1;
/* Flush any MAC and VLAN filter table state */
n->mac_table.in_use = 0;
n->mac_table.first_multi = 0;
n->mac_table.multi_overflow = 0;
n->mac_table.uni_overflow = 0;
memset(n->mac_table.macs, 0, MAC_TABLE_ENTRIES * ETH_ALEN);
memcpy(&n->mac[0], &n->nic->conf->macaddr, sizeof(n->mac));
qemu_format_nic_info_str(qemu_get_queue(n->nic), n->mac);
memset(n->vlans, 0, MAX_VLAN >> 3);
}
| DoS Exec Code Overflow | 0 | static void virtio_net_reset(VirtIODevice *vdev)
{
VirtIONet *n = VIRTIO_NET(vdev);
/* Reset back to compatibility mode */
n->promisc = 1;
n->allmulti = 0;
n->alluni = 0;
n->nomulti = 0;
n->nouni = 0;
n->nobcast = 0;
/* multiqueue is disabled by default */
n->curr_queues = 1;
/* Flush any MAC and VLAN filter table state */
n->mac_table.in_use = 0;
n->mac_table.first_multi = 0;
n->mac_table.multi_overflow = 0;
n->mac_table.uni_overflow = 0;
memset(n->mac_table.macs, 0, MAC_TABLE_ENTRIES * ETH_ALEN);
memcpy(&n->mac[0], &n->nic->conf->macaddr, sizeof(n->mac));
qemu_format_nic_info_str(qemu_get_queue(n->nic), n->mac);
memset(n->vlans, 0, MAX_VLAN >> 3);
}
| @@ -1407,6 +1407,11 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int version_id)
}
n->curr_queues = qemu_get_be16(f);
+ if (n->curr_queues > n->max_queues) {
+ error_report("virtio-net: curr_queues %x > max_queues %x",
+ n->curr_queues, n->max_queues);
+ return -1;
+ }
for (i = 1; i < n->curr_queues; i++) {
n->vqs[i].tx_waiting = qemu_get_be32(f);
} | CWE-119 | null | null |
12,714 | static void virtio_net_save(QEMUFile *f, void *opaque)
{
int i;
VirtIONet *n = opaque;
VirtIODevice *vdev = VIRTIO_DEVICE(n);
/* At this point, backend must be stopped, otherwise
* it might keep writing to memory. */
assert(!n->vhost_started);
virtio_save(vdev, f);
qemu_put_buffer(f, n->mac, ETH_ALEN);
qemu_put_be32(f, n->vqs[0].tx_waiting);
qemu_put_be32(f, n->mergeable_rx_bufs);
qemu_put_be16(f, n->status);
qemu_put_byte(f, n->promisc);
qemu_put_byte(f, n->allmulti);
qemu_put_be32(f, n->mac_table.in_use);
qemu_put_buffer(f, n->mac_table.macs, n->mac_table.in_use * ETH_ALEN);
qemu_put_buffer(f, (uint8_t *)n->vlans, MAX_VLAN >> 3);
qemu_put_be32(f, n->has_vnet_hdr);
qemu_put_byte(f, n->mac_table.multi_overflow);
qemu_put_byte(f, n->mac_table.uni_overflow);
qemu_put_byte(f, n->alluni);
qemu_put_byte(f, n->nomulti);
qemu_put_byte(f, n->nouni);
qemu_put_byte(f, n->nobcast);
qemu_put_byte(f, n->has_ufo);
if (n->max_queues > 1) {
qemu_put_be16(f, n->max_queues);
qemu_put_be16(f, n->curr_queues);
for (i = 1; i < n->curr_queues; i++) {
qemu_put_be32(f, n->vqs[i].tx_waiting);
}
}
if ((1 << VIRTIO_NET_F_CTRL_GUEST_OFFLOADS) & vdev->guest_features) {
qemu_put_be64(f, n->curr_guest_offloads);
}
}
| DoS Exec Code Overflow | 0 | static void virtio_net_save(QEMUFile *f, void *opaque)
{
int i;
VirtIONet *n = opaque;
VirtIODevice *vdev = VIRTIO_DEVICE(n);
/* At this point, backend must be stopped, otherwise
* it might keep writing to memory. */
assert(!n->vhost_started);
virtio_save(vdev, f);
qemu_put_buffer(f, n->mac, ETH_ALEN);
qemu_put_be32(f, n->vqs[0].tx_waiting);
qemu_put_be32(f, n->mergeable_rx_bufs);
qemu_put_be16(f, n->status);
qemu_put_byte(f, n->promisc);
qemu_put_byte(f, n->allmulti);
qemu_put_be32(f, n->mac_table.in_use);
qemu_put_buffer(f, n->mac_table.macs, n->mac_table.in_use * ETH_ALEN);
qemu_put_buffer(f, (uint8_t *)n->vlans, MAX_VLAN >> 3);
qemu_put_be32(f, n->has_vnet_hdr);
qemu_put_byte(f, n->mac_table.multi_overflow);
qemu_put_byte(f, n->mac_table.uni_overflow);
qemu_put_byte(f, n->alluni);
qemu_put_byte(f, n->nomulti);
qemu_put_byte(f, n->nouni);
qemu_put_byte(f, n->nobcast);
qemu_put_byte(f, n->has_ufo);
if (n->max_queues > 1) {
qemu_put_be16(f, n->max_queues);
qemu_put_be16(f, n->curr_queues);
for (i = 1; i < n->curr_queues; i++) {
qemu_put_be32(f, n->vqs[i].tx_waiting);
}
}
if ((1 << VIRTIO_NET_F_CTRL_GUEST_OFFLOADS) & vdev->guest_features) {
qemu_put_be64(f, n->curr_guest_offloads);
}
}
| @@ -1407,6 +1407,11 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int version_id)
}
n->curr_queues = qemu_get_be16(f);
+ if (n->curr_queues > n->max_queues) {
+ error_report("virtio-net: curr_queues %x > max_queues %x",
+ n->curr_queues, n->max_queues);
+ return -1;
+ }
for (i = 1; i < n->curr_queues; i++) {
n->vqs[i].tx_waiting = qemu_get_be32(f);
} | CWE-119 | null | null |
12,715 | static void virtio_net_set_config(VirtIODevice *vdev, const uint8_t *config)
{
VirtIONet *n = VIRTIO_NET(vdev);
struct virtio_net_config netcfg = {};
memcpy(&netcfg, config, n->config_size);
if (!(vdev->guest_features >> VIRTIO_NET_F_CTRL_MAC_ADDR & 1) &&
memcmp(netcfg.mac, n->mac, ETH_ALEN)) {
memcpy(n->mac, netcfg.mac, ETH_ALEN);
qemu_format_nic_info_str(qemu_get_queue(n->nic), n->mac);
}
}
| DoS Exec Code Overflow | 0 | static void virtio_net_set_config(VirtIODevice *vdev, const uint8_t *config)
{
VirtIONet *n = VIRTIO_NET(vdev);
struct virtio_net_config netcfg = {};
memcpy(&netcfg, config, n->config_size);
if (!(vdev->guest_features >> VIRTIO_NET_F_CTRL_MAC_ADDR & 1) &&
memcmp(netcfg.mac, n->mac, ETH_ALEN)) {
memcpy(n->mac, netcfg.mac, ETH_ALEN);
qemu_format_nic_info_str(qemu_get_queue(n->nic), n->mac);
}
}
| @@ -1407,6 +1407,11 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int version_id)
}
n->curr_queues = qemu_get_be16(f);
+ if (n->curr_queues > n->max_queues) {
+ error_report("virtio-net: curr_queues %x > max_queues %x",
+ n->curr_queues, n->max_queues);
+ return -1;
+ }
for (i = 1; i < n->curr_queues; i++) {
n->vqs[i].tx_waiting = qemu_get_be32(f);
} | CWE-119 | null | null |
12,716 | void virtio_net_set_config_size(VirtIONet *n, uint32_t host_features)
{
int i, config_size = 0;
host_features |= (1 << VIRTIO_NET_F_MAC);
for (i = 0; feature_sizes[i].flags != 0; i++) {
if (host_features & feature_sizes[i].flags) {
config_size = MAX(feature_sizes[i].end, config_size);
}
}
n->config_size = config_size;
}
| DoS Exec Code Overflow | 0 | void virtio_net_set_config_size(VirtIONet *n, uint32_t host_features)
{
int i, config_size = 0;
host_features |= (1 << VIRTIO_NET_F_MAC);
for (i = 0; feature_sizes[i].flags != 0; i++) {
if (host_features & feature_sizes[i].flags) {
config_size = MAX(feature_sizes[i].end, config_size);
}
}
n->config_size = config_size;
}
| @@ -1407,6 +1407,11 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int version_id)
}
n->curr_queues = qemu_get_be16(f);
+ if (n->curr_queues > n->max_queues) {
+ error_report("virtio-net: curr_queues %x > max_queues %x",
+ n->curr_queues, n->max_queues);
+ return -1;
+ }
for (i = 1; i < n->curr_queues; i++) {
n->vqs[i].tx_waiting = qemu_get_be32(f);
} | CWE-119 | null | null |
12,717 | static void virtio_net_set_link_status(NetClientState *nc)
{
VirtIONet *n = qemu_get_nic_opaque(nc);
VirtIODevice *vdev = VIRTIO_DEVICE(n);
uint16_t old_status = n->status;
if (nc->link_down)
n->status &= ~VIRTIO_NET_S_LINK_UP;
else
n->status |= VIRTIO_NET_S_LINK_UP;
if (n->status != old_status)
virtio_notify_config(vdev);
virtio_net_set_status(vdev, vdev->status);
}
| DoS Exec Code Overflow | 0 | static void virtio_net_set_link_status(NetClientState *nc)
{
VirtIONet *n = qemu_get_nic_opaque(nc);
VirtIODevice *vdev = VIRTIO_DEVICE(n);
uint16_t old_status = n->status;
if (nc->link_down)
n->status &= ~VIRTIO_NET_S_LINK_UP;
else
n->status |= VIRTIO_NET_S_LINK_UP;
if (n->status != old_status)
virtio_notify_config(vdev);
virtio_net_set_status(vdev, vdev->status);
}
| @@ -1407,6 +1407,11 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int version_id)
}
n->curr_queues = qemu_get_be16(f);
+ if (n->curr_queues > n->max_queues) {
+ error_report("virtio-net: curr_queues %x > max_queues %x",
+ n->curr_queues, n->max_queues);
+ return -1;
+ }
for (i = 1; i < n->curr_queues; i++) {
n->vqs[i].tx_waiting = qemu_get_be32(f);
} | CWE-119 | null | null |
12,718 | static void virtio_net_set_mrg_rx_bufs(VirtIONet *n, int mergeable_rx_bufs)
{
int i;
NetClientState *nc;
n->mergeable_rx_bufs = mergeable_rx_bufs;
n->guest_hdr_len = n->mergeable_rx_bufs ?
sizeof(struct virtio_net_hdr_mrg_rxbuf) : sizeof(struct virtio_net_hdr);
for (i = 0; i < n->max_queues; i++) {
nc = qemu_get_subqueue(n->nic, i);
if (peer_has_vnet_hdr(n) &&
qemu_has_vnet_hdr_len(nc->peer, n->guest_hdr_len)) {
qemu_set_vnet_hdr_len(nc->peer, n->guest_hdr_len);
n->host_hdr_len = n->guest_hdr_len;
}
}
}
| DoS Exec Code Overflow | 0 | static void virtio_net_set_mrg_rx_bufs(VirtIONet *n, int mergeable_rx_bufs)
{
int i;
NetClientState *nc;
n->mergeable_rx_bufs = mergeable_rx_bufs;
n->guest_hdr_len = n->mergeable_rx_bufs ?
sizeof(struct virtio_net_hdr_mrg_rxbuf) : sizeof(struct virtio_net_hdr);
for (i = 0; i < n->max_queues; i++) {
nc = qemu_get_subqueue(n->nic, i);
if (peer_has_vnet_hdr(n) &&
qemu_has_vnet_hdr_len(nc->peer, n->guest_hdr_len)) {
qemu_set_vnet_hdr_len(nc->peer, n->guest_hdr_len);
n->host_hdr_len = n->guest_hdr_len;
}
}
}
| @@ -1407,6 +1407,11 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int version_id)
}
n->curr_queues = qemu_get_be16(f);
+ if (n->curr_queues > n->max_queues) {
+ error_report("virtio-net: curr_queues %x > max_queues %x",
+ n->curr_queues, n->max_queues);
+ return -1;
+ }
for (i = 1; i < n->curr_queues; i++) {
n->vqs[i].tx_waiting = qemu_get_be32(f);
} | CWE-119 | null | null |
12,719 | static void virtio_net_set_multiqueue(VirtIONet *n, int multiqueue)
{
VirtIODevice *vdev = VIRTIO_DEVICE(n);
int i, max = multiqueue ? n->max_queues : 1;
n->multiqueue = multiqueue;
for (i = 2; i <= n->max_queues * 2 + 1; i++) {
virtio_del_queue(vdev, i);
}
for (i = 1; i < max; i++) {
n->vqs[i].rx_vq = virtio_add_queue(vdev, 256, virtio_net_handle_rx);
if (n->vqs[i].tx_timer) {
n->vqs[i].tx_vq =
virtio_add_queue(vdev, 256, virtio_net_handle_tx_timer);
n->vqs[i].tx_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL,
virtio_net_tx_timer,
&n->vqs[i]);
} else {
n->vqs[i].tx_vq =
virtio_add_queue(vdev, 256, virtio_net_handle_tx_bh);
n->vqs[i].tx_bh = qemu_bh_new(virtio_net_tx_bh, &n->vqs[i]);
}
n->vqs[i].tx_waiting = 0;
n->vqs[i].n = n;
}
/* Note: Minux Guests (version 3.2.1) use ctrl vq but don't ack
* VIRTIO_NET_F_CTRL_VQ. Create ctrl vq unconditionally to avoid
* breaking them.
*/
n->ctrl_vq = virtio_add_queue(vdev, 64, virtio_net_handle_ctrl);
virtio_net_set_queues(n);
}
| DoS Exec Code Overflow | 0 | static void virtio_net_set_multiqueue(VirtIONet *n, int multiqueue)
{
VirtIODevice *vdev = VIRTIO_DEVICE(n);
int i, max = multiqueue ? n->max_queues : 1;
n->multiqueue = multiqueue;
for (i = 2; i <= n->max_queues * 2 + 1; i++) {
virtio_del_queue(vdev, i);
}
for (i = 1; i < max; i++) {
n->vqs[i].rx_vq = virtio_add_queue(vdev, 256, virtio_net_handle_rx);
if (n->vqs[i].tx_timer) {
n->vqs[i].tx_vq =
virtio_add_queue(vdev, 256, virtio_net_handle_tx_timer);
n->vqs[i].tx_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL,
virtio_net_tx_timer,
&n->vqs[i]);
} else {
n->vqs[i].tx_vq =
virtio_add_queue(vdev, 256, virtio_net_handle_tx_bh);
n->vqs[i].tx_bh = qemu_bh_new(virtio_net_tx_bh, &n->vqs[i]);
}
n->vqs[i].tx_waiting = 0;
n->vqs[i].n = n;
}
/* Note: Minux Guests (version 3.2.1) use ctrl vq but don't ack
* VIRTIO_NET_F_CTRL_VQ. Create ctrl vq unconditionally to avoid
* breaking them.
*/
n->ctrl_vq = virtio_add_queue(vdev, 64, virtio_net_handle_ctrl);
virtio_net_set_queues(n);
}
| @@ -1407,6 +1407,11 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int version_id)
}
n->curr_queues = qemu_get_be16(f);
+ if (n->curr_queues > n->max_queues) {
+ error_report("virtio-net: curr_queues %x > max_queues %x",
+ n->curr_queues, n->max_queues);
+ return -1;
+ }
for (i = 1; i < n->curr_queues; i++) {
n->vqs[i].tx_waiting = qemu_get_be32(f);
} | CWE-119 | null | null |
12,720 | static void virtio_net_set_queues(VirtIONet *n)
{
int i;
int r;
for (i = 0; i < n->max_queues; i++) {
if (i < n->curr_queues) {
r = peer_attach(n, i);
assert(!r);
} else {
r = peer_detach(n, i);
assert(!r);
}
}
}
| DoS Exec Code Overflow | 0 | static void virtio_net_set_queues(VirtIONet *n)
{
int i;
int r;
for (i = 0; i < n->max_queues; i++) {
if (i < n->curr_queues) {
r = peer_attach(n, i);
assert(!r);
} else {
r = peer_detach(n, i);
assert(!r);
}
}
}
| @@ -1407,6 +1407,11 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int version_id)
}
n->curr_queues = qemu_get_be16(f);
+ if (n->curr_queues > n->max_queues) {
+ error_report("virtio-net: curr_queues %x > max_queues %x",
+ n->curr_queues, n->max_queues);
+ return -1;
+ }
for (i = 1; i < n->curr_queues; i++) {
n->vqs[i].tx_waiting = qemu_get_be32(f);
} | CWE-119 | null | null |
12,721 | static void virtio_net_set_status(struct VirtIODevice *vdev, uint8_t status)
{
VirtIONet *n = VIRTIO_NET(vdev);
VirtIONetQueue *q;
int i;
uint8_t queue_status;
virtio_net_vhost_status(n, status);
for (i = 0; i < n->max_queues; i++) {
q = &n->vqs[i];
if ((!n->multiqueue && i != 0) || i >= n->curr_queues) {
queue_status = 0;
} else {
queue_status = status;
}
if (!q->tx_waiting) {
continue;
}
if (virtio_net_started(n, queue_status) && !n->vhost_started) {
if (q->tx_timer) {
timer_mod(q->tx_timer,
qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + n->tx_timeout);
} else {
qemu_bh_schedule(q->tx_bh);
}
} else {
if (q->tx_timer) {
timer_del(q->tx_timer);
} else {
qemu_bh_cancel(q->tx_bh);
}
}
}
}
| DoS Exec Code Overflow | 0 | static void virtio_net_set_status(struct VirtIODevice *vdev, uint8_t status)
{
VirtIONet *n = VIRTIO_NET(vdev);
VirtIONetQueue *q;
int i;
uint8_t queue_status;
virtio_net_vhost_status(n, status);
for (i = 0; i < n->max_queues; i++) {
q = &n->vqs[i];
if ((!n->multiqueue && i != 0) || i >= n->curr_queues) {
queue_status = 0;
} else {
queue_status = status;
}
if (!q->tx_waiting) {
continue;
}
if (virtio_net_started(n, queue_status) && !n->vhost_started) {
if (q->tx_timer) {
timer_mod(q->tx_timer,
qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + n->tx_timeout);
} else {
qemu_bh_schedule(q->tx_bh);
}
} else {
if (q->tx_timer) {
timer_del(q->tx_timer);
} else {
qemu_bh_cancel(q->tx_bh);
}
}
}
}
| @@ -1407,6 +1407,11 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int version_id)
}
n->curr_queues = qemu_get_be16(f);
+ if (n->curr_queues > n->max_queues) {
+ error_report("virtio-net: curr_queues %x > max_queues %x",
+ n->curr_queues, n->max_queues);
+ return -1;
+ }
for (i = 1; i < n->curr_queues; i++) {
n->vqs[i].tx_waiting = qemu_get_be32(f);
} | CWE-119 | null | null |
12,722 | static bool virtio_net_started(VirtIONet *n, uint8_t status)
{
VirtIODevice *vdev = VIRTIO_DEVICE(n);
return (status & VIRTIO_CONFIG_S_DRIVER_OK) &&
(n->status & VIRTIO_NET_S_LINK_UP) && vdev->vm_running;
}
| DoS Exec Code Overflow | 0 | static bool virtio_net_started(VirtIONet *n, uint8_t status)
{
VirtIODevice *vdev = VIRTIO_DEVICE(n);
return (status & VIRTIO_CONFIG_S_DRIVER_OK) &&
(n->status & VIRTIO_NET_S_LINK_UP) && vdev->vm_running;
}
| @@ -1407,6 +1407,11 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int version_id)
}
n->curr_queues = qemu_get_be16(f);
+ if (n->curr_queues > n->max_queues) {
+ error_report("virtio-net: curr_queues %x > max_queues %x",
+ n->curr_queues, n->max_queues);
+ return -1;
+ }
for (i = 1; i < n->curr_queues; i++) {
n->vqs[i].tx_waiting = qemu_get_be32(f);
} | CWE-119 | null | null |
12,723 | static void virtio_net_tx_complete(NetClientState *nc, ssize_t len)
{
VirtIONet *n = qemu_get_nic_opaque(nc);
VirtIONetQueue *q = virtio_net_get_subqueue(nc);
VirtIODevice *vdev = VIRTIO_DEVICE(n);
virtqueue_push(q->tx_vq, &q->async_tx.elem, 0);
virtio_notify(vdev, q->tx_vq);
q->async_tx.elem.out_num = q->async_tx.len = 0;
virtio_queue_set_notification(q->tx_vq, 1);
virtio_net_flush_tx(q);
}
| DoS Exec Code Overflow | 0 | static void virtio_net_tx_complete(NetClientState *nc, ssize_t len)
{
VirtIONet *n = qemu_get_nic_opaque(nc);
VirtIONetQueue *q = virtio_net_get_subqueue(nc);
VirtIODevice *vdev = VIRTIO_DEVICE(n);
virtqueue_push(q->tx_vq, &q->async_tx.elem, 0);
virtio_notify(vdev, q->tx_vq);
q->async_tx.elem.out_num = q->async_tx.len = 0;
virtio_queue_set_notification(q->tx_vq, 1);
virtio_net_flush_tx(q);
}
| @@ -1407,6 +1407,11 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int version_id)
}
n->curr_queues = qemu_get_be16(f);
+ if (n->curr_queues > n->max_queues) {
+ error_report("virtio-net: curr_queues %x > max_queues %x",
+ n->curr_queues, n->max_queues);
+ return -1;
+ }
for (i = 1; i < n->curr_queues; i++) {
n->vqs[i].tx_waiting = qemu_get_be32(f);
} | CWE-119 | null | null |
12,724 | static void virtio_net_tx_timer(void *opaque)
{
VirtIONetQueue *q = opaque;
VirtIONet *n = q->n;
VirtIODevice *vdev = VIRTIO_DEVICE(n);
assert(vdev->vm_running);
q->tx_waiting = 0;
/* Just in case the driver is not ready on more */
if (!(vdev->status & VIRTIO_CONFIG_S_DRIVER_OK)) {
return;
}
virtio_queue_set_notification(q->tx_vq, 1);
virtio_net_flush_tx(q);
}
| DoS Exec Code Overflow | 0 | static void virtio_net_tx_timer(void *opaque)
{
VirtIONetQueue *q = opaque;
VirtIONet *n = q->n;
VirtIODevice *vdev = VIRTIO_DEVICE(n);
assert(vdev->vm_running);
q->tx_waiting = 0;
/* Just in case the driver is not ready on more */
if (!(vdev->status & VIRTIO_CONFIG_S_DRIVER_OK)) {
return;
}
virtio_queue_set_notification(q->tx_vq, 1);
virtio_net_flush_tx(q);
}
| @@ -1407,6 +1407,11 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int version_id)
}
n->curr_queues = qemu_get_be16(f);
+ if (n->curr_queues > n->max_queues) {
+ error_report("virtio-net: curr_queues %x > max_queues %x",
+ n->curr_queues, n->max_queues);
+ return -1;
+ }
for (i = 1; i < n->curr_queues; i++) {
n->vqs[i].tx_waiting = qemu_get_be32(f);
} | CWE-119 | null | null |
12,725 | static void virtio_net_vhost_status(VirtIONet *n, uint8_t status)
{
VirtIODevice *vdev = VIRTIO_DEVICE(n);
NetClientState *nc = qemu_get_queue(n->nic);
int queues = n->multiqueue ? n->max_queues : 1;
if (!nc->peer) {
return;
}
if (nc->peer->info->type != NET_CLIENT_OPTIONS_KIND_TAP) {
return;
}
if (!tap_get_vhost_net(nc->peer)) {
return;
}
if (!!n->vhost_started ==
(virtio_net_started(n, status) && !nc->peer->link_down)) {
return;
}
if (!n->vhost_started) {
int r;
if (!vhost_net_query(tap_get_vhost_net(nc->peer), vdev)) {
return;
}
n->vhost_started = 1;
r = vhost_net_start(vdev, n->nic->ncs, queues);
if (r < 0) {
error_report("unable to start vhost net: %d: "
"falling back on userspace virtio", -r);
n->vhost_started = 0;
}
} else {
vhost_net_stop(vdev, n->nic->ncs, queues);
n->vhost_started = 0;
}
}
| DoS Exec Code Overflow | 0 | static void virtio_net_vhost_status(VirtIONet *n, uint8_t status)
{
VirtIODevice *vdev = VIRTIO_DEVICE(n);
NetClientState *nc = qemu_get_queue(n->nic);
int queues = n->multiqueue ? n->max_queues : 1;
if (!nc->peer) {
return;
}
if (nc->peer->info->type != NET_CLIENT_OPTIONS_KIND_TAP) {
return;
}
if (!tap_get_vhost_net(nc->peer)) {
return;
}
if (!!n->vhost_started ==
(virtio_net_started(n, status) && !nc->peer->link_down)) {
return;
}
if (!n->vhost_started) {
int r;
if (!vhost_net_query(tap_get_vhost_net(nc->peer), vdev)) {
return;
}
n->vhost_started = 1;
r = vhost_net_start(vdev, n->nic->ncs, queues);
if (r < 0) {
error_report("unable to start vhost net: %d: "
"falling back on userspace virtio", -r);
n->vhost_started = 0;
}
} else {
vhost_net_stop(vdev, n->nic->ncs, queues);
n->vhost_started = 0;
}
}
| @@ -1407,6 +1407,11 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int version_id)
}
n->curr_queues = qemu_get_be16(f);
+ if (n->curr_queues > n->max_queues) {
+ error_report("virtio-net: curr_queues %x > max_queues %x",
+ n->curr_queues, n->max_queues);
+ return -1;
+ }
for (i = 1; i < n->curr_queues; i++) {
n->vqs[i].tx_waiting = qemu_get_be32(f);
} | CWE-119 | null | null |
12,726 | static void virtio_register_types(void)
{
type_register_static(&virtio_net_info);
}
| DoS Exec Code Overflow | 0 | static void virtio_register_types(void)
{
type_register_static(&virtio_net_info);
}
| @@ -1407,6 +1407,11 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int version_id)
}
n->curr_queues = qemu_get_be16(f);
+ if (n->curr_queues > n->max_queues) {
+ error_report("virtio-net: curr_queues %x > max_queues %x",
+ n->curr_queues, n->max_queues);
+ return -1;
+ }
for (i = 1; i < n->curr_queues; i++) {
n->vqs[i].tx_waiting = qemu_get_be32(f);
} | CWE-119 | null | null |
12,727 | static void work_around_broken_dhclient(struct virtio_net_hdr *hdr,
uint8_t *buf, size_t size)
{
if ((hdr->flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) && /* missing csum */
(size > 27 && size < 1500) && /* normal sized MTU */
(buf[12] == 0x08 && buf[13] == 0x00) && /* ethertype == IPv4 */
(buf[23] == 17) && /* ip.protocol == UDP */
(buf[34] == 0 && buf[35] == 67)) { /* udp.srcport == bootps */
net_checksum_calculate(buf, size);
hdr->flags &= ~VIRTIO_NET_HDR_F_NEEDS_CSUM;
}
}
| DoS Exec Code Overflow | 0 | static void work_around_broken_dhclient(struct virtio_net_hdr *hdr,
uint8_t *buf, size_t size)
{
if ((hdr->flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) && /* missing csum */
(size > 27 && size < 1500) && /* normal sized MTU */
(buf[12] == 0x08 && buf[13] == 0x00) && /* ethertype == IPv4 */
(buf[23] == 17) && /* ip.protocol == UDP */
(buf[34] == 0 && buf[35] == 67)) { /* udp.srcport == bootps */
net_checksum_calculate(buf, size);
hdr->flags &= ~VIRTIO_NET_HDR_F_NEEDS_CSUM;
}
}
| @@ -1407,6 +1407,11 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int version_id)
}
n->curr_queues = qemu_get_be16(f);
+ if (n->curr_queues > n->max_queues) {
+ error_report("virtio-net: curr_queues %x > max_queues %x",
+ n->curr_queues, n->max_queues);
+ return -1;
+ }
for (i = 1; i < n->curr_queues; i++) {
n->vqs[i].tx_waiting = qemu_get_be32(f);
} | CWE-119 | null | null |
12,728 | _csi_arg_get(Eina_Unicode **ptr)
{
Eina_Unicode *b = *ptr;
int sum = 0;
while ((*b) && (*b < '0' || *b > '9')) b++;
if (!*b)
{
*ptr = NULL;
return 0;
}
while ((*b >= '0') && (*b <= '9'))
{
sum *= 10;
sum += *b - '0';
b++;
}
*ptr = b;
return sum;
}
| Exec Code | 0 | _csi_arg_get(Eina_Unicode **ptr)
{
Eina_Unicode *b = *ptr;
int sum = 0;
while ((*b) && (*b < '0' || *b > '9')) b++;
if (!*b)
{
*ptr = NULL;
return 0;
}
while ((*b >= '0') && (*b <= '9'))
{
sum *= 10;
sum += *b - '0';
b++;
}
*ptr = b;
return sum;
}
| @@ -1303,12 +1303,8 @@ _handle_esc_xterm(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
goto err;
if (*p == '?')
{
- TERMPTY_WRITE_STR("\033]0;");
- if (ty->prop.title)
- {
- TERMPTY_WRITE_STR(ty->prop.title);
- }
- TERMPTY_WRITE_STR("\007");
+ /* returns empty string. See CVE-2003-0063 */
+ TERMPTY_WRITE_STR("\033]0;Terminology\007");
}
else
{
@@ -1336,12 +1332,8 @@ _handle_esc_xterm(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
goto err;
if (*p == '?')
{
- TERMPTY_WRITE_STR("\033]0;");
- if (ty->prop.icon)
- {
- TERMPTY_WRITE_STR(ty->prop.icon);
- }
- TERMPTY_WRITE_STR("\007");
+ /* returns empty string. See CVE-2003-0063 */
+ TERMPTY_WRITE_STR("\033]1;Terminology\007");
}
else
{
@@ -1365,12 +1357,8 @@ _handle_esc_xterm(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
goto err;
if (*p == '?')
{
- TERMPTY_WRITE_STR("\033]0;");
- if (ty->prop.title)
- {
- TERMPTY_WRITE_STR(ty->prop.title);
- }
- TERMPTY_WRITE_STR("\007");
+ /* returns empty string. See CVE-2003-0063 */
+ TERMPTY_WRITE_STR("\033]2;Terminology\007");
}
else
{ | CWE-77 | null | null |
12,729 | _eina_unicode_to_hex(Eina_Unicode u)
{
if (u >= '0' && u <= '9')
return u - '0';
if (u >= 'a' && u <= 'f')
return 10 + u - 'a';
if (u >= 'A' && u <= 'F')
return 10 + u - 'A';
return -1;
}
| Exec Code | 0 | _eina_unicode_to_hex(Eina_Unicode u)
{
if (u >= '0' && u <= '9')
return u - '0';
if (u >= 'a' && u <= 'f')
return 10 + u - 'a';
if (u >= 'A' && u <= 'F')
return 10 + u - 'A';
return -1;
}
| @@ -1303,12 +1303,8 @@ _handle_esc_xterm(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
goto err;
if (*p == '?')
{
- TERMPTY_WRITE_STR("\033]0;");
- if (ty->prop.title)
- {
- TERMPTY_WRITE_STR(ty->prop.title);
- }
- TERMPTY_WRITE_STR("\007");
+ /* returns empty string. See CVE-2003-0063 */
+ TERMPTY_WRITE_STR("\033]0;Terminology\007");
}
else
{
@@ -1336,12 +1332,8 @@ _handle_esc_xterm(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
goto err;
if (*p == '?')
{
- TERMPTY_WRITE_STR("\033]0;");
- if (ty->prop.icon)
- {
- TERMPTY_WRITE_STR(ty->prop.icon);
- }
- TERMPTY_WRITE_STR("\007");
+ /* returns empty string. See CVE-2003-0063 */
+ TERMPTY_WRITE_STR("\033]1;Terminology\007");
}
else
{
@@ -1365,12 +1357,8 @@ _handle_esc_xterm(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
goto err;
if (*p == '?')
{
- TERMPTY_WRITE_STR("\033]0;");
- if (ty->prop.title)
- {
- TERMPTY_WRITE_STR(ty->prop.title);
- }
- TERMPTY_WRITE_STR("\007");
+ /* returns empty string. See CVE-2003-0063 */
+ TERMPTY_WRITE_STR("\033]2;Terminology\007");
}
else
{ | CWE-77 | null | null |
12,730 | _handle_cursor_control(Termpty *ty, const Eina_Unicode *cc)
{
switch (*cc)
{
case 0x07: // BEL '\a' (bell)
ty->termstate.had_cr = 0;
if (ty->cb.bell.func) ty->cb.bell.func(ty->cb.bell.data);
return;
case 0x08: // BS '\b' (backspace)
DBG("->BS");
ty->termstate.had_cr = 0;
ty->termstate.wrapnext = 0;
ty->cursor_state.cx--;
TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, ty->w);
return;
case 0x09: // HT '\t' (horizontal tab)
DBG("->HT");
ty->termstate.had_cr = 0;
TERMPTY_SCREEN(ty, ty->cursor_state.cx, ty->cursor_state.cy).att.tab = 1;
ty->termstate.wrapnext = 0;
ty->cursor_state.cx += 8;
ty->cursor_state.cx = (ty->cursor_state.cx / 8) * 8;
TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, ty->w);
return;
case 0x0a: // LF '\n' (new line)
case 0x0b: // VT '\v' (vertical tab)
case 0x0c: // FF '\f' (form feed)
DBG("->LF");
if (ty->termstate.had_cr)
{
TERMPTY_SCREEN(ty, ty->termstate.had_cr_x,
ty->termstate.had_cr_y).att.newline = 1;
}
ty->termstate.had_cr = 0;
ty->termstate.wrapnext = 0;
if (ty->termstate.crlf) ty->cursor_state.cx = 0;
ty->cursor_state.cy++;
termpty_text_scroll_test(ty, EINA_TRUE);
return;
case 0x0d: // CR '\r' (carriage ret)
DBG("->CR");
if (ty->cursor_state.cx != 0)
{
ty->termstate.had_cr_x = ty->cursor_state.cx;
ty->termstate.had_cr_y = ty->cursor_state.cy;
ty->termstate.wrapnext = 0;
}
ty->cursor_state.cx = 0;
return;
default:
return;
}
}
| Exec Code | 0 | _handle_cursor_control(Termpty *ty, const Eina_Unicode *cc)
{
switch (*cc)
{
case 0x07: // BEL '\a' (bell)
ty->termstate.had_cr = 0;
if (ty->cb.bell.func) ty->cb.bell.func(ty->cb.bell.data);
return;
case 0x08: // BS '\b' (backspace)
DBG("->BS");
ty->termstate.had_cr = 0;
ty->termstate.wrapnext = 0;
ty->cursor_state.cx--;
TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, ty->w);
return;
case 0x09: // HT '\t' (horizontal tab)
DBG("->HT");
ty->termstate.had_cr = 0;
TERMPTY_SCREEN(ty, ty->cursor_state.cx, ty->cursor_state.cy).att.tab = 1;
ty->termstate.wrapnext = 0;
ty->cursor_state.cx += 8;
ty->cursor_state.cx = (ty->cursor_state.cx / 8) * 8;
TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, ty->w);
return;
case 0x0a: // LF '\n' (new line)
case 0x0b: // VT '\v' (vertical tab)
case 0x0c: // FF '\f' (form feed)
DBG("->LF");
if (ty->termstate.had_cr)
{
TERMPTY_SCREEN(ty, ty->termstate.had_cr_x,
ty->termstate.had_cr_y).att.newline = 1;
}
ty->termstate.had_cr = 0;
ty->termstate.wrapnext = 0;
if (ty->termstate.crlf) ty->cursor_state.cx = 0;
ty->cursor_state.cy++;
termpty_text_scroll_test(ty, EINA_TRUE);
return;
case 0x0d: // CR '\r' (carriage ret)
DBG("->CR");
if (ty->cursor_state.cx != 0)
{
ty->termstate.had_cr_x = ty->cursor_state.cx;
ty->termstate.had_cr_y = ty->cursor_state.cy;
ty->termstate.wrapnext = 0;
}
ty->cursor_state.cx = 0;
return;
default:
return;
}
}
| @@ -1303,12 +1303,8 @@ _handle_esc_xterm(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
goto err;
if (*p == '?')
{
- TERMPTY_WRITE_STR("\033]0;");
- if (ty->prop.title)
- {
- TERMPTY_WRITE_STR(ty->prop.title);
- }
- TERMPTY_WRITE_STR("\007");
+ /* returns empty string. See CVE-2003-0063 */
+ TERMPTY_WRITE_STR("\033]0;Terminology\007");
}
else
{
@@ -1336,12 +1332,8 @@ _handle_esc_xterm(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
goto err;
if (*p == '?')
{
- TERMPTY_WRITE_STR("\033]0;");
- if (ty->prop.icon)
- {
- TERMPTY_WRITE_STR(ty->prop.icon);
- }
- TERMPTY_WRITE_STR("\007");
+ /* returns empty string. See CVE-2003-0063 */
+ TERMPTY_WRITE_STR("\033]1;Terminology\007");
}
else
{
@@ -1365,12 +1357,8 @@ _handle_esc_xterm(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
goto err;
if (*p == '?')
{
- TERMPTY_WRITE_STR("\033]0;");
- if (ty->prop.title)
- {
- TERMPTY_WRITE_STR(ty->prop.title);
- }
- TERMPTY_WRITE_STR("\007");
+ /* returns empty string. See CVE-2003-0063 */
+ TERMPTY_WRITE_STR("\033]2;Terminology\007");
}
else
{ | CWE-77 | null | null |
12,731 | _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
{
int arg, i;
const Eina_Unicode *cc, *be;
Eina_Unicode buf[4096], *b;
cc = (Eina_Unicode *)c;
b = buf;
be = buf + sizeof(buf) / sizeof(buf[0]);
while ((cc < ce) && (*cc <= '?') && (b < be))
{
_handle_cursor_control(ty, cc);
*b = *cc;
b++;
cc++;
}
if (b == be)
{
ERR("csi parsing overflowed, skipping the whole buffer (binary data?)");
return cc - c;
}
if (cc == ce) return 0;
*b = 0;
b = buf;
DBG(" CSI: '%s' args '%s'", _safechar(*cc), (char *) buf);
switch (*cc)
{
case 'm': // color set
_handle_esc_csi_color_set(ty, &b);
break;
case '@': // insert N blank chars
arg = _csi_arg_get(&b);
if (arg < 1) arg = 1;
DBG("insert %d blank chars", arg);
{
int pi = ty->termstate.insert;
Eina_Unicode blank[1] = { ' ' };
int cx = ty->cursor_state.cx;
ty->termstate.wrapnext = 0;
ty->termstate.insert = 1;
for (i = 0; i < arg; i++)
termpty_text_append(ty, blank, 1);
ty->termstate.insert = pi;
ty->cursor_state.cx = cx;
TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, ty->w);
}
break;
case 'A': // cursor up N
case 'e': // cursor up N
arg = _csi_arg_get(&b);
if (arg < 1) arg = 1;
DBG("cursor up %d", arg);
ty->termstate.wrapnext = 0;
ty->cursor_state.cy = MAX(0, ty->cursor_state.cy - arg);
TERMPTY_RESTRICT_FIELD(ty->cursor_state.cy, 0, ty->h);
break;
case 'B': // cursor down N
arg = _csi_arg_get(&b);
if (arg < 1) arg = 1;
DBG("cursor down %d", arg);
ty->termstate.wrapnext = 0;
ty->cursor_state.cy = MIN(ty->h - 1, ty->cursor_state.cy + arg);
TERMPTY_RESTRICT_FIELD(ty->cursor_state.cy, 0, ty->h);
break;
case 'D': // cursor left N
arg = _csi_arg_get(&b);
if (arg < 1) arg = 1;
DBG("cursor left %d", arg);
ty->termstate.wrapnext = 0;
for (i = 0; i < arg; i++)
ty->cursor_state.cx--;
TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, ty->w);
break;
case 'C': // cursor right N
case 'a': // cursor right N
arg = _csi_arg_get(&b);
if (arg < 1) arg = 1;
DBG("cursor right %d", arg);
ty->termstate.wrapnext = 0;
for (i = 0; i < arg; i++)
ty->cursor_state.cx++;
TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, ty->w);
break;
case 'H': // cursor pos set
case 'f': // cursor pos set
DBG("cursor pos set");
ty->termstate.wrapnext = 0;
if (!*b)
{
ty->cursor_state.cx = 0;
ty->cursor_state.cy = 0;
}
else
{
arg = _csi_arg_get(&b);
if (arg < 1) arg = 1;
arg--;
if (arg >= ty->h) arg = ty->h - 1;
if (b)
{
ty->cursor_state.cy = arg;
TERMPTY_RESTRICT_FIELD(ty->cursor_state.cy, 0, ty->h);
arg = _csi_arg_get(&b);
if (arg < 1) arg = 1;
arg--;
}
else arg = 0;
if (arg >= ty->w) arg = ty->w - 1;
if (b)
{
ty->cursor_state.cx = arg;
TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, ty->w);
}
}
ty->cursor_state.cy += ty->termstate.margin_top;
TERMPTY_RESTRICT_FIELD(ty->cursor_state.cy, 0, ty->h);
break;
case 'G': // to column N
arg = _csi_arg_get(&b);
if (arg < 1) arg = 1;
DBG("to column %d", arg);
ty->termstate.wrapnext = 0;
ty->cursor_state.cx = arg - 1;
TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, ty->w);
break;
case 'd': // to row N
arg = _csi_arg_get(&b);
if (arg < 1) arg = 1;
DBG("to row %d", arg);
ty->termstate.wrapnext = 0;
ty->cursor_state.cy = arg - 1;
TERMPTY_RESTRICT_FIELD(ty->cursor_state.cy, 0, ty->h);
break;
case 'E': // down relative N rows, and to col 0
arg = _csi_arg_get(&b);
if (arg < 1) arg = 1;
DBG("down relative %d rows, and to col 0", arg);
ty->termstate.wrapnext = 0;
ty->cursor_state.cy += arg;
TERMPTY_RESTRICT_FIELD(ty->cursor_state.cy, 0, ty->h);
ty->cursor_state.cx = 0;
break;
case 'F': // up relative N rows, and to col 0
arg = _csi_arg_get(&b);
if (arg < 1) arg = 1;
DBG("up relative %d rows, and to col 0", arg);
ty->termstate.wrapnext = 0;
ty->cursor_state.cy -= arg;
TERMPTY_RESTRICT_FIELD(ty->cursor_state.cy, 0, ty->h);
ty->cursor_state.cx = 0;
break;
case 'X': // erase N chars
arg = _csi_arg_get(&b);
if (arg < 1) arg = 1;
DBG("erase %d chars", arg);
termpty_clear_line(ty, TERMPTY_CLR_END, arg);
break;
case 'S': // scroll up N lines
arg = _csi_arg_get(&b);
if (arg < 1) arg = 1;
DBG("scroll up %d lines", arg);
for (i = 0; i < arg; i++)
termpty_text_scroll(ty, EINA_TRUE);
break;
case 'T': // scroll down N lines
arg = _csi_arg_get(&b);
if (arg < 1) arg = 1;
DBG("scroll down %d lines", arg);
for (i = 0; i < arg; i++)
termpty_text_scroll_rev(ty, EINA_TRUE);
break;
case 'M': // delete N lines - cy
case 'L': // insert N lines - cy
arg = _csi_arg_get(&b);
if (arg < 1) arg = 1;
DBG("%s %d lines", (*cc == 'M') ? "delete" : "insert", arg);
{
int sy1, sy2;
sy1 = ty->termstate.scroll_y1;
sy2 = ty->termstate.scroll_y2;
if (ty->termstate.scroll_y2 == 0)
{
ty->termstate.scroll_y1 = ty->cursor_state.cy;
ty->termstate.scroll_y2 = ty->h;
}
else
{
ty->termstate.scroll_y1 = ty->cursor_state.cy;
if (ty->termstate.scroll_y2 <= ty->termstate.scroll_y1)
ty->termstate.scroll_y2 = ty->termstate.scroll_y1 + 1;
}
for (i = 0; i < arg; i++)
{
if (*cc == 'M')
termpty_text_scroll(ty, EINA_TRUE);
else
termpty_text_scroll_rev(ty, EINA_TRUE);
}
ty->termstate.scroll_y1 = sy1;
ty->termstate.scroll_y2 = sy2;
}
break;
case 'P': // erase and scrollback N chars
arg = _csi_arg_get(&b);
if (arg < 1) arg = 1;
DBG("erase and scrollback %d chars", arg);
{
Termcell *cells;
int x, lim;
cells = &(TERMPTY_SCREEN(ty, 0, ty->cursor_state.cy));
lim = ty->w - arg;
for (x = ty->cursor_state.cx; x < (ty->w); x++)
{
if (x < lim)
termpty_cell_copy(ty, &(cells[x + arg]), &(cells[x]), 1);
else
{
cells[x].codepoint = ' ';
cells[x].att.underline = 0;
cells[x].att.blink = 0;
cells[x].att.blink2 = 0;
cells[x].att.inverse = 0;
cells[x].att.strike = 0;
#if defined(SUPPORT_DBLWIDTH)
cells[x].att.dblwidth = 0;
#endif
}
}
}
break;
case 'c': // query device attributes
DBG("query device attributes");
{
char bf[32];
if (b && *b == '>')
{
snprintf(bf, sizeof(bf), "\033[>41;285;%ic", 0);
}
else
{
snprintf(bf, sizeof(bf), "\033[?64;1;2;6;9;15;18;21;22c");
}
termpty_write(ty, bf, strlen(bf));
}
break;
case 'J': // "2j" erases the screen, 1j erase from screen start to curs, 0j erase cursor to end of screen
DBG("2j erases the screen, 1j erase from screen start to curs, 0j erase cursor to end of screen");
arg = _csi_arg_get(&b);
if (b)
{
if ((arg >= TERMPTY_CLR_END) && (arg <= TERMPTY_CLR_ALL))
termpty_clear_screen(ty, arg);
else
ERR("invalid clr scr %i", arg);
}
else
termpty_clear_screen(ty, TERMPTY_CLR_END);
break;
case 'K': // 0K erase to end of line, 1K erase from screen start to cursor, 2K erase all of line
arg = _csi_arg_get(&b);
DBG("0K erase to end of line, 1K erase from screen start to cursor, 2K erase all of line: %d", arg);
if (b)
{
if ((arg >= TERMPTY_CLR_END) && (arg <= TERMPTY_CLR_ALL))
termpty_clear_line(ty, arg, ty->w);
else
ERR("invalid clr lin %i", arg);
}
else termpty_clear_line(ty, TERMPTY_CLR_END, ty->w);
break;
case 'h':
case 'l':
_handle_esc_csi_reset_mode(ty, *cc, b);
break;
case 'r':
arg = _csi_arg_get(&b);
if (!b)
{
WRN("no region args reset region");
ty->termstate.scroll_y1 = 0;
ty->termstate.scroll_y2 = 0;
}
else
{
int arg2;
arg2 = _csi_arg_get(&b);
if (!b)
{
WRN("failed to give 2 regions args reset region");
ty->termstate.scroll_y1 = 0;
ty->termstate.scroll_y2 = 0;
}
else
{
if (arg > arg2)
{
DBG("scroll region beginning > end [%i %i]", arg, arg2);
ty->termstate.scroll_y1 = 0;
ty->termstate.scroll_y2 = 0;
}
else
{
DBG("2 regions args: %i %i", arg, arg2);
if (arg >= ty->h) arg = ty->h - 1;
if (arg == 0) arg = 1;
if (arg2 > ty->h) arg2 = ty->h;
ty->termstate.scroll_y1 = arg - 1;
ty->termstate.scroll_y2 = arg2;
if ((arg == 1) && (arg2 == ty->h))
ty->termstate.scroll_y2 = 0;
}
}
}
break;
case 's': // store cursor pos
termpty_cursor_copy(ty, EINA_TRUE);
break;
case 'u': // restore cursor pos
termpty_cursor_copy(ty, EINA_FALSE);
break;
case 'p': // define key assignments based on keycode
if (b && *b == '!')
{
DBG("soft reset (DECSTR)");
termpty_reset_state(ty);
}
else
{
goto unhandled;
}
break;
case 'n':
_handle_esc_csi_dsr(ty, b);
break;
/*
case 'R': // report cursor
break;
case 's':
break;
case 't':
break;
case 'q': // set/clear led's
break;
case 'x': // request terminal parameters
break;
case 'r': // set top and bottom margins
break;
case 'y': // invoke confidence test
break;
*/
case 'g': // clear tabulation
arg = _csi_arg_get(&b);
DBG("Tabulation Clear (TBC): %d", arg);
break;
case 'Z': // Cursor Back Tab
{
int idx, size, cx = ty->cursor_state.cx, cy = ty->cursor_state.cy;
arg = _csi_arg_get(&b);
if (arg < 1) arg = 1;
size = ty->w * cy + cx + 1;
for (idx = size - 1; idx >= 0; idx--)
{
if (TERMPTY_SCREEN(ty, cx, cy).att.tab) arg--;
cx--;
if (cx < 0)
{
cx = ty->w - 1;
cy--;
}
if (!arg) break;
}
if (!arg)
{
ty->cursor_state.cx = cx;
TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, ty->w);
ty->cursor_state.cy = cy;
TERMPTY_RESTRICT_FIELD(ty->cursor_state.cy, 0, ty->h);
}
}
break;
default:
goto unhandled;
}
cc++;
return cc - c;
unhandled:
{
Eina_Strbuf *bf = eina_strbuf_new();
for (i = 0; c + i <= cc && i < 100; i++)
{
if ((c[i] < ' ') || (c[i] >= 0x7f))
eina_strbuf_append_printf(bf, "\033[35m%08x\033[0m",
(unsigned int) c[i]);
else
eina_strbuf_append_char(bf, c[i]);
}
ERR("unhandled CSI '%s': %s", _safechar(*cc), eina_strbuf_string_get(bf));
eina_strbuf_free(bf);
}
cc++;
return cc - c;
}
| Exec Code | 0 | _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
{
int arg, i;
const Eina_Unicode *cc, *be;
Eina_Unicode buf[4096], *b;
cc = (Eina_Unicode *)c;
b = buf;
be = buf + sizeof(buf) / sizeof(buf[0]);
while ((cc < ce) && (*cc <= '?') && (b < be))
{
_handle_cursor_control(ty, cc);
*b = *cc;
b++;
cc++;
}
if (b == be)
{
ERR("csi parsing overflowed, skipping the whole buffer (binary data?)");
return cc - c;
}
if (cc == ce) return 0;
*b = 0;
b = buf;
DBG(" CSI: '%s' args '%s'", _safechar(*cc), (char *) buf);
switch (*cc)
{
case 'm': // color set
_handle_esc_csi_color_set(ty, &b);
break;
case '@': // insert N blank chars
arg = _csi_arg_get(&b);
if (arg < 1) arg = 1;
DBG("insert %d blank chars", arg);
{
int pi = ty->termstate.insert;
Eina_Unicode blank[1] = { ' ' };
int cx = ty->cursor_state.cx;
ty->termstate.wrapnext = 0;
ty->termstate.insert = 1;
for (i = 0; i < arg; i++)
termpty_text_append(ty, blank, 1);
ty->termstate.insert = pi;
ty->cursor_state.cx = cx;
TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, ty->w);
}
break;
case 'A': // cursor up N
case 'e': // cursor up N
arg = _csi_arg_get(&b);
if (arg < 1) arg = 1;
DBG("cursor up %d", arg);
ty->termstate.wrapnext = 0;
ty->cursor_state.cy = MAX(0, ty->cursor_state.cy - arg);
TERMPTY_RESTRICT_FIELD(ty->cursor_state.cy, 0, ty->h);
break;
case 'B': // cursor down N
arg = _csi_arg_get(&b);
if (arg < 1) arg = 1;
DBG("cursor down %d", arg);
ty->termstate.wrapnext = 0;
ty->cursor_state.cy = MIN(ty->h - 1, ty->cursor_state.cy + arg);
TERMPTY_RESTRICT_FIELD(ty->cursor_state.cy, 0, ty->h);
break;
case 'D': // cursor left N
arg = _csi_arg_get(&b);
if (arg < 1) arg = 1;
DBG("cursor left %d", arg);
ty->termstate.wrapnext = 0;
for (i = 0; i < arg; i++)
ty->cursor_state.cx--;
TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, ty->w);
break;
case 'C': // cursor right N
case 'a': // cursor right N
arg = _csi_arg_get(&b);
if (arg < 1) arg = 1;
DBG("cursor right %d", arg);
ty->termstate.wrapnext = 0;
for (i = 0; i < arg; i++)
ty->cursor_state.cx++;
TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, ty->w);
break;
case 'H': // cursor pos set
case 'f': // cursor pos set
DBG("cursor pos set");
ty->termstate.wrapnext = 0;
if (!*b)
{
ty->cursor_state.cx = 0;
ty->cursor_state.cy = 0;
}
else
{
arg = _csi_arg_get(&b);
if (arg < 1) arg = 1;
arg--;
if (arg >= ty->h) arg = ty->h - 1;
if (b)
{
ty->cursor_state.cy = arg;
TERMPTY_RESTRICT_FIELD(ty->cursor_state.cy, 0, ty->h);
arg = _csi_arg_get(&b);
if (arg < 1) arg = 1;
arg--;
}
else arg = 0;
if (arg >= ty->w) arg = ty->w - 1;
if (b)
{
ty->cursor_state.cx = arg;
TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, ty->w);
}
}
ty->cursor_state.cy += ty->termstate.margin_top;
TERMPTY_RESTRICT_FIELD(ty->cursor_state.cy, 0, ty->h);
break;
case 'G': // to column N
arg = _csi_arg_get(&b);
if (arg < 1) arg = 1;
DBG("to column %d", arg);
ty->termstate.wrapnext = 0;
ty->cursor_state.cx = arg - 1;
TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, ty->w);
break;
case 'd': // to row N
arg = _csi_arg_get(&b);
if (arg < 1) arg = 1;
DBG("to row %d", arg);
ty->termstate.wrapnext = 0;
ty->cursor_state.cy = arg - 1;
TERMPTY_RESTRICT_FIELD(ty->cursor_state.cy, 0, ty->h);
break;
case 'E': // down relative N rows, and to col 0
arg = _csi_arg_get(&b);
if (arg < 1) arg = 1;
DBG("down relative %d rows, and to col 0", arg);
ty->termstate.wrapnext = 0;
ty->cursor_state.cy += arg;
TERMPTY_RESTRICT_FIELD(ty->cursor_state.cy, 0, ty->h);
ty->cursor_state.cx = 0;
break;
case 'F': // up relative N rows, and to col 0
arg = _csi_arg_get(&b);
if (arg < 1) arg = 1;
DBG("up relative %d rows, and to col 0", arg);
ty->termstate.wrapnext = 0;
ty->cursor_state.cy -= arg;
TERMPTY_RESTRICT_FIELD(ty->cursor_state.cy, 0, ty->h);
ty->cursor_state.cx = 0;
break;
case 'X': // erase N chars
arg = _csi_arg_get(&b);
if (arg < 1) arg = 1;
DBG("erase %d chars", arg);
termpty_clear_line(ty, TERMPTY_CLR_END, arg);
break;
case 'S': // scroll up N lines
arg = _csi_arg_get(&b);
if (arg < 1) arg = 1;
DBG("scroll up %d lines", arg);
for (i = 0; i < arg; i++)
termpty_text_scroll(ty, EINA_TRUE);
break;
case 'T': // scroll down N lines
arg = _csi_arg_get(&b);
if (arg < 1) arg = 1;
DBG("scroll down %d lines", arg);
for (i = 0; i < arg; i++)
termpty_text_scroll_rev(ty, EINA_TRUE);
break;
case 'M': // delete N lines - cy
case 'L': // insert N lines - cy
arg = _csi_arg_get(&b);
if (arg < 1) arg = 1;
DBG("%s %d lines", (*cc == 'M') ? "delete" : "insert", arg);
{
int sy1, sy2;
sy1 = ty->termstate.scroll_y1;
sy2 = ty->termstate.scroll_y2;
if (ty->termstate.scroll_y2 == 0)
{
ty->termstate.scroll_y1 = ty->cursor_state.cy;
ty->termstate.scroll_y2 = ty->h;
}
else
{
ty->termstate.scroll_y1 = ty->cursor_state.cy;
if (ty->termstate.scroll_y2 <= ty->termstate.scroll_y1)
ty->termstate.scroll_y2 = ty->termstate.scroll_y1 + 1;
}
for (i = 0; i < arg; i++)
{
if (*cc == 'M')
termpty_text_scroll(ty, EINA_TRUE);
else
termpty_text_scroll_rev(ty, EINA_TRUE);
}
ty->termstate.scroll_y1 = sy1;
ty->termstate.scroll_y2 = sy2;
}
break;
case 'P': // erase and scrollback N chars
arg = _csi_arg_get(&b);
if (arg < 1) arg = 1;
DBG("erase and scrollback %d chars", arg);
{
Termcell *cells;
int x, lim;
cells = &(TERMPTY_SCREEN(ty, 0, ty->cursor_state.cy));
lim = ty->w - arg;
for (x = ty->cursor_state.cx; x < (ty->w); x++)
{
if (x < lim)
termpty_cell_copy(ty, &(cells[x + arg]), &(cells[x]), 1);
else
{
cells[x].codepoint = ' ';
cells[x].att.underline = 0;
cells[x].att.blink = 0;
cells[x].att.blink2 = 0;
cells[x].att.inverse = 0;
cells[x].att.strike = 0;
#if defined(SUPPORT_DBLWIDTH)
cells[x].att.dblwidth = 0;
#endif
}
}
}
break;
case 'c': // query device attributes
DBG("query device attributes");
{
char bf[32];
if (b && *b == '>')
{
snprintf(bf, sizeof(bf), "\033[>41;285;%ic", 0);
}
else
{
snprintf(bf, sizeof(bf), "\033[?64;1;2;6;9;15;18;21;22c");
}
termpty_write(ty, bf, strlen(bf));
}
break;
case 'J': // "2j" erases the screen, 1j erase from screen start to curs, 0j erase cursor to end of screen
DBG("2j erases the screen, 1j erase from screen start to curs, 0j erase cursor to end of screen");
arg = _csi_arg_get(&b);
if (b)
{
if ((arg >= TERMPTY_CLR_END) && (arg <= TERMPTY_CLR_ALL))
termpty_clear_screen(ty, arg);
else
ERR("invalid clr scr %i", arg);
}
else
termpty_clear_screen(ty, TERMPTY_CLR_END);
break;
case 'K': // 0K erase to end of line, 1K erase from screen start to cursor, 2K erase all of line
arg = _csi_arg_get(&b);
DBG("0K erase to end of line, 1K erase from screen start to cursor, 2K erase all of line: %d", arg);
if (b)
{
if ((arg >= TERMPTY_CLR_END) && (arg <= TERMPTY_CLR_ALL))
termpty_clear_line(ty, arg, ty->w);
else
ERR("invalid clr lin %i", arg);
}
else termpty_clear_line(ty, TERMPTY_CLR_END, ty->w);
break;
case 'h':
case 'l':
_handle_esc_csi_reset_mode(ty, *cc, b);
break;
case 'r':
arg = _csi_arg_get(&b);
if (!b)
{
WRN("no region args reset region");
ty->termstate.scroll_y1 = 0;
ty->termstate.scroll_y2 = 0;
}
else
{
int arg2;
arg2 = _csi_arg_get(&b);
if (!b)
{
WRN("failed to give 2 regions args reset region");
ty->termstate.scroll_y1 = 0;
ty->termstate.scroll_y2 = 0;
}
else
{
if (arg > arg2)
{
DBG("scroll region beginning > end [%i %i]", arg, arg2);
ty->termstate.scroll_y1 = 0;
ty->termstate.scroll_y2 = 0;
}
else
{
DBG("2 regions args: %i %i", arg, arg2);
if (arg >= ty->h) arg = ty->h - 1;
if (arg == 0) arg = 1;
if (arg2 > ty->h) arg2 = ty->h;
ty->termstate.scroll_y1 = arg - 1;
ty->termstate.scroll_y2 = arg2;
if ((arg == 1) && (arg2 == ty->h))
ty->termstate.scroll_y2 = 0;
}
}
}
break;
case 's': // store cursor pos
termpty_cursor_copy(ty, EINA_TRUE);
break;
case 'u': // restore cursor pos
termpty_cursor_copy(ty, EINA_FALSE);
break;
case 'p': // define key assignments based on keycode
if (b && *b == '!')
{
DBG("soft reset (DECSTR)");
termpty_reset_state(ty);
}
else
{
goto unhandled;
}
break;
case 'n':
_handle_esc_csi_dsr(ty, b);
break;
/*
case 'R': // report cursor
break;
case 's':
break;
case 't':
break;
case 'q': // set/clear led's
break;
case 'x': // request terminal parameters
break;
case 'r': // set top and bottom margins
break;
case 'y': // invoke confidence test
break;
*/
case 'g': // clear tabulation
arg = _csi_arg_get(&b);
DBG("Tabulation Clear (TBC): %d", arg);
break;
case 'Z': // Cursor Back Tab
{
int idx, size, cx = ty->cursor_state.cx, cy = ty->cursor_state.cy;
arg = _csi_arg_get(&b);
if (arg < 1) arg = 1;
size = ty->w * cy + cx + 1;
for (idx = size - 1; idx >= 0; idx--)
{
if (TERMPTY_SCREEN(ty, cx, cy).att.tab) arg--;
cx--;
if (cx < 0)
{
cx = ty->w - 1;
cy--;
}
if (!arg) break;
}
if (!arg)
{
ty->cursor_state.cx = cx;
TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, ty->w);
ty->cursor_state.cy = cy;
TERMPTY_RESTRICT_FIELD(ty->cursor_state.cy, 0, ty->h);
}
}
break;
default:
goto unhandled;
}
cc++;
return cc - c;
unhandled:
{
Eina_Strbuf *bf = eina_strbuf_new();
for (i = 0; c + i <= cc && i < 100; i++)
{
if ((c[i] < ' ') || (c[i] >= 0x7f))
eina_strbuf_append_printf(bf, "\033[35m%08x\033[0m",
(unsigned int) c[i]);
else
eina_strbuf_append_char(bf, c[i]);
}
ERR("unhandled CSI '%s': %s", _safechar(*cc), eina_strbuf_string_get(bf));
eina_strbuf_free(bf);
}
cc++;
return cc - c;
}
| @@ -1303,12 +1303,8 @@ _handle_esc_xterm(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
goto err;
if (*p == '?')
{
- TERMPTY_WRITE_STR("\033]0;");
- if (ty->prop.title)
- {
- TERMPTY_WRITE_STR(ty->prop.title);
- }
- TERMPTY_WRITE_STR("\007");
+ /* returns empty string. See CVE-2003-0063 */
+ TERMPTY_WRITE_STR("\033]0;Terminology\007");
}
else
{
@@ -1336,12 +1332,8 @@ _handle_esc_xterm(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
goto err;
if (*p == '?')
{
- TERMPTY_WRITE_STR("\033]0;");
- if (ty->prop.icon)
- {
- TERMPTY_WRITE_STR(ty->prop.icon);
- }
- TERMPTY_WRITE_STR("\007");
+ /* returns empty string. See CVE-2003-0063 */
+ TERMPTY_WRITE_STR("\033]1;Terminology\007");
}
else
{
@@ -1365,12 +1357,8 @@ _handle_esc_xterm(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
goto err;
if (*p == '?')
{
- TERMPTY_WRITE_STR("\033]0;");
- if (ty->prop.title)
- {
- TERMPTY_WRITE_STR(ty->prop.title);
- }
- TERMPTY_WRITE_STR("\007");
+ /* returns empty string. See CVE-2003-0063 */
+ TERMPTY_WRITE_STR("\033]2;Terminology\007");
}
else
{ | CWE-77 | null | null |
12,732 | _handle_esc_csi_dsr(Termpty *ty, Eina_Unicode *b)
{
int arg, len;
char bf[32];
if (*b == '>')
{
ERR("TODO: disable key resources used by xterm");
return;
}
if (*b == '?')
{
b++;
arg = _csi_arg_get(&b);
switch (arg)
{
case 6:
len = snprintf(bf, sizeof(bf), "\033[?%d;%d;1R",
ty->cursor_state.cy + 1, ty->cursor_state.cx + 1);
termpty_write(ty, bf, len);
break;
default:
WRN("unhandled DSR (dec specific) %d", arg);
break;
}
}
else
{
arg = _csi_arg_get(&b);
switch (arg)
{
case 6:
len = snprintf(bf, sizeof(bf), "\033[%d;%dR",
ty->cursor_state.cy + 1, ty->cursor_state.cx + 1);
termpty_write(ty, bf, len);
break;
default:
WRN("unhandled DSR %d", arg);
break;
}
}
}
| Exec Code | 0 | _handle_esc_csi_dsr(Termpty *ty, Eina_Unicode *b)
{
int arg, len;
char bf[32];
if (*b == '>')
{
ERR("TODO: disable key resources used by xterm");
return;
}
if (*b == '?')
{
b++;
arg = _csi_arg_get(&b);
switch (arg)
{
case 6:
len = snprintf(bf, sizeof(bf), "\033[?%d;%d;1R",
ty->cursor_state.cy + 1, ty->cursor_state.cx + 1);
termpty_write(ty, bf, len);
break;
default:
WRN("unhandled DSR (dec specific) %d", arg);
break;
}
}
else
{
arg = _csi_arg_get(&b);
switch (arg)
{
case 6:
len = snprintf(bf, sizeof(bf), "\033[%d;%dR",
ty->cursor_state.cy + 1, ty->cursor_state.cx + 1);
termpty_write(ty, bf, len);
break;
default:
WRN("unhandled DSR %d", arg);
break;
}
}
}
| @@ -1303,12 +1303,8 @@ _handle_esc_xterm(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
goto err;
if (*p == '?')
{
- TERMPTY_WRITE_STR("\033]0;");
- if (ty->prop.title)
- {
- TERMPTY_WRITE_STR(ty->prop.title);
- }
- TERMPTY_WRITE_STR("\007");
+ /* returns empty string. See CVE-2003-0063 */
+ TERMPTY_WRITE_STR("\033]0;Terminology\007");
}
else
{
@@ -1336,12 +1332,8 @@ _handle_esc_xterm(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
goto err;
if (*p == '?')
{
- TERMPTY_WRITE_STR("\033]0;");
- if (ty->prop.icon)
- {
- TERMPTY_WRITE_STR(ty->prop.icon);
- }
- TERMPTY_WRITE_STR("\007");
+ /* returns empty string. See CVE-2003-0063 */
+ TERMPTY_WRITE_STR("\033]1;Terminology\007");
}
else
{
@@ -1365,12 +1357,8 @@ _handle_esc_xterm(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
goto err;
if (*p == '?')
{
- TERMPTY_WRITE_STR("\033]0;");
- if (ty->prop.title)
- {
- TERMPTY_WRITE_STR(ty->prop.title);
- }
- TERMPTY_WRITE_STR("\007");
+ /* returns empty string. See CVE-2003-0063 */
+ TERMPTY_WRITE_STR("\033]2;Terminology\007");
}
else
{ | CWE-77 | null | null |
12,733 | _handle_esc_csi_reset_mode(Termpty *ty, Eina_Unicode cc, Eina_Unicode *b)
{
int mode = 0, priv = 0, arg;
if (cc == 'h') mode = 1;
if (*b == '?')
{
priv = 1;
b++;
}
if (priv) /* DEC Private Mode Reset (DECRST) */
{
while (b)
{
arg = _csi_arg_get(&b);
if (b)
{
switch (arg)
{
case 1:
ty->termstate.appcursor = mode;
break;
case 2:
ty->termstate.kbd_lock = mode;
break;
case 3: // 132 column mode… should we handle this?
#if defined(SUPPORT_80_132_COLUMNS)
if (ty->termstate.att.is_80_132_mode_allowed)
{
/* ONLY FOR TESTING PURPOSE FTM */
Evas_Object *wn;
int w, h;
wn = termio_win_get(ty->obj);
elm_win_size_step_get(wn, &w, &h);
evas_object_resize(wn,
4 +
(mode ? 132 : 80) * w,
4 + ty->h * h);
termpty_resize(ty, mode ? 132 : 80,
ty->h);
termpty_reset_state(ty);
termpty_clear_screen(ty,
TERMPTY_CLR_ALL);
}
#endif
break;
case 4:
WRN("TODO: scrolling mode (DECSCLM): %i", mode);
break;
case 5:
ty->termstate.reverse = mode;
break;
case 6:
if (mode)
{
ty->termstate.margin_top = ty->cursor_state.cy;
ty->cursor_state.cx = 0;
}
else
{
ty->cursor_state.cx = 0;
ty->termstate.margin_top = 0;
}
DBG("origin mode (%d): cursor is at 0,0"
" cursor limited to screen/start point"
" for line #'s depends on top margin",
mode);
break;
case 7:
DBG("set wrap mode to %i", mode);
ty->termstate.wrap = mode;
break;
case 8:
ty->termstate.no_autorepeat = !mode;
DBG("auto repeat %i", mode);
break;
case 9:
DBG("set mouse (X10) %i", mode);
if (mode) ty->mouse_mode = MOUSE_X10;
else ty->mouse_mode = MOUSE_OFF;
break;
case 12: // ignore
WRN("TODO: set blinking cursor to (stop?) %i or local echo (ignored)", mode);
break;
case 19: // never seen this - what to do?
WRN("TODO: set print extent to full screen");
break;
case 20: // crfl==1 -> cur moves to col 0 on LF, FF or VT, ==0 -> mode is cr+lf
ty->termstate.crlf = mode;
break;
case 25:
ty->termstate.hide_cursor = !mode;
DBG("hide cursor: %d", !mode);
break;
case 30: // ignore
WRN("TODO: set scrollbar mapping %i", mode);
break;
case 33: // ignore
WRN("TODO: Stop cursor blink %i", mode);
break;
case 34: // ignore
WRN("TODO: Underline cursor mode %i", mode);
break;
case 35: // ignore
WRN("TODO: set shift keys %i", mode);
break;
case 38: // ignore
WRN("TODO: switch to tek window %i", mode);
break;
case 40:
DBG("Allow 80 -> 132 Mode %i", mode);
#if defined(SUPPORT_80_132_COLUMNS)
ty->termstate.att.is_80_132_mode_allowed = mode;
#endif
break;
case 45: // ignore
WRN("TODO: Reverse-wraparound Mode");
break;
case 59: // ignore
WRN("TODO: kanji terminal mode %i", mode);
break;
case 66:
WRN("TODO: app keypad mode %i", mode);
break;
case 67:
ty->termstate.send_bs = mode;
DBG("backspace send bs not del = %i", mode);
break;
case 1000:
if (mode) ty->mouse_mode = MOUSE_NORMAL;
else ty->mouse_mode = MOUSE_OFF;
DBG("set mouse (press+release only) to %i", mode);
break;
case 1001:
WRN("TODO: x11 mouse highlighting %i", mode);
break;
case 1002:
if (mode) ty->mouse_mode = MOUSE_NORMAL_BTN_MOVE;
else ty->mouse_mode = MOUSE_OFF;
DBG("set mouse (press+release+motion while pressed) %i", mode);
break;
case 1003:
if (mode) ty->mouse_mode = MOUSE_NORMAL_ALL_MOVE;
else ty->mouse_mode = MOUSE_OFF;
DBG("set mouse (press+release+all motion) %i", mode);
break;
case 1004: // i dont know what focus repporting is?
WRN("TODO: enable focus reporting %i", mode);
break;
case 1005:
if (mode) ty->mouse_ext = MOUSE_EXT_UTF8;
else ty->mouse_ext = MOUSE_EXT_NONE;
DBG("set mouse (xterm utf8 style) %i", mode);
break;
case 1006:
if (mode) ty->mouse_ext = MOUSE_EXT_SGR;
else ty->mouse_ext = MOUSE_EXT_NONE;
DBG("set mouse (xterm sgr style) %i", mode);
break;
case 1010: // ignore
WRN("TODO: set home on tty output %i", mode);
break;
case 1012: // ignore
WRN("TODO: set home on tty input %i", mode);
break;
case 1015:
if (mode) ty->mouse_ext = MOUSE_EXT_URXVT;
else ty->mouse_ext = MOUSE_EXT_NONE;
DBG("set mouse (rxvt-unicode style) %i", mode);
break;
case 1034: // ignore
/* libreadline6 emits it but it shouldn't.
See http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=577012
*/
DBG("Ignored screen mode %i", arg);
break;
case 1047:
case 47:
_switch_to_alternative_screen(ty, mode);
break;
case 1048:
case 1049:
termpty_cursor_copy(ty, mode);
if (arg == 1049)
_switch_to_alternative_screen(ty, mode);
break;
case 2004:
ty->bracketed_paste = mode;
break;
case 7727: // ignore
WRN("TODO: enable application escape mode %i", mode);
break;
case 7786: // ignore
WRN("TODO: enable mouse wheel -> cursor key xlation %i", mode);
break;
default:
ERR("Unhandled DEC Private Reset Mode arg %i", arg);
break;
}
}
}
}
else /* Reset Mode (RM) */
{
while (b)
{
arg = _csi_arg_get(&b);
if (b)
{
switch (arg)
{
case 1:
ty->termstate.appcursor = mode;
break;
case 4:
DBG("set insert mode to %i", mode);
ty->termstate.insert = mode;
break;
case 34:
WRN("TODO: hebrew keyboard mapping: %i", mode);
break;
case 36:
WRN("TODO: hebrew encoding mode: %i", mode);
break;
default:
ERR("Unhandled ANSI Reset Mode arg %i", arg);
}
}
}
}
}
| Exec Code | 0 | _handle_esc_csi_reset_mode(Termpty *ty, Eina_Unicode cc, Eina_Unicode *b)
{
int mode = 0, priv = 0, arg;
if (cc == 'h') mode = 1;
if (*b == '?')
{
priv = 1;
b++;
}
if (priv) /* DEC Private Mode Reset (DECRST) */
{
while (b)
{
arg = _csi_arg_get(&b);
if (b)
{
switch (arg)
{
case 1:
ty->termstate.appcursor = mode;
break;
case 2:
ty->termstate.kbd_lock = mode;
break;
case 3: // 132 column mode… should we handle this?
#if defined(SUPPORT_80_132_COLUMNS)
if (ty->termstate.att.is_80_132_mode_allowed)
{
/* ONLY FOR TESTING PURPOSE FTM */
Evas_Object *wn;
int w, h;
wn = termio_win_get(ty->obj);
elm_win_size_step_get(wn, &w, &h);
evas_object_resize(wn,
4 +
(mode ? 132 : 80) * w,
4 + ty->h * h);
termpty_resize(ty, mode ? 132 : 80,
ty->h);
termpty_reset_state(ty);
termpty_clear_screen(ty,
TERMPTY_CLR_ALL);
}
#endif
break;
case 4:
WRN("TODO: scrolling mode (DECSCLM): %i", mode);
break;
case 5:
ty->termstate.reverse = mode;
break;
case 6:
if (mode)
{
ty->termstate.margin_top = ty->cursor_state.cy;
ty->cursor_state.cx = 0;
}
else
{
ty->cursor_state.cx = 0;
ty->termstate.margin_top = 0;
}
DBG("origin mode (%d): cursor is at 0,0"
" cursor limited to screen/start point"
" for line #'s depends on top margin",
mode);
break;
case 7:
DBG("set wrap mode to %i", mode);
ty->termstate.wrap = mode;
break;
case 8:
ty->termstate.no_autorepeat = !mode;
DBG("auto repeat %i", mode);
break;
case 9:
DBG("set mouse (X10) %i", mode);
if (mode) ty->mouse_mode = MOUSE_X10;
else ty->mouse_mode = MOUSE_OFF;
break;
case 12: // ignore
WRN("TODO: set blinking cursor to (stop?) %i or local echo (ignored)", mode);
break;
case 19: // never seen this - what to do?
WRN("TODO: set print extent to full screen");
break;
case 20: // crfl==1 -> cur moves to col 0 on LF, FF or VT, ==0 -> mode is cr+lf
ty->termstate.crlf = mode;
break;
case 25:
ty->termstate.hide_cursor = !mode;
DBG("hide cursor: %d", !mode);
break;
case 30: // ignore
WRN("TODO: set scrollbar mapping %i", mode);
break;
case 33: // ignore
WRN("TODO: Stop cursor blink %i", mode);
break;
case 34: // ignore
WRN("TODO: Underline cursor mode %i", mode);
break;
case 35: // ignore
WRN("TODO: set shift keys %i", mode);
break;
case 38: // ignore
WRN("TODO: switch to tek window %i", mode);
break;
case 40:
DBG("Allow 80 -> 132 Mode %i", mode);
#if defined(SUPPORT_80_132_COLUMNS)
ty->termstate.att.is_80_132_mode_allowed = mode;
#endif
break;
case 45: // ignore
WRN("TODO: Reverse-wraparound Mode");
break;
case 59: // ignore
WRN("TODO: kanji terminal mode %i", mode);
break;
case 66:
WRN("TODO: app keypad mode %i", mode);
break;
case 67:
ty->termstate.send_bs = mode;
DBG("backspace send bs not del = %i", mode);
break;
case 1000:
if (mode) ty->mouse_mode = MOUSE_NORMAL;
else ty->mouse_mode = MOUSE_OFF;
DBG("set mouse (press+release only) to %i", mode);
break;
case 1001:
WRN("TODO: x11 mouse highlighting %i", mode);
break;
case 1002:
if (mode) ty->mouse_mode = MOUSE_NORMAL_BTN_MOVE;
else ty->mouse_mode = MOUSE_OFF;
DBG("set mouse (press+release+motion while pressed) %i", mode);
break;
case 1003:
if (mode) ty->mouse_mode = MOUSE_NORMAL_ALL_MOVE;
else ty->mouse_mode = MOUSE_OFF;
DBG("set mouse (press+release+all motion) %i", mode);
break;
case 1004: // i dont know what focus repporting is?
WRN("TODO: enable focus reporting %i", mode);
break;
case 1005:
if (mode) ty->mouse_ext = MOUSE_EXT_UTF8;
else ty->mouse_ext = MOUSE_EXT_NONE;
DBG("set mouse (xterm utf8 style) %i", mode);
break;
case 1006:
if (mode) ty->mouse_ext = MOUSE_EXT_SGR;
else ty->mouse_ext = MOUSE_EXT_NONE;
DBG("set mouse (xterm sgr style) %i", mode);
break;
case 1010: // ignore
WRN("TODO: set home on tty output %i", mode);
break;
case 1012: // ignore
WRN("TODO: set home on tty input %i", mode);
break;
case 1015:
if (mode) ty->mouse_ext = MOUSE_EXT_URXVT;
else ty->mouse_ext = MOUSE_EXT_NONE;
DBG("set mouse (rxvt-unicode style) %i", mode);
break;
case 1034: // ignore
/* libreadline6 emits it but it shouldn't.
See http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=577012
*/
DBG("Ignored screen mode %i", arg);
break;
case 1047:
case 47:
_switch_to_alternative_screen(ty, mode);
break;
case 1048:
case 1049:
termpty_cursor_copy(ty, mode);
if (arg == 1049)
_switch_to_alternative_screen(ty, mode);
break;
case 2004:
ty->bracketed_paste = mode;
break;
case 7727: // ignore
WRN("TODO: enable application escape mode %i", mode);
break;
case 7786: // ignore
WRN("TODO: enable mouse wheel -> cursor key xlation %i", mode);
break;
default:
ERR("Unhandled DEC Private Reset Mode arg %i", arg);
break;
}
}
}
}
else /* Reset Mode (RM) */
{
while (b)
{
arg = _csi_arg_get(&b);
if (b)
{
switch (arg)
{
case 1:
ty->termstate.appcursor = mode;
break;
case 4:
DBG("set insert mode to %i", mode);
ty->termstate.insert = mode;
break;
case 34:
WRN("TODO: hebrew keyboard mapping: %i", mode);
break;
case 36:
WRN("TODO: hebrew encoding mode: %i", mode);
break;
default:
ERR("Unhandled ANSI Reset Mode arg %i", arg);
}
}
}
}
}
| @@ -1303,12 +1303,8 @@ _handle_esc_xterm(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
goto err;
if (*p == '?')
{
- TERMPTY_WRITE_STR("\033]0;");
- if (ty->prop.title)
- {
- TERMPTY_WRITE_STR(ty->prop.title);
- }
- TERMPTY_WRITE_STR("\007");
+ /* returns empty string. See CVE-2003-0063 */
+ TERMPTY_WRITE_STR("\033]0;Terminology\007");
}
else
{
@@ -1336,12 +1332,8 @@ _handle_esc_xterm(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
goto err;
if (*p == '?')
{
- TERMPTY_WRITE_STR("\033]0;");
- if (ty->prop.icon)
- {
- TERMPTY_WRITE_STR(ty->prop.icon);
- }
- TERMPTY_WRITE_STR("\007");
+ /* returns empty string. See CVE-2003-0063 */
+ TERMPTY_WRITE_STR("\033]1;Terminology\007");
}
else
{
@@ -1365,12 +1357,8 @@ _handle_esc_xterm(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
goto err;
if (*p == '?')
{
- TERMPTY_WRITE_STR("\033]0;");
- if (ty->prop.title)
- {
- TERMPTY_WRITE_STR(ty->prop.title);
- }
- TERMPTY_WRITE_STR("\007");
+ /* returns empty string. See CVE-2003-0063 */
+ TERMPTY_WRITE_STR("\033]2;Terminology\007");
}
else
{ | CWE-77 | null | null |
12,734 | static void msix_clr_pending(PCIDevice *dev, int vector)
{
*msix_pending_byte(dev, vector) &= ~msix_pending_mask(vector);
}
| DoS | 0 | static void msix_clr_pending(PCIDevice *dev, int vector)
{
*msix_pending_byte(dev, vector) &= ~msix_pending_mask(vector);
}
| @@ -200,8 +200,14 @@ static uint64_t msix_pba_mmio_read(void *opaque, hwaddr addr,
return pci_get_long(dev->msix_pba + addr);
}
+static void msix_pba_mmio_write(void *opaque, hwaddr addr,
+ uint64_t val, unsigned size)
+{
+}
+
static const MemoryRegionOps msix_pba_mmio_ops = {
.read = msix_pba_mmio_read,
+ .write = msix_pba_mmio_write,
.endianness = DEVICE_LITTLE_ENDIAN,
.valid = {
.min_access_size = 4, | CWE-476 | null | null |
12,735 | static void msix_fire_vector_notifier(PCIDevice *dev,
unsigned int vector, bool is_masked)
{
MSIMessage msg;
int ret;
if (!dev->msix_vector_use_notifier) {
return;
}
if (is_masked) {
dev->msix_vector_release_notifier(dev, vector);
} else {
msg = msix_get_message(dev, vector);
ret = dev->msix_vector_use_notifier(dev, vector, msg);
assert(ret >= 0);
}
}
| DoS | 0 | static void msix_fire_vector_notifier(PCIDevice *dev,
unsigned int vector, bool is_masked)
{
MSIMessage msg;
int ret;
if (!dev->msix_vector_use_notifier) {
return;
}
if (is_masked) {
dev->msix_vector_release_notifier(dev, vector);
} else {
msg = msix_get_message(dev, vector);
ret = dev->msix_vector_use_notifier(dev, vector, msg);
assert(ret >= 0);
}
}
| @@ -200,8 +200,14 @@ static uint64_t msix_pba_mmio_read(void *opaque, hwaddr addr,
return pci_get_long(dev->msix_pba + addr);
}
+static void msix_pba_mmio_write(void *opaque, hwaddr addr,
+ uint64_t val, unsigned size)
+{
+}
+
static const MemoryRegionOps msix_pba_mmio_ops = {
.read = msix_pba_mmio_read,
+ .write = msix_pba_mmio_write,
.endianness = DEVICE_LITTLE_ENDIAN,
.valid = {
.min_access_size = 4, | CWE-476 | null | null |
12,736 | MSIMessage msix_get_message(PCIDevice *dev, unsigned vector)
{
uint8_t *table_entry = dev->msix_table + vector * PCI_MSIX_ENTRY_SIZE;
MSIMessage msg;
msg.address = pci_get_quad(table_entry + PCI_MSIX_ENTRY_LOWER_ADDR);
msg.data = pci_get_long(table_entry + PCI_MSIX_ENTRY_DATA);
return msg;
}
| DoS | 0 | MSIMessage msix_get_message(PCIDevice *dev, unsigned vector)
{
uint8_t *table_entry = dev->msix_table + vector * PCI_MSIX_ENTRY_SIZE;
MSIMessage msg;
msg.address = pci_get_quad(table_entry + PCI_MSIX_ENTRY_LOWER_ADDR);
msg.data = pci_get_long(table_entry + PCI_MSIX_ENTRY_DATA);
return msg;
}
| @@ -200,8 +200,14 @@ static uint64_t msix_pba_mmio_read(void *opaque, hwaddr addr,
return pci_get_long(dev->msix_pba + addr);
}
+static void msix_pba_mmio_write(void *opaque, hwaddr addr,
+ uint64_t val, unsigned size)
+{
+}
+
static const MemoryRegionOps msix_pba_mmio_ops = {
.read = msix_pba_mmio_read,
+ .write = msix_pba_mmio_write,
.endianness = DEVICE_LITTLE_ENDIAN,
.valid = {
.min_access_size = 4, | CWE-476 | null | null |
12,737 | static void msix_handle_mask_update(PCIDevice *dev, int vector, bool was_masked)
{
bool is_masked = msix_is_masked(dev, vector);
if (is_masked == was_masked) {
return;
}
msix_fire_vector_notifier(dev, vector, is_masked);
if (!is_masked && msix_is_pending(dev, vector)) {
msix_clr_pending(dev, vector);
msix_notify(dev, vector);
}
}
| DoS | 0 | static void msix_handle_mask_update(PCIDevice *dev, int vector, bool was_masked)
{
bool is_masked = msix_is_masked(dev, vector);
if (is_masked == was_masked) {
return;
}
msix_fire_vector_notifier(dev, vector, is_masked);
if (!is_masked && msix_is_pending(dev, vector)) {
msix_clr_pending(dev, vector);
msix_notify(dev, vector);
}
}
| @@ -200,8 +200,14 @@ static uint64_t msix_pba_mmio_read(void *opaque, hwaddr addr,
return pci_get_long(dev->msix_pba + addr);
}
+static void msix_pba_mmio_write(void *opaque, hwaddr addr,
+ uint64_t val, unsigned size)
+{
+}
+
static const MemoryRegionOps msix_pba_mmio_ops = {
.read = msix_pba_mmio_read,
+ .write = msix_pba_mmio_write,
.endianness = DEVICE_LITTLE_ENDIAN,
.valid = {
.min_access_size = 4, | CWE-476 | null | null |
12,738 | bool msix_is_masked(PCIDevice *dev, unsigned int vector)
{
return msix_vector_masked(dev, vector, dev->msix_function_masked);
}
| DoS | 0 | bool msix_is_masked(PCIDevice *dev, unsigned int vector)
{
return msix_vector_masked(dev, vector, dev->msix_function_masked);
}
| @@ -200,8 +200,14 @@ static uint64_t msix_pba_mmio_read(void *opaque, hwaddr addr,
return pci_get_long(dev->msix_pba + addr);
}
+static void msix_pba_mmio_write(void *opaque, hwaddr addr,
+ uint64_t val, unsigned size)
+{
+}
+
static const MemoryRegionOps msix_pba_mmio_ops = {
.read = msix_pba_mmio_read,
+ .write = msix_pba_mmio_write,
.endianness = DEVICE_LITTLE_ENDIAN,
.valid = {
.min_access_size = 4, | CWE-476 | null | null |
12,739 | static int msix_is_pending(PCIDevice *dev, int vector)
{
return *msix_pending_byte(dev, vector) & msix_pending_mask(vector);
}
| DoS | 0 | static int msix_is_pending(PCIDevice *dev, int vector)
{
return *msix_pending_byte(dev, vector) & msix_pending_mask(vector);
}
| @@ -200,8 +200,14 @@ static uint64_t msix_pba_mmio_read(void *opaque, hwaddr addr,
return pci_get_long(dev->msix_pba + addr);
}
+static void msix_pba_mmio_write(void *opaque, hwaddr addr,
+ uint64_t val, unsigned size)
+{
+}
+
static const MemoryRegionOps msix_pba_mmio_ops = {
.read = msix_pba_mmio_read,
+ .write = msix_pba_mmio_write,
.endianness = DEVICE_LITTLE_ENDIAN,
.valid = {
.min_access_size = 4, | CWE-476 | null | null |
12,740 | static uint8_t *msix_pending_byte(PCIDevice *dev, int vector)
{
return dev->msix_pba + vector / 8;
}
| DoS | 0 | static uint8_t *msix_pending_byte(PCIDevice *dev, int vector)
{
return dev->msix_pba + vector / 8;
}
| @@ -200,8 +200,14 @@ static uint64_t msix_pba_mmio_read(void *opaque, hwaddr addr,
return pci_get_long(dev->msix_pba + addr);
}
+static void msix_pba_mmio_write(void *opaque, hwaddr addr,
+ uint64_t val, unsigned size)
+{
+}
+
static const MemoryRegionOps msix_pba_mmio_ops = {
.read = msix_pba_mmio_read,
+ .write = msix_pba_mmio_write,
.endianness = DEVICE_LITTLE_ENDIAN,
.valid = {
.min_access_size = 4, | CWE-476 | null | null |
12,741 | static uint8_t msix_pending_mask(int vector)
{
return 1 << (vector % 8);
}
| DoS | 0 | static uint8_t msix_pending_mask(int vector)
{
return 1 << (vector % 8);
}
| @@ -200,8 +200,14 @@ static uint64_t msix_pba_mmio_read(void *opaque, hwaddr addr,
return pci_get_long(dev->msix_pba + addr);
}
+static void msix_pba_mmio_write(void *opaque, hwaddr addr,
+ uint64_t val, unsigned size)
+{
+}
+
static const MemoryRegionOps msix_pba_mmio_ops = {
.read = msix_pba_mmio_read,
+ .write = msix_pba_mmio_write,
.endianness = DEVICE_LITTLE_ENDIAN,
.valid = {
.min_access_size = 4, | CWE-476 | null | null |
12,742 | void msix_set_message(PCIDevice *dev, int vector, struct MSIMessage msg)
{
uint8_t *table_entry = dev->msix_table + vector * PCI_MSIX_ENTRY_SIZE;
pci_set_quad(table_entry + PCI_MSIX_ENTRY_LOWER_ADDR, msg.address);
pci_set_long(table_entry + PCI_MSIX_ENTRY_DATA, msg.data);
table_entry[PCI_MSIX_ENTRY_VECTOR_CTRL] &= ~PCI_MSIX_ENTRY_CTRL_MASKBIT;
}
| DoS | 0 | void msix_set_message(PCIDevice *dev, int vector, struct MSIMessage msg)
{
uint8_t *table_entry = dev->msix_table + vector * PCI_MSIX_ENTRY_SIZE;
pci_set_quad(table_entry + PCI_MSIX_ENTRY_LOWER_ADDR, msg.address);
pci_set_long(table_entry + PCI_MSIX_ENTRY_DATA, msg.data);
table_entry[PCI_MSIX_ENTRY_VECTOR_CTRL] &= ~PCI_MSIX_ENTRY_CTRL_MASKBIT;
}
| @@ -200,8 +200,14 @@ static uint64_t msix_pba_mmio_read(void *opaque, hwaddr addr,
return pci_get_long(dev->msix_pba + addr);
}
+static void msix_pba_mmio_write(void *opaque, hwaddr addr,
+ uint64_t val, unsigned size)
+{
+}
+
static const MemoryRegionOps msix_pba_mmio_ops = {
.read = msix_pba_mmio_read,
+ .write = msix_pba_mmio_write,
.endianness = DEVICE_LITTLE_ENDIAN,
.valid = {
.min_access_size = 4, | CWE-476 | null | null |
12,743 | void msix_set_pending(PCIDevice *dev, unsigned int vector)
{
*msix_pending_byte(dev, vector) |= msix_pending_mask(vector);
}
| DoS | 0 | void msix_set_pending(PCIDevice *dev, unsigned int vector)
{
*msix_pending_byte(dev, vector) |= msix_pending_mask(vector);
}
| @@ -200,8 +200,14 @@ static uint64_t msix_pba_mmio_read(void *opaque, hwaddr addr,
return pci_get_long(dev->msix_pba + addr);
}
+static void msix_pba_mmio_write(void *opaque, hwaddr addr,
+ uint64_t val, unsigned size)
+{
+}
+
static const MemoryRegionOps msix_pba_mmio_ops = {
.read = msix_pba_mmio_read,
+ .write = msix_pba_mmio_write,
.endianness = DEVICE_LITTLE_ENDIAN,
.valid = {
.min_access_size = 4, | CWE-476 | null | null |
12,744 | static uint64_t msix_table_mmio_read(void *opaque, hwaddr addr,
unsigned size)
{
PCIDevice *dev = opaque;
return pci_get_long(dev->msix_table + addr);
}
| DoS | 0 | static uint64_t msix_table_mmio_read(void *opaque, hwaddr addr,
unsigned size)
{
PCIDevice *dev = opaque;
return pci_get_long(dev->msix_table + addr);
}
| @@ -200,8 +200,14 @@ static uint64_t msix_pba_mmio_read(void *opaque, hwaddr addr,
return pci_get_long(dev->msix_pba + addr);
}
+static void msix_pba_mmio_write(void *opaque, hwaddr addr,
+ uint64_t val, unsigned size)
+{
+}
+
static const MemoryRegionOps msix_pba_mmio_ops = {
.read = msix_pba_mmio_read,
+ .write = msix_pba_mmio_write,
.endianness = DEVICE_LITTLE_ENDIAN,
.valid = {
.min_access_size = 4, | CWE-476 | null | null |
12,745 | static void msix_table_mmio_write(void *opaque, hwaddr addr,
uint64_t val, unsigned size)
{
PCIDevice *dev = opaque;
int vector = addr / PCI_MSIX_ENTRY_SIZE;
bool was_masked;
was_masked = msix_is_masked(dev, vector);
pci_set_long(dev->msix_table + addr, val);
msix_handle_mask_update(dev, vector, was_masked);
}
| DoS | 0 | static void msix_table_mmio_write(void *opaque, hwaddr addr,
uint64_t val, unsigned size)
{
PCIDevice *dev = opaque;
int vector = addr / PCI_MSIX_ENTRY_SIZE;
bool was_masked;
was_masked = msix_is_masked(dev, vector);
pci_set_long(dev->msix_table + addr, val);
msix_handle_mask_update(dev, vector, was_masked);
}
| @@ -200,8 +200,14 @@ static uint64_t msix_pba_mmio_read(void *opaque, hwaddr addr,
return pci_get_long(dev->msix_pba + addr);
}
+static void msix_pba_mmio_write(void *opaque, hwaddr addr,
+ uint64_t val, unsigned size)
+{
+}
+
static const MemoryRegionOps msix_pba_mmio_ops = {
.read = msix_pba_mmio_read,
+ .write = msix_pba_mmio_write,
.endianness = DEVICE_LITTLE_ENDIAN,
.valid = {
.min_access_size = 4, | CWE-476 | null | null |
12,746 | static void msix_update_function_masked(PCIDevice *dev)
{
dev->msix_function_masked = !msix_enabled(dev) ||
(dev->config[dev->msix_cap + MSIX_CONTROL_OFFSET] & MSIX_MASKALL_MASK);
}
| DoS | 0 | static void msix_update_function_masked(PCIDevice *dev)
{
dev->msix_function_masked = !msix_enabled(dev) ||
(dev->config[dev->msix_cap + MSIX_CONTROL_OFFSET] & MSIX_MASKALL_MASK);
}
| @@ -200,8 +200,14 @@ static uint64_t msix_pba_mmio_read(void *opaque, hwaddr addr,
return pci_get_long(dev->msix_pba + addr);
}
+static void msix_pba_mmio_write(void *opaque, hwaddr addr,
+ uint64_t val, unsigned size)
+{
+}
+
static const MemoryRegionOps msix_pba_mmio_ops = {
.read = msix_pba_mmio_read,
+ .write = msix_pba_mmio_write,
.endianness = DEVICE_LITTLE_ENDIAN,
.valid = {
.min_access_size = 4, | CWE-476 | null | null |
12,747 | static bool msix_vector_masked(PCIDevice *dev, unsigned int vector, bool fmask)
{
unsigned offset = vector * PCI_MSIX_ENTRY_SIZE + PCI_MSIX_ENTRY_VECTOR_CTRL;
return fmask || dev->msix_table[offset] & PCI_MSIX_ENTRY_CTRL_MASKBIT;
}
| DoS | 0 | static bool msix_vector_masked(PCIDevice *dev, unsigned int vector, bool fmask)
{
unsigned offset = vector * PCI_MSIX_ENTRY_SIZE + PCI_MSIX_ENTRY_VECTOR_CTRL;
return fmask || dev->msix_table[offset] & PCI_MSIX_ENTRY_CTRL_MASKBIT;
}
| @@ -200,8 +200,14 @@ static uint64_t msix_pba_mmio_read(void *opaque, hwaddr addr,
return pci_get_long(dev->msix_pba + addr);
}
+static void msix_pba_mmio_write(void *opaque, hwaddr addr,
+ uint64_t val, unsigned size)
+{
+}
+
static const MemoryRegionOps msix_pba_mmio_ops = {
.read = msix_pba_mmio_read,
+ .write = msix_pba_mmio_write,
.endianness = DEVICE_LITTLE_ENDIAN,
.valid = {
.min_access_size = 4, | CWE-476 | null | null |
12,748 | void msix_write_config(PCIDevice *dev, uint32_t addr,
uint32_t val, int len)
{
unsigned enable_pos = dev->msix_cap + MSIX_CONTROL_OFFSET;
int vector;
bool was_masked;
if (!msix_present(dev) || !range_covers_byte(addr, len, enable_pos)) {
return;
}
was_masked = dev->msix_function_masked;
msix_update_function_masked(dev);
if (!msix_enabled(dev)) {
return;
}
pci_device_deassert_intx(dev);
if (dev->msix_function_masked == was_masked) {
return;
}
for (vector = 0; vector < dev->msix_entries_nr; ++vector) {
msix_handle_mask_update(dev, vector,
msix_vector_masked(dev, vector, was_masked));
}
}
| DoS | 0 | void msix_write_config(PCIDevice *dev, uint32_t addr,
uint32_t val, int len)
{
unsigned enable_pos = dev->msix_cap + MSIX_CONTROL_OFFSET;
int vector;
bool was_masked;
if (!msix_present(dev) || !range_covers_byte(addr, len, enable_pos)) {
return;
}
was_masked = dev->msix_function_masked;
msix_update_function_masked(dev);
if (!msix_enabled(dev)) {
return;
}
pci_device_deassert_intx(dev);
if (dev->msix_function_masked == was_masked) {
return;
}
for (vector = 0; vector < dev->msix_entries_nr; ++vector) {
msix_handle_mask_update(dev, vector,
msix_vector_masked(dev, vector, was_masked));
}
}
| @@ -200,8 +200,14 @@ static uint64_t msix_pba_mmio_read(void *opaque, hwaddr addr,
return pci_get_long(dev->msix_pba + addr);
}
+static void msix_pba_mmio_write(void *opaque, hwaddr addr,
+ uint64_t val, unsigned size)
+{
+}
+
static const MemoryRegionOps msix_pba_mmio_ops = {
.read = msix_pba_mmio_read,
+ .write = msix_pba_mmio_write,
.endianness = DEVICE_LITTLE_ENDIAN,
.valid = {
.min_access_size = 4, | CWE-476 | null | null |
12,749 | bool ConvertFromMacLang ( const std::string & macValue, XMP_Uns16 macLang, std::string * utf8Value )
{
utf8Value->erase();
if ( ! IsMacLangKnown ( macLang ) ) return false;
#if XMP_MacBuild
XMP_Uns16 macScript = GetMacScript ( macLang );
ReconcileUtils::MacEncodingToUTF8 ( macScript, macLang, (XMP_Uns8*)macValue.c_str(), macValue.size(), utf8Value );
#elif XMP_UNIXBuild
MacRomanToUTF8 ( macValue, utf8Value );
#elif XMP_WinBuild
UINT winCP = GetWinCP ( macLang );
ReconcileUtils::WinEncodingToUTF8 ( winCP, (XMP_Uns8*)macValue.c_str(), macValue.size(), utf8Value );
#elif XMP_iOSBuild
XMP_Uns32 iosEncCF = GetIOSEncodingCF(macLang);
ReconcileUtils::IOSConvertEncoding(iosEncCF, kCFStringEncodingUTF8, (XMP_Uns8*)macValue.c_str(), macValue.size(), utf8Value);
#endif
return true;
} // ConvertFromMacLang
| DoS | 0 | bool ConvertFromMacLang ( const std::string & macValue, XMP_Uns16 macLang, std::string * utf8Value )
{
utf8Value->erase();
if ( ! IsMacLangKnown ( macLang ) ) return false;
#if XMP_MacBuild
XMP_Uns16 macScript = GetMacScript ( macLang );
ReconcileUtils::MacEncodingToUTF8 ( macScript, macLang, (XMP_Uns8*)macValue.c_str(), macValue.size(), utf8Value );
#elif XMP_UNIXBuild
MacRomanToUTF8 ( macValue, utf8Value );
#elif XMP_WinBuild
UINT winCP = GetWinCP ( macLang );
ReconcileUtils::WinEncodingToUTF8 ( winCP, (XMP_Uns8*)macValue.c_str(), macValue.size(), utf8Value );
#elif XMP_iOSBuild
XMP_Uns32 iosEncCF = GetIOSEncodingCF(macLang);
ReconcileUtils::IOSConvertEncoding(iosEncCF, kCFStringEncodingUTF8, (XMP_Uns8*)macValue.c_str(), macValue.size(), utf8Value);
#endif
return true;
} // ConvertFromMacLang
| @@ -920,7 +920,8 @@ bool TradQT_Manager::ParseCachedBoxes ( const MOOV_Manager & moovMgr )
miniLen = 4 + GetUns16BE ( boxPtr ); // ! Include header in local miniLen.
macLang = GetUns16BE ( boxPtr+2);
- if ( (miniLen <= 4) || (miniLen > (boxEnd - boxPtr)) ) continue; // Ignore bad or empty values.
+ if ( (miniLen <= 4) || (miniLen > (boxEnd - boxPtr)) )
+ break; // Ignore bad or empty values.
XMP_StringPtr valuePtr = (char*)(boxPtr+4);
size_t valueLen = miniLen - 4; | CWE-835 | null | null |
12,750 | bool ConvertToMacLang ( const std::string & utf8Value, XMP_Uns16 macLang, std::string * macValue )
{
macValue->erase();
if ( macLang == kNoMacLang ) macLang = 0; // *** Zero is English, ought to use the "active" OS lang.
if ( ! IsMacLangKnown ( macLang ) ) return false;
#if XMP_MacBuild
XMP_Uns16 macScript = GetMacScript ( macLang );
ReconcileUtils::UTF8ToMacEncoding ( macScript, macLang, (XMP_Uns8*)utf8Value.c_str(), utf8Value.size(), macValue );
#elif XMP_UNIXBuild
UTF8ToMacRoman ( utf8Value, macValue );
#elif XMP_WinBuild
UINT winCP = GetWinCP ( macLang );
ReconcileUtils::UTF8ToWinEncoding ( winCP, (XMP_Uns8*)utf8Value.c_str(), utf8Value.size(), macValue );
#elif XMP_iOSBuild
XMP_Uns32 iosEncCF = GetIOSEncodingCF(macLang);
ReconcileUtils::IOSConvertEncoding(kCFStringEncodingUTF8, iosEncCF, (XMP_Uns8*)utf8Value.c_str(), utf8Value.size(), macValue);
#endif
return true;
} // ConvertToMacLang
| DoS | 0 | bool ConvertToMacLang ( const std::string & utf8Value, XMP_Uns16 macLang, std::string * macValue )
{
macValue->erase();
if ( macLang == kNoMacLang ) macLang = 0; // *** Zero is English, ought to use the "active" OS lang.
if ( ! IsMacLangKnown ( macLang ) ) return false;
#if XMP_MacBuild
XMP_Uns16 macScript = GetMacScript ( macLang );
ReconcileUtils::UTF8ToMacEncoding ( macScript, macLang, (XMP_Uns8*)utf8Value.c_str(), utf8Value.size(), macValue );
#elif XMP_UNIXBuild
UTF8ToMacRoman ( utf8Value, macValue );
#elif XMP_WinBuild
UINT winCP = GetWinCP ( macLang );
ReconcileUtils::UTF8ToWinEncoding ( winCP, (XMP_Uns8*)utf8Value.c_str(), utf8Value.size(), macValue );
#elif XMP_iOSBuild
XMP_Uns32 iosEncCF = GetIOSEncodingCF(macLang);
ReconcileUtils::IOSConvertEncoding(kCFStringEncodingUTF8, iosEncCF, (XMP_Uns8*)utf8Value.c_str(), utf8Value.size(), macValue);
#endif
return true;
} // ConvertToMacLang
| @@ -920,7 +920,8 @@ bool TradQT_Manager::ParseCachedBoxes ( const MOOV_Manager & moovMgr )
miniLen = 4 + GetUns16BE ( boxPtr ); // ! Include header in local miniLen.
macLang = GetUns16BE ( boxPtr+2);
- if ( (miniLen <= 4) || (miniLen > (boxEnd - boxPtr)) ) continue; // Ignore bad or empty values.
+ if ( (miniLen <= 4) || (miniLen > (boxEnd - boxPtr)) )
+ break; // Ignore bad or empty values.
XMP_StringPtr valuePtr = (char*)(boxPtr+4);
size_t valueLen = miniLen - 4; | CWE-835 | null | null |
12,751 | void TradQT_Manager::ExportSimpleXMP ( XMP_Uns32 id, const SXMPMeta & xmp, XMP_StringPtr ns, XMP_StringPtr prop,
bool createWithZeroLang /* = false */ )
{
std::string xmpValue, macValue;
InfoMapPos infoPos = this->parsedBoxes.find ( id );
bool qtFound = (infoPos != this->parsedBoxes.end()) && (! infoPos->second.values.empty());
bool xmpFound = xmp.GetProperty ( ns, prop, &xmpValue, 0 );
if ( (! xmpFound) || (xmpValue.empty()) ) {
if ( qtFound ) {
this->parsedBoxes.erase ( infoPos );
this->changed = true;
}
return;
}
XMP_Assert ( xmpFound );
if ( ! qtFound ) {
if ( ! createWithZeroLang ) return;
infoPos = this->parsedBoxes.insert ( this->parsedBoxes.end(),
InfoMap::value_type ( id, ParsedBoxInfo ( id ) ) );
ValueVector * newValues = &infoPos->second.values;
newValues->push_back ( ValueInfo() );
ValueInfo * newValue = &newValues->back();
newValue->macLang = 0; // Happens to be langEnglish.
newValue->xmpLang = kMacToXMPLang_0_94[0];
this->changed = infoPos->second.changed = true;
}
ValueInfo * qtItem = &infoPos->second.values[0]; // ! Use the first QT entry.
if ( ! IsMacLangKnown ( qtItem->macLang ) ) return;
bool convertOK = ConvertToMacLang ( xmpValue, qtItem->macLang, &macValue );
if ( convertOK && (macValue != qtItem->macValue) ) {
qtItem->macValue = macValue;
this->changed = infoPos->second.changed = true;
}
} // TradQT_Manager::ExportSimpleXMP
| DoS | 0 | void TradQT_Manager::ExportSimpleXMP ( XMP_Uns32 id, const SXMPMeta & xmp, XMP_StringPtr ns, XMP_StringPtr prop,
bool createWithZeroLang /* = false */ )
{
std::string xmpValue, macValue;
InfoMapPos infoPos = this->parsedBoxes.find ( id );
bool qtFound = (infoPos != this->parsedBoxes.end()) && (! infoPos->second.values.empty());
bool xmpFound = xmp.GetProperty ( ns, prop, &xmpValue, 0 );
if ( (! xmpFound) || (xmpValue.empty()) ) {
if ( qtFound ) {
this->parsedBoxes.erase ( infoPos );
this->changed = true;
}
return;
}
XMP_Assert ( xmpFound );
if ( ! qtFound ) {
if ( ! createWithZeroLang ) return;
infoPos = this->parsedBoxes.insert ( this->parsedBoxes.end(),
InfoMap::value_type ( id, ParsedBoxInfo ( id ) ) );
ValueVector * newValues = &infoPos->second.values;
newValues->push_back ( ValueInfo() );
ValueInfo * newValue = &newValues->back();
newValue->macLang = 0; // Happens to be langEnglish.
newValue->xmpLang = kMacToXMPLang_0_94[0];
this->changed = infoPos->second.changed = true;
}
ValueInfo * qtItem = &infoPos->second.values[0]; // ! Use the first QT entry.
if ( ! IsMacLangKnown ( qtItem->macLang ) ) return;
bool convertOK = ConvertToMacLang ( xmpValue, qtItem->macLang, &macValue );
if ( convertOK && (macValue != qtItem->macValue) ) {
qtItem->macValue = macValue;
this->changed = infoPos->second.changed = true;
}
} // TradQT_Manager::ExportSimpleXMP
| @@ -920,7 +920,8 @@ bool TradQT_Manager::ParseCachedBoxes ( const MOOV_Manager & moovMgr )
miniLen = 4 + GetUns16BE ( boxPtr ); // ! Include header in local miniLen.
macLang = GetUns16BE ( boxPtr+2);
- if ( (miniLen <= 4) || (miniLen > (boxEnd - boxPtr)) ) continue; // Ignore bad or empty values.
+ if ( (miniLen <= 4) || (miniLen > (boxEnd - boxPtr)) )
+ break; // Ignore bad or empty values.
XMP_StringPtr valuePtr = (char*)(boxPtr+4);
size_t valueLen = miniLen - 4; | CWE-835 | null | null |
12,752 | static XMP_Uns32 GetIOSEncodingCF ( XMP_Uns16 macLang )
{
XMP_Uns32 encCF = kCFStringEncodingInvalidId;
if ( macLang <= 94 ) encCF = kMacToIOSEncodingCF_0_94[macLang];
if ( encCF == kCFStringEncodingInvalidId || !CFStringIsEncodingAvailable(encCF)) {
XMP_Uns16 macScript = GetMacScript ( macLang );
if ( macScript != kNoMacScript ) encCF = kMacScriptToIOSEncodingCF[macScript];
}
return encCF;
} // GetIOSEncodingCF
| DoS | 0 | static XMP_Uns32 GetIOSEncodingCF ( XMP_Uns16 macLang )
{
XMP_Uns32 encCF = kCFStringEncodingInvalidId;
if ( macLang <= 94 ) encCF = kMacToIOSEncodingCF_0_94[macLang];
if ( encCF == kCFStringEncodingInvalidId || !CFStringIsEncodingAvailable(encCF)) {
XMP_Uns16 macScript = GetMacScript ( macLang );
if ( macScript != kNoMacScript ) encCF = kMacScriptToIOSEncodingCF[macScript];
}
return encCF;
} // GetIOSEncodingCF
| @@ -920,7 +920,8 @@ bool TradQT_Manager::ParseCachedBoxes ( const MOOV_Manager & moovMgr )
miniLen = 4 + GetUns16BE ( boxPtr ); // ! Include header in local miniLen.
macLang = GetUns16BE ( boxPtr+2);
- if ( (miniLen <= 4) || (miniLen > (boxEnd - boxPtr)) ) continue; // Ignore bad or empty values.
+ if ( (miniLen <= 4) || (miniLen > (boxEnd - boxPtr)) )
+ break; // Ignore bad or empty values.
XMP_StringPtr valuePtr = (char*)(boxPtr+4);
size_t valueLen = miniLen - 4; | CWE-835 | null | null |
12,753 | static XMP_Uns16 GetMacScript ( XMP_Uns16 macLang )
{
XMP_Uns16 macScript = kNoMacScript;
if ( macLang <= 94 ) {
macScript = kMacLangToScript_0_94[macLang];
} else if ( (128 <= macLang) && (macLang <= 151) ) {
macScript = kMacLangToScript_128_151[macLang-128];
}
return macScript;
} // GetMacScript
| DoS | 0 | static XMP_Uns16 GetMacScript ( XMP_Uns16 macLang )
{
XMP_Uns16 macScript = kNoMacScript;
if ( macLang <= 94 ) {
macScript = kMacLangToScript_0_94[macLang];
} else if ( (128 <= macLang) && (macLang <= 151) ) {
macScript = kMacLangToScript_128_151[macLang-128];
}
return macScript;
} // GetMacScript
| @@ -920,7 +920,8 @@ bool TradQT_Manager::ParseCachedBoxes ( const MOOV_Manager & moovMgr )
miniLen = 4 + GetUns16BE ( boxPtr ); // ! Include header in local miniLen.
macLang = GetUns16BE ( boxPtr+2);
- if ( (miniLen <= 4) || (miniLen > (boxEnd - boxPtr)) ) continue; // Ignore bad or empty values.
+ if ( (miniLen <= 4) || (miniLen > (boxEnd - boxPtr)) )
+ break; // Ignore bad or empty values.
XMP_StringPtr valuePtr = (char*)(boxPtr+4);
size_t valueLen = miniLen - 4; | CWE-835 | null | null |
12,754 | static UINT GetWinCP ( XMP_Uns16 macLang )
{
UINT winCP = 0;
if ( macLang <= 94 ) winCP = kMacToWinCP_0_94[macLang];
if ( winCP == 0 ) {
XMP_Uns16 macScript = GetMacScript ( macLang );
if ( macScript != kNoMacScript ) winCP = kMacScriptToWinCP[macScript];
}
return winCP;
} // GetWinCP
| DoS | 0 | static UINT GetWinCP ( XMP_Uns16 macLang )
{
UINT winCP = 0;
if ( macLang <= 94 ) winCP = kMacToWinCP_0_94[macLang];
if ( winCP == 0 ) {
XMP_Uns16 macScript = GetMacScript ( macLang );
if ( macScript != kNoMacScript ) winCP = kMacScriptToWinCP[macScript];
}
return winCP;
} // GetWinCP
| @@ -920,7 +920,8 @@ bool TradQT_Manager::ParseCachedBoxes ( const MOOV_Manager & moovMgr )
miniLen = 4 + GetUns16BE ( boxPtr ); // ! Include header in local miniLen.
macLang = GetUns16BE ( boxPtr+2);
- if ( (miniLen <= 4) || (miniLen > (boxEnd - boxPtr)) ) continue; // Ignore bad or empty values.
+ if ( (miniLen <= 4) || (miniLen > (boxEnd - boxPtr)) )
+ break; // Ignore bad or empty values.
XMP_StringPtr valuePtr = (char*)(boxPtr+4);
size_t valueLen = miniLen - 4; | CWE-835 | null | null |
12,755 | bool TradQT_Manager::ImportLangAltXMP ( XMP_Uns32 id, SXMPMeta * xmp, XMP_StringPtr ns, XMP_StringPtr langArray ) const
{
try {
InfoMapCPos infoPos = this->parsedBoxes.find ( id );
if ( infoPos == this->parsedBoxes.end() ) return false;
if ( infoPos->second.values.empty() ) return false; // Quit now if there are no values.
XMP_OptionBits flags;
bool xmpExists = xmp->GetProperty ( ns, langArray, 0, &flags );
if ( ! xmpExists ) {
xmp->SetProperty ( ns, langArray, 0, kXMP_PropArrayIsAltText );
} else if ( ! XMP_ArrayIsAltText ( flags ) ) {
XMP_Throw ( "TradQT_Manager::ImportLangAltXMP - XMP array must be AltText", kXMPErr_BadParam );
}
bool haveMappings = false;
const ValueVector & qtValues = infoPos->second.values;
for ( size_t i = 0, limit = qtValues.size(); i < limit; ++i ) {
const ValueInfo & qtItem = qtValues[i];
if ( *qtItem.xmpLang == 0 ) continue; // Only do known mappings in the loop.
haveMappings |= this->ImportLangItem ( qtItem, xmp, ns, langArray );
}
if ( ! haveMappings ) {
haveMappings = this->ImportLangItem ( qtValues[0], xmp, ns, langArray ); // ! No xmpLang implies "x-default".
}
return haveMappings;
} catch ( ... ) {
return false; // Don't let one failure abort other imports.
}
} // TradQT_Manager::ImportLangAltXMP
| DoS | 0 | bool TradQT_Manager::ImportLangAltXMP ( XMP_Uns32 id, SXMPMeta * xmp, XMP_StringPtr ns, XMP_StringPtr langArray ) const
{
try {
InfoMapCPos infoPos = this->parsedBoxes.find ( id );
if ( infoPos == this->parsedBoxes.end() ) return false;
if ( infoPos->second.values.empty() ) return false; // Quit now if there are no values.
XMP_OptionBits flags;
bool xmpExists = xmp->GetProperty ( ns, langArray, 0, &flags );
if ( ! xmpExists ) {
xmp->SetProperty ( ns, langArray, 0, kXMP_PropArrayIsAltText );
} else if ( ! XMP_ArrayIsAltText ( flags ) ) {
XMP_Throw ( "TradQT_Manager::ImportLangAltXMP - XMP array must be AltText", kXMPErr_BadParam );
}
bool haveMappings = false;
const ValueVector & qtValues = infoPos->second.values;
for ( size_t i = 0, limit = qtValues.size(); i < limit; ++i ) {
const ValueInfo & qtItem = qtValues[i];
if ( *qtItem.xmpLang == 0 ) continue; // Only do known mappings in the loop.
haveMappings |= this->ImportLangItem ( qtItem, xmp, ns, langArray );
}
if ( ! haveMappings ) {
haveMappings = this->ImportLangItem ( qtValues[0], xmp, ns, langArray ); // ! No xmpLang implies "x-default".
}
return haveMappings;
} catch ( ... ) {
return false; // Don't let one failure abort other imports.
}
} // TradQT_Manager::ImportLangAltXMP
| @@ -920,7 +920,8 @@ bool TradQT_Manager::ParseCachedBoxes ( const MOOV_Manager & moovMgr )
miniLen = 4 + GetUns16BE ( boxPtr ); // ! Include header in local miniLen.
macLang = GetUns16BE ( boxPtr+2);
- if ( (miniLen <= 4) || (miniLen > (boxEnd - boxPtr)) ) continue; // Ignore bad or empty values.
+ if ( (miniLen <= 4) || (miniLen > (boxEnd - boxPtr)) )
+ break; // Ignore bad or empty values.
XMP_StringPtr valuePtr = (char*)(boxPtr+4);
size_t valueLen = miniLen - 4; | CWE-835 | null | null |
12,756 | bool TradQT_Manager::ImportSimpleXMP ( XMP_Uns32 id, SXMPMeta * xmp, XMP_StringPtr ns, XMP_StringPtr prop ) const
{
try {
InfoMapCPos infoPos = this->parsedBoxes.find ( id );
if ( infoPos == this->parsedBoxes.end() ) return false;
if ( infoPos->second.values.empty() ) return false;
std::string xmpValue, tempValue;
XMP_OptionBits flags;
bool xmpExists = xmp->GetProperty ( ns, prop, &xmpValue, &flags );
if ( xmpExists && (! XMP_PropIsSimple ( flags )) ) {
XMP_Throw ( "TradQT_Manager::ImportSimpleXMP - XMP property must be simple", kXMPErr_BadParam );
}
bool convertOK;
const ValueInfo & qtItem = infoPos->second.values[0]; // ! Use the first QT entry.
if ( xmpExists ) {
convertOK = ConvertToMacLang ( xmpValue, qtItem.macLang, &tempValue );
if ( ! convertOK ) return false; // throw?
if ( tempValue == qtItem.macValue ) return false; // QT value matches back converted XMP value.
}
convertOK = ConvertFromMacLang ( qtItem.macValue, qtItem.macLang, &tempValue );
if ( ! convertOK ) return false; // throw?
xmp->SetProperty ( ns, prop, tempValue.c_str() );
return true;
} catch ( ... ) {
return false; // Don't let one failure abort other imports.
}
} // TradQT_Manager::ImportSimpleXMP
| DoS | 0 | bool TradQT_Manager::ImportSimpleXMP ( XMP_Uns32 id, SXMPMeta * xmp, XMP_StringPtr ns, XMP_StringPtr prop ) const
{
try {
InfoMapCPos infoPos = this->parsedBoxes.find ( id );
if ( infoPos == this->parsedBoxes.end() ) return false;
if ( infoPos->second.values.empty() ) return false;
std::string xmpValue, tempValue;
XMP_OptionBits flags;
bool xmpExists = xmp->GetProperty ( ns, prop, &xmpValue, &flags );
if ( xmpExists && (! XMP_PropIsSimple ( flags )) ) {
XMP_Throw ( "TradQT_Manager::ImportSimpleXMP - XMP property must be simple", kXMPErr_BadParam );
}
bool convertOK;
const ValueInfo & qtItem = infoPos->second.values[0]; // ! Use the first QT entry.
if ( xmpExists ) {
convertOK = ConvertToMacLang ( xmpValue, qtItem.macLang, &tempValue );
if ( ! convertOK ) return false; // throw?
if ( tempValue == qtItem.macValue ) return false; // QT value matches back converted XMP value.
}
convertOK = ConvertFromMacLang ( qtItem.macValue, qtItem.macLang, &tempValue );
if ( ! convertOK ) return false; // throw?
xmp->SetProperty ( ns, prop, tempValue.c_str() );
return true;
} catch ( ... ) {
return false; // Don't let one failure abort other imports.
}
} // TradQT_Manager::ImportSimpleXMP
| @@ -920,7 +920,8 @@ bool TradQT_Manager::ParseCachedBoxes ( const MOOV_Manager & moovMgr )
miniLen = 4 + GetUns16BE ( boxPtr ); // ! Include header in local miniLen.
macLang = GetUns16BE ( boxPtr+2);
- if ( (miniLen <= 4) || (miniLen > (boxEnd - boxPtr)) ) continue; // Ignore bad or empty values.
+ if ( (miniLen <= 4) || (miniLen > (boxEnd - boxPtr)) )
+ break; // Ignore bad or empty values.
XMP_StringPtr valuePtr = (char*)(boxPtr+4);
size_t valueLen = miniLen - 4; | CWE-835 | null | null |
12,757 | static inline bool IsMacLangKnown ( XMP_Uns16 macLang )
{
XMP_Uns16 macScript = GetMacScript ( macLang );
if ( macScript == kNoMacScript ) return false;
#if XMP_UNIXBuild
if ( macScript != smRoman ) return false;
#elif XMP_WinBuild
if ( GetWinCP(macLang) == 0 ) return false;
#endif
return true;
} // IsMacLangKnown
| DoS | 0 | static inline bool IsMacLangKnown ( XMP_Uns16 macLang )
{
XMP_Uns16 macScript = GetMacScript ( macLang );
if ( macScript == kNoMacScript ) return false;
#if XMP_UNIXBuild
if ( macScript != smRoman ) return false;
#elif XMP_WinBuild
if ( GetWinCP(macLang) == 0 ) return false;
#endif
return true;
} // IsMacLangKnown
| @@ -920,7 +920,8 @@ bool TradQT_Manager::ParseCachedBoxes ( const MOOV_Manager & moovMgr )
miniLen = 4 + GetUns16BE ( boxPtr ); // ! Include header in local miniLen.
macLang = GetUns16BE ( boxPtr+2);
- if ( (miniLen <= 4) || (miniLen > (boxEnd - boxPtr)) ) continue; // Ignore bad or empty values.
+ if ( (miniLen <= 4) || (miniLen > (boxEnd - boxPtr)) )
+ break; // Ignore bad or empty values.
XMP_StringPtr valuePtr = (char*)(boxPtr+4);
size_t valueLen = miniLen - 4; | CWE-835 | null | null |
12,758 | static void MacRomanToUTF8 ( const std::string & macRoman, std::string * utf8 )
{
utf8->erase();
for ( XMP_Uns8* chPtr = (XMP_Uns8*)macRoman.c_str(); *chPtr != 0; ++chPtr ) { // ! Don't trust that char is unsigned.
if ( *chPtr < 0x80 ) {
(*utf8) += (char)*chPtr;
} else {
(*utf8) += kMacRomanUTF8[(*chPtr)-0x80];
}
}
} // MacRomanToUTF8
| DoS | 0 | static void MacRomanToUTF8 ( const std::string & macRoman, std::string * utf8 )
{
utf8->erase();
for ( XMP_Uns8* chPtr = (XMP_Uns8*)macRoman.c_str(); *chPtr != 0; ++chPtr ) { // ! Don't trust that char is unsigned.
if ( *chPtr < 0x80 ) {
(*utf8) += (char)*chPtr;
} else {
(*utf8) += kMacRomanUTF8[(*chPtr)-0x80];
}
}
} // MacRomanToUTF8
| @@ -920,7 +920,8 @@ bool TradQT_Manager::ParseCachedBoxes ( const MOOV_Manager & moovMgr )
miniLen = 4 + GetUns16BE ( boxPtr ); // ! Include header in local miniLen.
macLang = GetUns16BE ( boxPtr+2);
- if ( (miniLen <= 4) || (miniLen > (boxEnd - boxPtr)) ) continue; // Ignore bad or empty values.
+ if ( (miniLen <= 4) || (miniLen > (boxEnd - boxPtr)) )
+ break; // Ignore bad or empty values.
XMP_StringPtr valuePtr = (char*)(boxPtr+4);
size_t valueLen = miniLen - 4; | CWE-835 | null | null |
12,759 | static void UTF8ToMacRoman ( const std::string & utf8, std::string * macRoman )
{
macRoman->erase();
bool inNonMRSpan = false;
for ( const XMP_Uns8 * chPtr = (XMP_Uns8*)utf8.c_str(); *chPtr != 0; ++chPtr ) { // ! Don't trust that char is unsigned.
if ( *chPtr < 0x80 ) {
(*macRoman) += (char)*chPtr;
inNonMRSpan = false;
} else {
XMP_Uns32 cp = GetCodePoint ( &chPtr );
--chPtr; // Make room for the loop increment.
XMP_Uns8 mr;
for ( mr = 0; (mr < 0x80) && (cp != kMacRomanCP[mr]); ++mr ) {}; // Using std::map would be faster.
if ( mr < 0x80 ) {
(*macRoman) += (char)(mr+0x80);
inNonMRSpan = false;
} else if ( ! inNonMRSpan ) {
(*macRoman) += '?';
inNonMRSpan = true;
}
}
}
} // UTF8ToMacRoman
| DoS | 0 | static void UTF8ToMacRoman ( const std::string & utf8, std::string * macRoman )
{
macRoman->erase();
bool inNonMRSpan = false;
for ( const XMP_Uns8 * chPtr = (XMP_Uns8*)utf8.c_str(); *chPtr != 0; ++chPtr ) { // ! Don't trust that char is unsigned.
if ( *chPtr < 0x80 ) {
(*macRoman) += (char)*chPtr;
inNonMRSpan = false;
} else {
XMP_Uns32 cp = GetCodePoint ( &chPtr );
--chPtr; // Make room for the loop increment.
XMP_Uns8 mr;
for ( mr = 0; (mr < 0x80) && (cp != kMacRomanCP[mr]); ++mr ) {}; // Using std::map would be faster.
if ( mr < 0x80 ) {
(*macRoman) += (char)(mr+0x80);
inNonMRSpan = false;
} else if ( ! inNonMRSpan ) {
(*macRoman) += '?';
inNonMRSpan = true;
}
}
}
} // UTF8ToMacRoman
| @@ -920,7 +920,8 @@ bool TradQT_Manager::ParseCachedBoxes ( const MOOV_Manager & moovMgr )
miniLen = 4 + GetUns16BE ( boxPtr ); // ! Include header in local miniLen.
macLang = GetUns16BE ( boxPtr+2);
- if ( (miniLen <= 4) || (miniLen > (boxEnd - boxPtr)) ) continue; // Ignore bad or empty values.
+ if ( (miniLen <= 4) || (miniLen > (boxEnd - boxPtr)) )
+ break; // Ignore bad or empty values.
XMP_StringPtr valuePtr = (char*)(boxPtr+4);
size_t valueLen = miniLen - 4; | CWE-835 | null | null |
12,760 | void TradQT_Manager::UpdateChangedBoxes ( MOOV_Manager * moovMgr )
{
MOOV_Manager::BoxInfo udtaInfo;
MOOV_Manager::BoxRef udtaRef = moovMgr->GetBox ( "moov/udta", &udtaInfo );
XMP_Assert ( (udtaRef != 0) || (udtaInfo.childCount == 0) );
if ( udtaRef != 0 ) { // Might not have been a moov/udta box in the parse.
for ( XMP_Uns32 ordinal = udtaInfo.childCount; ordinal > 0; --ordinal ) { // ! Go backwards because of deletions.
MOOV_Manager::BoxInfo currInfo;
MOOV_Manager::BoxRef currRef = moovMgr->GetNthChild ( udtaRef, (ordinal-1), &currInfo );
if ( currRef == 0 ) break; // Sanity check, should not happen.
if ( (currInfo.boxType >> 24) != 0xA9 ) continue;
if ( currInfo.contentSize < 2+2+1 ) continue; // These were skipped by ParseCachedBoxes.
InfoMapPos infoPos = this->parsedBoxes.find ( currInfo.boxType );
if ( infoPos == this->parsedBoxes.end() ) moovMgr->DeleteNthChild ( udtaRef, (ordinal-1) );
}
}
InfoMapCPos infoPos = this->parsedBoxes.begin();
InfoMapCPos infoEnd = this->parsedBoxes.end();
for ( ; infoPos != infoEnd; ++infoPos ) {
ParsedBoxInfo * qtItem = (ParsedBoxInfo*) &infoPos->second;
if ( ! qtItem->changed ) continue;
qtItem->changed = false;
XMP_Uns32 qtTotalSize = 0; // Total size of the QT values, ignoring empty values.
for ( size_t i = 0, limit = qtItem->values.size(); i < limit; ++i ) {
if ( ! qtItem->values[i].macValue.empty() ) {
if ( qtItem->values[i].macValue.size() > 0xFFFF ) qtItem->values[i].macValue.erase ( 0xFFFF );
qtTotalSize += (XMP_Uns32)(2+2 + qtItem->values[i].macValue.size());
}
}
if ( udtaRef == 0 ) { // Might not have been a moov/udta box in the parse.
moovMgr->SetBox ( "moov/udta", 0, 0 );
udtaRef = moovMgr->GetBox ( "moov/udta", &udtaInfo );
XMP_Assert ( udtaRef != 0 );
}
if ( qtTotalSize == 0 ) {
moovMgr->DeleteTypeChild ( udtaRef, qtItem->id );
} else {
RawDataBlock fullValue;
fullValue.assign ( qtTotalSize, 0 );
XMP_Uns8 * valuePtr = &fullValue[0];
for ( size_t i = 0, limit = qtItem->values.size(); i < limit; ++i ) {
XMP_Assert ( qtItem->values[i].macValue.size() <= 0xFFFF );
XMP_Uns16 textSize = (XMP_Uns16)qtItem->values[i].macValue.size();
if ( textSize == 0 ) continue;
PutUns16BE ( textSize, valuePtr ); valuePtr += 2;
PutUns16BE ( qtItem->values[i].macLang, valuePtr ); valuePtr += 2;
memcpy ( valuePtr, qtItem->values[i].macValue.c_str(), textSize ); valuePtr += textSize;
}
MOOV_Manager::BoxInfo itemInfo;
MOOV_Manager::BoxRef itemRef = moovMgr->GetTypeChild ( udtaRef, qtItem->id, &itemInfo );
if ( itemRef != 0 ) {
moovMgr->SetBox ( itemRef, &fullValue[0], qtTotalSize );
} else {
moovMgr->AddChildBox ( udtaRef, qtItem->id, &fullValue[0], qtTotalSize );
}
}
}
} // TradQT_Manager::UpdateChangedBoxes
| DoS | 0 | void TradQT_Manager::UpdateChangedBoxes ( MOOV_Manager * moovMgr )
{
MOOV_Manager::BoxInfo udtaInfo;
MOOV_Manager::BoxRef udtaRef = moovMgr->GetBox ( "moov/udta", &udtaInfo );
XMP_Assert ( (udtaRef != 0) || (udtaInfo.childCount == 0) );
if ( udtaRef != 0 ) { // Might not have been a moov/udta box in the parse.
for ( XMP_Uns32 ordinal = udtaInfo.childCount; ordinal > 0; --ordinal ) { // ! Go backwards because of deletions.
MOOV_Manager::BoxInfo currInfo;
MOOV_Manager::BoxRef currRef = moovMgr->GetNthChild ( udtaRef, (ordinal-1), &currInfo );
if ( currRef == 0 ) break; // Sanity check, should not happen.
if ( (currInfo.boxType >> 24) != 0xA9 ) continue;
if ( currInfo.contentSize < 2+2+1 ) continue; // These were skipped by ParseCachedBoxes.
InfoMapPos infoPos = this->parsedBoxes.find ( currInfo.boxType );
if ( infoPos == this->parsedBoxes.end() ) moovMgr->DeleteNthChild ( udtaRef, (ordinal-1) );
}
}
InfoMapCPos infoPos = this->parsedBoxes.begin();
InfoMapCPos infoEnd = this->parsedBoxes.end();
for ( ; infoPos != infoEnd; ++infoPos ) {
ParsedBoxInfo * qtItem = (ParsedBoxInfo*) &infoPos->second;
if ( ! qtItem->changed ) continue;
qtItem->changed = false;
XMP_Uns32 qtTotalSize = 0; // Total size of the QT values, ignoring empty values.
for ( size_t i = 0, limit = qtItem->values.size(); i < limit; ++i ) {
if ( ! qtItem->values[i].macValue.empty() ) {
if ( qtItem->values[i].macValue.size() > 0xFFFF ) qtItem->values[i].macValue.erase ( 0xFFFF );
qtTotalSize += (XMP_Uns32)(2+2 + qtItem->values[i].macValue.size());
}
}
if ( udtaRef == 0 ) { // Might not have been a moov/udta box in the parse.
moovMgr->SetBox ( "moov/udta", 0, 0 );
udtaRef = moovMgr->GetBox ( "moov/udta", &udtaInfo );
XMP_Assert ( udtaRef != 0 );
}
if ( qtTotalSize == 0 ) {
moovMgr->DeleteTypeChild ( udtaRef, qtItem->id );
} else {
RawDataBlock fullValue;
fullValue.assign ( qtTotalSize, 0 );
XMP_Uns8 * valuePtr = &fullValue[0];
for ( size_t i = 0, limit = qtItem->values.size(); i < limit; ++i ) {
XMP_Assert ( qtItem->values[i].macValue.size() <= 0xFFFF );
XMP_Uns16 textSize = (XMP_Uns16)qtItem->values[i].macValue.size();
if ( textSize == 0 ) continue;
PutUns16BE ( textSize, valuePtr ); valuePtr += 2;
PutUns16BE ( qtItem->values[i].macLang, valuePtr ); valuePtr += 2;
memcpy ( valuePtr, qtItem->values[i].macValue.c_str(), textSize ); valuePtr += textSize;
}
MOOV_Manager::BoxInfo itemInfo;
MOOV_Manager::BoxRef itemRef = moovMgr->GetTypeChild ( udtaRef, qtItem->id, &itemInfo );
if ( itemRef != 0 ) {
moovMgr->SetBox ( itemRef, &fullValue[0], qtTotalSize );
} else {
moovMgr->AddChildBox ( udtaRef, qtItem->id, &fullValue[0], qtTotalSize );
}
}
}
} // TradQT_Manager::UpdateChangedBoxes
| @@ -920,7 +920,8 @@ bool TradQT_Manager::ParseCachedBoxes ( const MOOV_Manager & moovMgr )
miniLen = 4 + GetUns16BE ( boxPtr ); // ! Include header in local miniLen.
macLang = GetUns16BE ( boxPtr+2);
- if ( (miniLen <= 4) || (miniLen > (boxEnd - boxPtr)) ) continue; // Ignore bad or empty values.
+ if ( (miniLen <= 4) || (miniLen > (boxEnd - boxPtr)) )
+ break; // Ignore bad or empty values.
XMP_StringPtr valuePtr = (char*)(boxPtr+4);
size_t valueLen = miniLen - 4; | CWE-835 | null | null |
12,761 | static void AdjustYearIfNeeded(short &year)
{
if (year<100)
{
if (year >40)
{
year=1900+year;
}
else
{
year=2000+year;
}
}
}
| DoS | 0 | static void AdjustYearIfNeeded(short &year)
{
if (year<100)
{
if (year >40)
{
year=1900+year;
}
else
{
year=2000+year;
}
}
}
| @@ -814,7 +814,8 @@ std::string PostScript_Support::ConvertToDate(const char* inString)
std::vector<PostScript_Support::DateTimeTokens>:: const_iterator itr=tokenzs.begin();
for(;itr!=tokenzs.end();itr++)
{
- if(itr->token[0]=='+' ||itr->token[0]=='-')
+ // token[0] is invalid on an empty string. -- Hub
+ if(!itr->token.empty() && (itr->token[0]=='+' ||itr->token[0]=='-'))
{
const char *str=itr->token.c_str();
date.offsetSign=*(str++);
@@ -1013,7 +1014,14 @@ std::string PostScript_Support::ConvertToDate(const char* inString)
if(itr!=tokenzs.end())
{
++itr;
- if (itr!=tokenzs.end()&&itr->noOfDelimiter==0 && IsNumeric(itr->token[0]) )
+ if (itr == tokenzs.end())
+ {
+ // bug 101914 - corrupt file make us
+ // reach the end. -- Hub
+ // https://bugs.freedesktop.org/show_bug.cgi?id=101914
+ break;
+ }
+ if (itr->noOfDelimiter==0 && IsNumeric(itr->token[0]) )
{
const char * str=itr->token.c_str();
short day= GetNumber(&str); | CWE-476 | null | null |
12,762 | ASF_LegacyManager::ASF_LegacyManager() : fields(fieldLast), broadcastSet(false), digestComputed(false),
imported(false), objectsExisting(0), objectsToExport(0), legacyDiff(0), padding(0)
{
}
| DoS | 0 | ASF_LegacyManager::ASF_LegacyManager() : fields(fieldLast), broadcastSet(false), digestComputed(false),
imported(false), objectsExisting(0), objectsToExport(0), legacyDiff(0), padding(0)
{
}
| @@ -270,6 +270,8 @@ bool ASF_Support::ReadHeaderObject ( XMP_IO* fileRef, ObjectState& inOutObjectSt
this->ReadHeaderExtensionObject ( fileRef, inOutObjectState, pos, objectBase );
+ } else if (objectBase.size == 0) {
+ break;
}
pos += objectBase.size; | CWE-835 | null | null |
12,763 | ASF_Support::ASF_Support() : legacyManager(0),progressTracker(0), posFileSizeInfo(0) {}
| DoS | 0 | ASF_Support::ASF_Support() : legacyManager(0),progressTracker(0), posFileSizeInfo(0) {}
| @@ -270,6 +270,8 @@ bool ASF_Support::ReadHeaderObject ( XMP_IO* fileRef, ObjectState& inOutObjectSt
this->ReadHeaderExtensionObject ( fileRef, inOutObjectState, pos, objectBase );
+ } else if (objectBase.size == 0) {
+ break;
}
pos += objectBase.size; | CWE-835 | null | null |
12,764 | void ASF_LegacyManager::ComputeDigest()
{
MD5_CTX context;
MD5_Digest digest;
char buffer[40];
MD5Init ( &context );
digestStr.clear();
digestStr.reserve ( 160 );
for ( int type=0; type < fieldLast; ++type ) {
if (fields[type].size ( ) > 0 ) {
snprintf ( buffer, sizeof(buffer), "%d,", type );
digestStr.append ( buffer );
MD5Update ( &context, (XMP_Uns8*)fields[type].data(), fields[type].size() );
}
}
if( digestStr.size() > 0 ) digestStr[digestStr.size()-1] = ';';
MD5Final ( digest, &context );
size_t in, out;
for ( in = 0, out = 0; in < 16; in += 1, out += 2 ) {
XMP_Uns8 byte = digest[in];
buffer[out] = ReconcileUtils::kHexDigits [ byte >> 4 ];
buffer[out+1] = ReconcileUtils::kHexDigits [ byte & 0xF ];
}
buffer[32] = 0;
digestStr.append ( buffer );
digestComputed = true;
}
| DoS | 0 | void ASF_LegacyManager::ComputeDigest()
{
MD5_CTX context;
MD5_Digest digest;
char buffer[40];
MD5Init ( &context );
digestStr.clear();
digestStr.reserve ( 160 );
for ( int type=0; type < fieldLast; ++type ) {
if (fields[type].size ( ) > 0 ) {
snprintf ( buffer, sizeof(buffer), "%d,", type );
digestStr.append ( buffer );
MD5Update ( &context, (XMP_Uns8*)fields[type].data(), fields[type].size() );
}
}
if( digestStr.size() > 0 ) digestStr[digestStr.size()-1] = ';';
MD5Final ( digest, &context );
size_t in, out;
for ( in = 0, out = 0; in < 16; in += 1, out += 2 ) {
XMP_Uns8 byte = digest[in];
buffer[out] = ReconcileUtils::kHexDigits [ byte >> 4 ];
buffer[out+1] = ReconcileUtils::kHexDigits [ byte & 0xF ];
}
buffer[32] = 0;
digestStr.append ( buffer );
digestComputed = true;
}
| @@ -270,6 +270,8 @@ bool ASF_Support::ReadHeaderObject ( XMP_IO* fileRef, ObjectState& inOutObjectSt
this->ReadHeaderExtensionObject ( fileRef, inOutObjectState, pos, objectBase );
+ } else if (objectBase.size == 0) {
+ break;
}
pos += objectBase.size; | CWE-835 | null | null |
12,765 | void ASF_LegacyManager::ConvertISODateToMSDate ( std::string& source, std::string* dest )
{
XMP_DateTime date;
SXMPUtils::ConvertToDate ( source, &date );
SXMPUtils::ConvertToUTCTime ( &date );
XMP_Int64 creationDate;
creationDate = date.nanoSecond / 100;
creationDate += (XMP_Int64 ( date.second) * (10*1000*1000) );
creationDate += (XMP_Int64 ( date.minute) * 60 * (10*1000*1000) );
creationDate += (XMP_Int64 ( date.hour) * 3600 * (10*1000*1000) );
XMP_Int32 days = (date.day - 1);
--date.month;
while ( date.month >= 1 ) {
days += DaysInMonth ( date.year, date.month );
--date.month;
}
--date.year;
while ( date.year >= 1601 ) {
days += (IsLeapYear ( date.year) ? 366 : 365 );
--date.year;
}
creationDate += (XMP_Int64 ( days) * 86400 * (10*1000*1000) );
creationDate = GetUns64LE ( &creationDate );
dest->assign ( (const char*)&creationDate, 8 );
}
| DoS | 0 | void ASF_LegacyManager::ConvertISODateToMSDate ( std::string& source, std::string* dest )
{
XMP_DateTime date;
SXMPUtils::ConvertToDate ( source, &date );
SXMPUtils::ConvertToUTCTime ( &date );
XMP_Int64 creationDate;
creationDate = date.nanoSecond / 100;
creationDate += (XMP_Int64 ( date.second) * (10*1000*1000) );
creationDate += (XMP_Int64 ( date.minute) * 60 * (10*1000*1000) );
creationDate += (XMP_Int64 ( date.hour) * 3600 * (10*1000*1000) );
XMP_Int32 days = (date.day - 1);
--date.month;
while ( date.month >= 1 ) {
days += DaysInMonth ( date.year, date.month );
--date.month;
}
--date.year;
while ( date.year >= 1601 ) {
days += (IsLeapYear ( date.year) ? 366 : 365 );
--date.year;
}
creationDate += (XMP_Int64 ( days) * 86400 * (10*1000*1000) );
creationDate = GetUns64LE ( &creationDate );
dest->assign ( (const char*)&creationDate, 8 );
}
| @@ -270,6 +270,8 @@ bool ASF_Support::ReadHeaderObject ( XMP_IO* fileRef, ObjectState& inOutObjectSt
this->ReadHeaderExtensionObject ( fileRef, inOutObjectState, pos, objectBase );
+ } else if (objectBase.size == 0) {
+ break;
}
pos += objectBase.size; | CWE-835 | null | null |
12,766 | void ASF_LegacyManager::ConvertMSDateToISODate ( std::string& source, std::string* dest )
{
XMP_Int64 creationDate = GetUns64LE ( source.c_str() );
XMP_Int64 totalSecs = creationDate / (10*1000*1000);
XMP_Int32 nanoSec = ( ( XMP_Int32) (creationDate - (totalSecs * 10*1000*1000)) ) * 100;
XMP_Int32 days = (XMP_Int32) (totalSecs / 86400);
totalSecs -= ( ( XMP_Int64)days * 86400 );
XMP_Int32 hour = (XMP_Int32) (totalSecs / 3600);
totalSecs -= ( ( XMP_Int64)hour * 3600 );
XMP_Int32 minute = (XMP_Int32) (totalSecs / 60);
totalSecs -= ( ( XMP_Int64)minute * 60 );
XMP_Int32 second = (XMP_Int32)totalSecs;
XMP_DateTime date;
memset ( &date, 0, sizeof ( date ) );
date.year = 1601; // The MS date origin.
date.month = 1;
date.day = 1;
date.day += days; // Add in the delta.
date.hour = hour;
date.minute = minute;
date.second = second;
date.nanoSecond = nanoSec;
date.hasTimeZone = true; // ! Needed for ConvertToUTCTime to do anything.
SXMPUtils::ConvertToUTCTime ( &date ); // Normalize the date/time.
SXMPUtils::ConvertFromDate ( date, dest ); // Convert to an ISO 8601 string.
}
| DoS | 0 | void ASF_LegacyManager::ConvertMSDateToISODate ( std::string& source, std::string* dest )
{
XMP_Int64 creationDate = GetUns64LE ( source.c_str() );
XMP_Int64 totalSecs = creationDate / (10*1000*1000);
XMP_Int32 nanoSec = ( ( XMP_Int32) (creationDate - (totalSecs * 10*1000*1000)) ) * 100;
XMP_Int32 days = (XMP_Int32) (totalSecs / 86400);
totalSecs -= ( ( XMP_Int64)days * 86400 );
XMP_Int32 hour = (XMP_Int32) (totalSecs / 3600);
totalSecs -= ( ( XMP_Int64)hour * 3600 );
XMP_Int32 minute = (XMP_Int32) (totalSecs / 60);
totalSecs -= ( ( XMP_Int64)minute * 60 );
XMP_Int32 second = (XMP_Int32)totalSecs;
XMP_DateTime date;
memset ( &date, 0, sizeof ( date ) );
date.year = 1601; // The MS date origin.
date.month = 1;
date.day = 1;
date.day += days; // Add in the delta.
date.hour = hour;
date.minute = minute;
date.second = second;
date.nanoSecond = nanoSec;
date.hasTimeZone = true; // ! Needed for ConvertToUTCTime to do anything.
SXMPUtils::ConvertToUTCTime ( &date ); // Normalize the date/time.
SXMPUtils::ConvertFromDate ( date, dest ); // Convert to an ISO 8601 string.
}
| @@ -270,6 +270,8 @@ bool ASF_Support::ReadHeaderObject ( XMP_IO* fileRef, ObjectState& inOutObjectSt
this->ReadHeaderExtensionObject ( fileRef, inOutObjectState, pos, objectBase );
+ } else if (objectBase.size == 0) {
+ break;
}
pos += objectBase.size; | CWE-835 | null | null |
12,767 | bool ASF_Support::CopyObject ( XMP_IO* sourceRef, XMP_IO* destRef, const ObjectData& object )
{
try {
sourceRef->Seek ( object.pos, kXMP_SeekFromStart );
XIO::Copy ( sourceRef, destRef, object.len );
} catch ( ... ) {
return false;
}
return true;
}
| DoS | 0 | bool ASF_Support::CopyObject ( XMP_IO* sourceRef, XMP_IO* destRef, const ObjectData& object )
{
try {
sourceRef->Seek ( object.pos, kXMP_SeekFromStart );
XIO::Copy ( sourceRef, destRef, object.len );
} catch ( ... ) {
return false;
}
return true;
}
| @@ -270,6 +270,8 @@ bool ASF_Support::ReadHeaderObject ( XMP_IO* fileRef, ObjectState& inOutObjectSt
this->ReadHeaderExtensionObject ( fileRef, inOutObjectState, pos, objectBase );
+ } else if (objectBase.size == 0) {
+ break;
}
pos += objectBase.size; | CWE-835 | null | null |
12,768 | bool ASF_Support::CreatePaddingObject ( std::string* header, const XMP_Uns64 size )
{
if ( ( ! header) || (size < 24) ) return false;
ASF_ObjectBase newObjectBase;
newObjectBase.guid = ASF_Padding_Object;
newObjectBase.size = MakeUns64LE ( size );
header->append ( (const char*)&newObjectBase, kASF_ObjectBaseLen );
header->append ( XMP_Uns32 ( size - 24 ), '\0' );
return true;
}
| DoS | 0 | bool ASF_Support::CreatePaddingObject ( std::string* header, const XMP_Uns64 size )
{
if ( ( ! header) || (size < 24) ) return false;
ASF_ObjectBase newObjectBase;
newObjectBase.guid = ASF_Padding_Object;
newObjectBase.size = MakeUns64LE ( size );
header->append ( (const char*)&newObjectBase, kASF_ObjectBaseLen );
header->append ( XMP_Uns32 ( size - 24 ), '\0' );
return true;
}
| @@ -270,6 +270,8 @@ bool ASF_Support::ReadHeaderObject ( XMP_IO* fileRef, ObjectState& inOutObjectSt
this->ReadHeaderExtensionObject ( fileRef, inOutObjectState, pos, objectBase );
+ } else if (objectBase.size == 0) {
+ break;
}
pos += objectBase.size; | CWE-835 | null | null |
12,769 | int ASF_LegacyManager::ExportLegacy ( const SXMPMeta& xmp )
{
int changed = 0;
objectsToExport = 0;
legacyDiff = 0;
std::string utf8;
std::string utf16;
XMP_OptionBits flags;
if ( ! broadcastSet ) {
if ( xmp.GetProperty ( kXMP_NS_XMP, "CreateDate", &utf8, &flags ) ) {
std::string date;
ConvertISODateToMSDate ( utf8, &date );
if ( fields[fieldCreationDate] != date ) {
legacyDiff += date.size();
legacyDiff -= fields[fieldCreationDate].size();
this->SetField ( fieldCreationDate, date );
objectsToExport |= objectFileProperties;
changed ++;
}
}
}
if ( xmp.GetLocalizedText ( kXMP_NS_DC, "title", "", "x-default", 0, &utf8, &flags ) ) {
NormalizeStringTrailingNull ( utf8 );
ToUTF16 ( (const UTF8Unit*)utf8.data(), utf8.size(), &utf16, false );
if ( fields[fieldTitle] != utf16 ) {
legacyDiff += utf16.size();
legacyDiff -= fields[fieldTitle].size();
this->SetField ( fieldTitle, utf16 );
objectsToExport |= objectContentDescription;
changed ++;
}
}
utf8.clear();
SXMPUtils::CatenateArrayItems ( xmp, kXMP_NS_DC, "creator", 0, 0, kXMPUtil_AllowCommas, &utf8 );
if ( ! utf8.empty() ) {
NormalizeStringTrailingNull ( utf8 );
ToUTF16 ( (const UTF8Unit*)utf8.data(), utf8.size(), &utf16, false );
if ( fields[fieldAuthor] != utf16 ) {
legacyDiff += utf16.size();
legacyDiff -= fields[fieldAuthor].size();
this->SetField ( fieldAuthor, utf16 );
objectsToExport |= objectContentDescription;
changed ++;
}
}
if ( xmp.GetLocalizedText ( kXMP_NS_DC, "rights", "", "x-default", 0, &utf8, &flags ) ) {
NormalizeStringTrailingNull ( utf8 );
ToUTF16 ( (const UTF8Unit*)utf8.data(), utf8.size(), &utf16, false );
if ( fields[fieldCopyright] != utf16 ) {
legacyDiff += utf16.size();
legacyDiff -= fields[fieldCopyright].size();
this->SetField ( fieldCopyright, utf16 );
objectsToExport |= objectContentDescription;
changed ++;
}
}
if ( xmp.GetLocalizedText ( kXMP_NS_DC, "description", "", "x-default", 0, &utf8, &flags ) ) {
NormalizeStringTrailingNull ( utf8 );
ToUTF16 ( (const UTF8Unit*)utf8.data(), utf8.size(), &utf16, false );
if ( fields[fieldDescription] != utf16 ) {
legacyDiff += utf16.size();
legacyDiff -= fields[fieldDescription].size();
this->SetField ( fieldDescription, utf16 );
objectsToExport |= objectContentDescription;
changed ++;
}
}
if ( xmp.GetProperty ( kXMP_NS_XMP_Rights, "WebStatement", &utf8, &flags ) ) {
NormalizeStringTrailingNull ( utf8 );
if ( fields[fieldCopyrightURL] != utf8 ) {
legacyDiff += utf8.size();
legacyDiff -= fields[fieldCopyrightURL].size();
this->SetField ( fieldCopyrightURL, utf8 );
objectsToExport |= objectContentBranding;
changed ++;
}
}
#if ! Exclude_LicenseURL_Recon
if ( xmp.GetProperty ( kXMP_NS_XMP_Rights, "Certificate", &utf8, &flags ) ) {
NormalizeStringTrailingNull ( utf8 );
if ( fields[fieldLicenseURL] != utf8 ) {
legacyDiff += utf8.size();
legacyDiff -= fields[fieldLicenseURL].size();
this->SetField ( fieldLicenseURL, utf8 );
objectsToExport |= objectContentEncryption;
changed ++;
}
}
#endif
int newObjects = (objectsToExport & !objectsExisting);
if ( newObjects & objectContentDescription )
legacyDiff += sizeContentDescription;
if ( newObjects & objectContentBranding )
legacyDiff += sizeContentBranding;
if ( newObjects & objectContentEncryption )
legacyDiff += sizeContentEncryption;
ComputeDigest();
return changed;
}
| DoS | 0 | int ASF_LegacyManager::ExportLegacy ( const SXMPMeta& xmp )
{
int changed = 0;
objectsToExport = 0;
legacyDiff = 0;
std::string utf8;
std::string utf16;
XMP_OptionBits flags;
if ( ! broadcastSet ) {
if ( xmp.GetProperty ( kXMP_NS_XMP, "CreateDate", &utf8, &flags ) ) {
std::string date;
ConvertISODateToMSDate ( utf8, &date );
if ( fields[fieldCreationDate] != date ) {
legacyDiff += date.size();
legacyDiff -= fields[fieldCreationDate].size();
this->SetField ( fieldCreationDate, date );
objectsToExport |= objectFileProperties;
changed ++;
}
}
}
if ( xmp.GetLocalizedText ( kXMP_NS_DC, "title", "", "x-default", 0, &utf8, &flags ) ) {
NormalizeStringTrailingNull ( utf8 );
ToUTF16 ( (const UTF8Unit*)utf8.data(), utf8.size(), &utf16, false );
if ( fields[fieldTitle] != utf16 ) {
legacyDiff += utf16.size();
legacyDiff -= fields[fieldTitle].size();
this->SetField ( fieldTitle, utf16 );
objectsToExport |= objectContentDescription;
changed ++;
}
}
utf8.clear();
SXMPUtils::CatenateArrayItems ( xmp, kXMP_NS_DC, "creator", 0, 0, kXMPUtil_AllowCommas, &utf8 );
if ( ! utf8.empty() ) {
NormalizeStringTrailingNull ( utf8 );
ToUTF16 ( (const UTF8Unit*)utf8.data(), utf8.size(), &utf16, false );
if ( fields[fieldAuthor] != utf16 ) {
legacyDiff += utf16.size();
legacyDiff -= fields[fieldAuthor].size();
this->SetField ( fieldAuthor, utf16 );
objectsToExport |= objectContentDescription;
changed ++;
}
}
if ( xmp.GetLocalizedText ( kXMP_NS_DC, "rights", "", "x-default", 0, &utf8, &flags ) ) {
NormalizeStringTrailingNull ( utf8 );
ToUTF16 ( (const UTF8Unit*)utf8.data(), utf8.size(), &utf16, false );
if ( fields[fieldCopyright] != utf16 ) {
legacyDiff += utf16.size();
legacyDiff -= fields[fieldCopyright].size();
this->SetField ( fieldCopyright, utf16 );
objectsToExport |= objectContentDescription;
changed ++;
}
}
if ( xmp.GetLocalizedText ( kXMP_NS_DC, "description", "", "x-default", 0, &utf8, &flags ) ) {
NormalizeStringTrailingNull ( utf8 );
ToUTF16 ( (const UTF8Unit*)utf8.data(), utf8.size(), &utf16, false );
if ( fields[fieldDescription] != utf16 ) {
legacyDiff += utf16.size();
legacyDiff -= fields[fieldDescription].size();
this->SetField ( fieldDescription, utf16 );
objectsToExport |= objectContentDescription;
changed ++;
}
}
if ( xmp.GetProperty ( kXMP_NS_XMP_Rights, "WebStatement", &utf8, &flags ) ) {
NormalizeStringTrailingNull ( utf8 );
if ( fields[fieldCopyrightURL] != utf8 ) {
legacyDiff += utf8.size();
legacyDiff -= fields[fieldCopyrightURL].size();
this->SetField ( fieldCopyrightURL, utf8 );
objectsToExport |= objectContentBranding;
changed ++;
}
}
#if ! Exclude_LicenseURL_Recon
if ( xmp.GetProperty ( kXMP_NS_XMP_Rights, "Certificate", &utf8, &flags ) ) {
NormalizeStringTrailingNull ( utf8 );
if ( fields[fieldLicenseURL] != utf8 ) {
legacyDiff += utf8.size();
legacyDiff -= fields[fieldLicenseURL].size();
this->SetField ( fieldLicenseURL, utf8 );
objectsToExport |= objectContentEncryption;
changed ++;
}
}
#endif
int newObjects = (objectsToExport & !objectsExisting);
if ( newObjects & objectContentDescription )
legacyDiff += sizeContentDescription;
if ( newObjects & objectContentBranding )
legacyDiff += sizeContentBranding;
if ( newObjects & objectContentEncryption )
legacyDiff += sizeContentEncryption;
ComputeDigest();
return changed;
}
| @@ -270,6 +270,8 @@ bool ASF_Support::ReadHeaderObject ( XMP_IO* fileRef, ObjectState& inOutObjectSt
this->ReadHeaderExtensionObject ( fileRef, inOutObjectState, pos, objectBase );
+ } else if (objectBase.size == 0) {
+ break;
}
pos += objectBase.size; | CWE-835 | null | null |
12,770 | bool ASF_LegacyManager::GetBroadcast()
{
return broadcastSet;
}
| DoS | 0 | bool ASF_LegacyManager::GetBroadcast()
{
return broadcastSet;
}
| @@ -270,6 +270,8 @@ bool ASF_Support::ReadHeaderObject ( XMP_IO* fileRef, ObjectState& inOutObjectSt
this->ReadHeaderExtensionObject ( fileRef, inOutObjectState, pos, objectBase );
+ } else if (objectBase.size == 0) {
+ break;
}
pos += objectBase.size; | CWE-835 | null | null |
12,771 | std::string ASF_LegacyManager::GetField ( fieldType field )
{
if ( field >= fieldLast ) return std::string();
return fields[field];
}
| DoS | 0 | std::string ASF_LegacyManager::GetField ( fieldType field )
{
if ( field >= fieldLast ) return std::string();
return fields[field];
}
| @@ -270,6 +270,8 @@ bool ASF_Support::ReadHeaderObject ( XMP_IO* fileRef, ObjectState& inOutObjectSt
this->ReadHeaderExtensionObject ( fileRef, inOutObjectState, pos, objectBase );
+ } else if (objectBase.size == 0) {
+ break;
}
pos += objectBase.size; | CWE-835 | null | null |
12,772 | unsigned int ASF_LegacyManager::GetFieldMaxSize ( fieldType field )
{
unsigned int maxSize = 0;
switch ( field ) {
case fieldCreationDate :
maxSize = 8;
break;
case fieldTitle :
case fieldAuthor :
case fieldCopyright :
case fieldDescription :
maxSize = 0xFFFF;
break;
case fieldCopyrightURL :
#if ! Exclude_LicenseURL_Recon
case fieldLicenseURL :
#endif
maxSize = 0xFFFFFFFF;
break;
default:
break;
}
return maxSize;
}
| DoS | 0 | unsigned int ASF_LegacyManager::GetFieldMaxSize ( fieldType field )
{
unsigned int maxSize = 0;
switch ( field ) {
case fieldCreationDate :
maxSize = 8;
break;
case fieldTitle :
case fieldAuthor :
case fieldCopyright :
case fieldDescription :
maxSize = 0xFFFF;
break;
case fieldCopyrightURL :
#if ! Exclude_LicenseURL_Recon
case fieldLicenseURL :
#endif
maxSize = 0xFFFFFFFF;
break;
default:
break;
}
return maxSize;
}
| @@ -270,6 +270,8 @@ bool ASF_Support::ReadHeaderObject ( XMP_IO* fileRef, ObjectState& inOutObjectSt
this->ReadHeaderExtensionObject ( fileRef, inOutObjectState, pos, objectBase );
+ } else if (objectBase.size == 0) {
+ break;
}
pos += objectBase.size; | CWE-835 | null | null |
12,773 | XMP_Int64 ASF_LegacyManager::GetPadding()
{
return padding;
}
| DoS | 0 | XMP_Int64 ASF_LegacyManager::GetPadding()
{
return padding;
}
| @@ -270,6 +270,8 @@ bool ASF_Support::ReadHeaderObject ( XMP_IO* fileRef, ObjectState& inOutObjectSt
this->ReadHeaderExtensionObject ( fileRef, inOutObjectState, pos, objectBase );
+ } else if (objectBase.size == 0) {
+ break;
}
pos += objectBase.size; | CWE-835 | null | null |
12,774 | void ASF_LegacyManager::ImportLegacy ( SXMPMeta* xmp )
{
std::string utf8;
if ( ! broadcastSet ) {
ConvertMSDateToISODate ( fields[fieldCreationDate], &utf8 );
if ( ! utf8.empty() ) xmp->SetProperty ( kXMP_NS_XMP, "CreateDate", utf8.c_str(), kXMP_DeleteExisting );
}
FromUTF16 ( (UTF16Unit*)fields[fieldTitle].c_str(), (fields[fieldTitle].size() / 2), &utf8, false );
if ( ! utf8.empty() ) xmp->SetLocalizedText ( kXMP_NS_DC, "title", "", "x-default", utf8.c_str(), kXMP_DeleteExisting );
xmp->DeleteProperty ( kXMP_NS_DC, "creator" );
FromUTF16 ( (UTF16Unit*)fields[fieldAuthor].c_str(), (fields[fieldAuthor].size() / 2), &utf8, false );
if ( ! utf8.empty() ) SXMPUtils::SeparateArrayItems ( xmp, kXMP_NS_DC, "creator",
(kXMP_PropArrayIsOrdered | kXMPUtil_AllowCommas), utf8.c_str() );
FromUTF16 ( (UTF16Unit*)fields[fieldCopyright].c_str(), (fields[fieldCopyright].size() / 2), &utf8, false );
if ( ! utf8.empty() ) xmp->SetLocalizedText ( kXMP_NS_DC, "rights", "", "x-default", utf8.c_str(), kXMP_DeleteExisting );
FromUTF16 ( (UTF16Unit*)fields[fieldDescription].c_str(), (fields[fieldDescription].size() / 2), &utf8, false );
if ( ! utf8.empty() ) xmp->SetLocalizedText ( kXMP_NS_DC, "description", "", "x-default", utf8.c_str(), kXMP_DeleteExisting );
if ( ! fields[fieldCopyrightURL].empty() ) xmp->SetProperty ( kXMP_NS_XMP_Rights, "WebStatement", fields[fieldCopyrightURL].c_str(), kXMP_DeleteExisting );
#if ! Exclude_LicenseURL_Recon
if ( ! fields[fieldLicenseURL].empty() ) xmp->SetProperty ( kXMP_NS_XMP_Rights, "Certificate", fields[fieldLicenseURL].c_str(), kXMP_DeleteExisting );
#endif
imported = true;
}
| DoS | 0 | void ASF_LegacyManager::ImportLegacy ( SXMPMeta* xmp )
{
std::string utf8;
if ( ! broadcastSet ) {
ConvertMSDateToISODate ( fields[fieldCreationDate], &utf8 );
if ( ! utf8.empty() ) xmp->SetProperty ( kXMP_NS_XMP, "CreateDate", utf8.c_str(), kXMP_DeleteExisting );
}
FromUTF16 ( (UTF16Unit*)fields[fieldTitle].c_str(), (fields[fieldTitle].size() / 2), &utf8, false );
if ( ! utf8.empty() ) xmp->SetLocalizedText ( kXMP_NS_DC, "title", "", "x-default", utf8.c_str(), kXMP_DeleteExisting );
xmp->DeleteProperty ( kXMP_NS_DC, "creator" );
FromUTF16 ( (UTF16Unit*)fields[fieldAuthor].c_str(), (fields[fieldAuthor].size() / 2), &utf8, false );
if ( ! utf8.empty() ) SXMPUtils::SeparateArrayItems ( xmp, kXMP_NS_DC, "creator",
(kXMP_PropArrayIsOrdered | kXMPUtil_AllowCommas), utf8.c_str() );
FromUTF16 ( (UTF16Unit*)fields[fieldCopyright].c_str(), (fields[fieldCopyright].size() / 2), &utf8, false );
if ( ! utf8.empty() ) xmp->SetLocalizedText ( kXMP_NS_DC, "rights", "", "x-default", utf8.c_str(), kXMP_DeleteExisting );
FromUTF16 ( (UTF16Unit*)fields[fieldDescription].c_str(), (fields[fieldDescription].size() / 2), &utf8, false );
if ( ! utf8.empty() ) xmp->SetLocalizedText ( kXMP_NS_DC, "description", "", "x-default", utf8.c_str(), kXMP_DeleteExisting );
if ( ! fields[fieldCopyrightURL].empty() ) xmp->SetProperty ( kXMP_NS_XMP_Rights, "WebStatement", fields[fieldCopyrightURL].c_str(), kXMP_DeleteExisting );
#if ! Exclude_LicenseURL_Recon
if ( ! fields[fieldLicenseURL].empty() ) xmp->SetProperty ( kXMP_NS_XMP_Rights, "Certificate", fields[fieldLicenseURL].c_str(), kXMP_DeleteExisting );
#endif
imported = true;
}
| @@ -270,6 +270,8 @@ bool ASF_Support::ReadHeaderObject ( XMP_IO* fileRef, ObjectState& inOutObjectSt
this->ReadHeaderExtensionObject ( fileRef, inOutObjectState, pos, objectBase );
+ } else if (objectBase.size == 0) {
+ break;
}
pos += objectBase.size; | CWE-835 | null | null |
12,775 | int IsEqualGUID ( const GUID& guid1, const GUID& guid2 )
{
return (memcmp ( &guid1, &guid2, sizeof(GUID) ) == 0);
}
| DoS | 0 | int IsEqualGUID ( const GUID& guid1, const GUID& guid2 )
{
return (memcmp ( &guid1, &guid2, sizeof(GUID) ) == 0);
}
| @@ -270,6 +270,8 @@ bool ASF_Support::ReadHeaderObject ( XMP_IO* fileRef, ObjectState& inOutObjectSt
this->ReadHeaderExtensionObject ( fileRef, inOutObjectState, pos, objectBase );
+ } else if (objectBase.size == 0) {
+ break;
}
pos += objectBase.size; | CWE-835 | null | null |
12,776 | bool ASF_LegacyManager::IsLeapYear ( long year )
{
if ( year < 0 ) year = -year + 1; // Fold the negative years, assuming there is a year 0.
if ( (year % 4) != 0 ) return false; // Not a multiple of 4.
if ( (year % 100) != 0 ) return true; // A multiple of 4 but not a multiple of 100.
if ( (year % 400) == 0 ) return true; // A multiple of 400.
return false; // A multiple of 100 but not a multiple of 400.
}
| DoS | 0 | bool ASF_LegacyManager::IsLeapYear ( long year )
{
if ( year < 0 ) year = -year + 1; // Fold the negative years, assuming there is a year 0.
if ( (year % 4) != 0 ) return false; // Not a multiple of 4.
if ( (year % 100) != 0 ) return true; // A multiple of 4 but not a multiple of 100.
if ( (year % 400) == 0 ) return true; // A multiple of 400.
return false; // A multiple of 100 but not a multiple of 400.
}
| @@ -270,6 +270,8 @@ bool ASF_Support::ReadHeaderObject ( XMP_IO* fileRef, ObjectState& inOutObjectSt
this->ReadHeaderExtensionObject ( fileRef, inOutObjectState, pos, objectBase );
+ } else if (objectBase.size == 0) {
+ break;
}
pos += objectBase.size; | CWE-835 | null | null |
12,777 | std::string ASF_LegacyManager::NormalizeStringDisplayASCII ( std::string& operand )
{
std::basic_string<char>::iterator current = operand.begin();
std::basic_string<char>::iterator end = operand.end();;
for ( ; (current != end); ++current ) {
char element = *current;
if ( ( (element < 0x21) && (element != 0x00)) || (element > 0x7e) ) {
*current = '?';
}
}
return operand;
}
| DoS | 0 | std::string ASF_LegacyManager::NormalizeStringDisplayASCII ( std::string& operand )
{
std::basic_string<char>::iterator current = operand.begin();
std::basic_string<char>::iterator end = operand.end();;
for ( ; (current != end); ++current ) {
char element = *current;
if ( ( (element < 0x21) && (element != 0x00)) || (element > 0x7e) ) {
*current = '?';
}
}
return operand;
}
| @@ -270,6 +270,8 @@ bool ASF_Support::ReadHeaderObject ( XMP_IO* fileRef, ObjectState& inOutObjectSt
this->ReadHeaderExtensionObject ( fileRef, inOutObjectState, pos, objectBase );
+ } else if (objectBase.size == 0) {
+ break;
}
pos += objectBase.size; | CWE-835 | null | null |
12,778 | std::string ASF_LegacyManager::NormalizeStringTrailingNull ( std::string& operand )
{
if ( ( operand.size() > 0) && (operand[operand.size() - 1] != '\0') ) {
operand.append ( 1, '\0' );
}
return operand;
}
| DoS | 0 | std::string ASF_LegacyManager::NormalizeStringTrailingNull ( std::string& operand )
{
if ( ( operand.size() > 0) && (operand[operand.size() - 1] != '\0') ) {
operand.append ( 1, '\0' );
}
return operand;
}
| @@ -270,6 +270,8 @@ bool ASF_Support::ReadHeaderObject ( XMP_IO* fileRef, ObjectState& inOutObjectSt
this->ReadHeaderExtensionObject ( fileRef, inOutObjectState, pos, objectBase );
+ } else if (objectBase.size == 0) {
+ break;
}
pos += objectBase.size; | CWE-835 | null | null |
12,779 | long ASF_Support::OpenASF ( XMP_IO* fileRef, ObjectState & inOutObjectState )
{
XMP_Uns64 pos = 0;
XMP_Uns64 len;
try {
pos = fileRef->Rewind();
} catch ( ... ) {}
if ( pos != 0 ) return 0;
while ( ReadObject ( fileRef, inOutObjectState, &len, pos) ) {}
return inOutObjectState.objects.size();
}
| DoS | 0 | long ASF_Support::OpenASF ( XMP_IO* fileRef, ObjectState & inOutObjectState )
{
XMP_Uns64 pos = 0;
XMP_Uns64 len;
try {
pos = fileRef->Rewind();
} catch ( ... ) {}
if ( pos != 0 ) return 0;
while ( ReadObject ( fileRef, inOutObjectState, &len, pos) ) {}
return inOutObjectState.objects.size();
}
| @@ -270,6 +270,8 @@ bool ASF_Support::ReadHeaderObject ( XMP_IO* fileRef, ObjectState& inOutObjectSt
this->ReadHeaderExtensionObject ( fileRef, inOutObjectState, pos, objectBase );
+ } else if (objectBase.size == 0) {
+ break;
}
pos += objectBase.size; | CWE-835 | null | null |
12,780 | bool ASF_Support::ReadBuffer ( XMP_IO* fileRef, XMP_Uns64 & pos, XMP_Uns64 len, char * outBuffer )
{
try {
if ( (fileRef == 0) || (outBuffer == 0) ) return false;
fileRef->Seek ( pos, kXMP_SeekFromStart );
long bytesRead = fileRef->ReadAll ( outBuffer, XMP_Int32(len) );
if ( XMP_Uns32 ( bytesRead ) != len ) return false;
return true;
} catch ( ... ) {}
return false;
}
| DoS | 0 | bool ASF_Support::ReadBuffer ( XMP_IO* fileRef, XMP_Uns64 & pos, XMP_Uns64 len, char * outBuffer )
{
try {
if ( (fileRef == 0) || (outBuffer == 0) ) return false;
fileRef->Seek ( pos, kXMP_SeekFromStart );
long bytesRead = fileRef->ReadAll ( outBuffer, XMP_Int32(len) );
if ( XMP_Uns32 ( bytesRead ) != len ) return false;
return true;
} catch ( ... ) {}
return false;
}
| @@ -270,6 +270,8 @@ bool ASF_Support::ReadHeaderObject ( XMP_IO* fileRef, ObjectState& inOutObjectSt
this->ReadHeaderExtensionObject ( fileRef, inOutObjectState, pos, objectBase );
+ } else if (objectBase.size == 0) {
+ break;
}
pos += objectBase.size; | CWE-835 | null | null |
12,781 | bool ASF_Support::ReadHeaderExtensionObject ( XMP_IO* fileRef, ObjectState& inOutObjectState, const XMP_Uns64& _pos, const ASF_ObjectBase& _objectBase )
{
if ( ! IsEqualGUID ( ASF_Header_Extension_Object, _objectBase.guid) || (! legacyManager ) ) return false;
try {
const XMP_Uns64 offset = 46;
XMP_Uns64 read = 0;
XMP_Uns64 data = (_objectBase.size - offset);
XMP_Uns64 pos = (_pos + offset);
ASF_ObjectBase objectBase;
while ( read < data ) {
fileRef->Seek ( pos, kXMP_SeekFromStart );
if ( kASF_ObjectBaseLen != fileRef->Read ( &objectBase, kASF_ObjectBaseLen, true ) ) break;
objectBase.size = GetUns64LE ( &objectBase.size );
if ( IsEqualGUID ( ASF_Padding_Object, objectBase.guid ) ) {
legacyManager->SetPadding ( legacyManager->GetPadding() + (objectBase.size - 24) );
}
pos += objectBase.size;
read += objectBase.size;
}
} catch ( ... ) {
return false;
}
return true;
}
| DoS | 0 | bool ASF_Support::ReadHeaderExtensionObject ( XMP_IO* fileRef, ObjectState& inOutObjectState, const XMP_Uns64& _pos, const ASF_ObjectBase& _objectBase )
{
if ( ! IsEqualGUID ( ASF_Header_Extension_Object, _objectBase.guid) || (! legacyManager ) ) return false;
try {
const XMP_Uns64 offset = 46;
XMP_Uns64 read = 0;
XMP_Uns64 data = (_objectBase.size - offset);
XMP_Uns64 pos = (_pos + offset);
ASF_ObjectBase objectBase;
while ( read < data ) {
fileRef->Seek ( pos, kXMP_SeekFromStart );
if ( kASF_ObjectBaseLen != fileRef->Read ( &objectBase, kASF_ObjectBaseLen, true ) ) break;
objectBase.size = GetUns64LE ( &objectBase.size );
if ( IsEqualGUID ( ASF_Padding_Object, objectBase.guid ) ) {
legacyManager->SetPadding ( legacyManager->GetPadding() + (objectBase.size - 24) );
}
pos += objectBase.size;
read += objectBase.size;
}
} catch ( ... ) {
return false;
}
return true;
}
| @@ -270,6 +270,8 @@ bool ASF_Support::ReadHeaderObject ( XMP_IO* fileRef, ObjectState& inOutObjectSt
this->ReadHeaderExtensionObject ( fileRef, inOutObjectState, pos, objectBase );
+ } else if (objectBase.size == 0) {
+ break;
}
pos += objectBase.size; | CWE-835 | null | null |
12,782 | Container::Container(WEBP_MetaHandler* handler) : Chunk(NULL, handler)
{
this->needsRewrite = false;
XMP_IO* file = handler->parent->ioRef;
file->Seek(12, kXMP_SeekFromStart);
XMP_Int64 size = handler->initialFileSize;
XMP_Uns32 peek = 0;
while (file->Offset() < size) {
peek = XIO::PeekUns32_LE(file);
switch (peek) {
case kChunk_XMP_:
this->addChunk(new XMPChunk(this, handler));
break;
case kChunk_VP8X:
this->addChunk(new VP8XChunk(this, handler));
break;
default:
this->addChunk(new Chunk(this, handler));
break;
}
}
if (this->chunks[WEBP_CHUNK_IMAGE].size() == 0) {
XMP_Throw("File has no image bitstream", kXMPErr_BadFileFormat);
}
if (this->chunks[WEBP_CHUNK_VP8X].size() == 0) {
this->needsRewrite = true;
this->addChunk(new VP8XChunk(this));
}
if (this->chunks[WEBP_CHUNK_XMP].size() == 0) {
XMPChunk* xmpChunk = new XMPChunk(this);
this->addChunk(xmpChunk);
handler->xmpChunk = xmpChunk;
this->vp8x->xmp(true);
}
}
| DoS | 0 | Container::Container(WEBP_MetaHandler* handler) : Chunk(NULL, handler)
{
this->needsRewrite = false;
XMP_IO* file = handler->parent->ioRef;
file->Seek(12, kXMP_SeekFromStart);
XMP_Int64 size = handler->initialFileSize;
XMP_Uns32 peek = 0;
while (file->Offset() < size) {
peek = XIO::PeekUns32_LE(file);
switch (peek) {
case kChunk_XMP_:
this->addChunk(new XMPChunk(this, handler));
break;
case kChunk_VP8X:
this->addChunk(new VP8XChunk(this, handler));
break;
default:
this->addChunk(new Chunk(this, handler));
break;
}
}
if (this->chunks[WEBP_CHUNK_IMAGE].size() == 0) {
XMP_Throw("File has no image bitstream", kXMPErr_BadFileFormat);
}
if (this->chunks[WEBP_CHUNK_VP8X].size() == 0) {
this->needsRewrite = true;
this->addChunk(new VP8XChunk(this));
}
if (this->chunks[WEBP_CHUNK_XMP].size() == 0) {
XMPChunk* xmpChunk = new XMPChunk(this);
this->addChunk(xmpChunk);
handler->xmpChunk = xmpChunk;
this->vp8x->xmp(true);
}
}
| @@ -141,7 +141,7 @@ XMP_Uns32 VP8XChunk::width()
}
void VP8XChunk::width(XMP_Uns32 val)
{
- PutLE24(&this->data[4], val - 1);
+ PutLE24(&this->data[4], val > 0 ? val - 1 : 0);
}
XMP_Uns32 VP8XChunk::height()
{
@@ -149,7 +149,7 @@ XMP_Uns32 VP8XChunk::height()
}
void VP8XChunk::height(XMP_Uns32 val)
{
- PutLE24(&this->data[7], val - 1);
+ PutLE24(&this->data[7], val > 0 ? val - 1 : 0);
}
bool VP8XChunk::xmp()
{ | CWE-20 | null | null |
12,783 | VP8XChunk::VP8XChunk(Container* parent)
: Chunk(parent, kChunk_VP8X)
{
this->needsRewrite = true;
this->size = 10;
this->data.resize(this->size);
this->data.assign(this->size, 0);
XMP_Uns8* bitstream =
(XMP_Uns8*)parent->chunks[WEBP_CHUNK_IMAGE][0]->data.data();
XMP_Uns32 width = ((bitstream[7] << 8) | bitstream[6]) & 0x3fff;
XMP_Uns32 height = ((bitstream[9] << 8) | bitstream[8]) & 0x3fff;
this->width(width);
this->height(height);
parent->vp8x = this;
}
| DoS | 0 | VP8XChunk::VP8XChunk(Container* parent)
: Chunk(parent, kChunk_VP8X)
{
this->needsRewrite = true;
this->size = 10;
this->data.resize(this->size);
this->data.assign(this->size, 0);
XMP_Uns8* bitstream =
(XMP_Uns8*)parent->chunks[WEBP_CHUNK_IMAGE][0]->data.data();
XMP_Uns32 width = ((bitstream[7] << 8) | bitstream[6]) & 0x3fff;
XMP_Uns32 height = ((bitstream[9] << 8) | bitstream[8]) & 0x3fff;
this->width(width);
this->height(height);
parent->vp8x = this;
}
| @@ -141,7 +141,7 @@ XMP_Uns32 VP8XChunk::width()
}
void VP8XChunk::width(XMP_Uns32 val)
{
- PutLE24(&this->data[4], val - 1);
+ PutLE24(&this->data[4], val > 0 ? val - 1 : 0);
}
XMP_Uns32 VP8XChunk::height()
{
@@ -149,7 +149,7 @@ XMP_Uns32 VP8XChunk::height()
}
void VP8XChunk::height(XMP_Uns32 val)
{
- PutLE24(&this->data[7], val - 1);
+ PutLE24(&this->data[7], val > 0 ? val - 1 : 0);
}
bool VP8XChunk::xmp()
{ | CWE-20 | null | null |
12,784 | void Container::addChunk(Chunk* chunk)
{
ChunkId idx;
try {
idx = chunkMap.at(chunk->tag);
}
catch (const std::out_of_range& e) {
idx = WEBP_CHUNK_UNKNOWN;
}
this->chunks[idx].push_back(chunk);
}
| DoS | 0 | void Container::addChunk(Chunk* chunk)
{
ChunkId idx;
try {
idx = chunkMap.at(chunk->tag);
}
catch (const std::out_of_range& e) {
idx = WEBP_CHUNK_UNKNOWN;
}
this->chunks[idx].push_back(chunk);
}
| @@ -141,7 +141,7 @@ XMP_Uns32 VP8XChunk::width()
}
void VP8XChunk::width(XMP_Uns32 val)
{
- PutLE24(&this->data[4], val - 1);
+ PutLE24(&this->data[4], val > 0 ? val - 1 : 0);
}
XMP_Uns32 VP8XChunk::height()
{
@@ -149,7 +149,7 @@ XMP_Uns32 VP8XChunk::height()
}
void VP8XChunk::height(XMP_Uns32 val)
{
- PutLE24(&this->data[7], val - 1);
+ PutLE24(&this->data[7], val > 0 ? val - 1 : 0);
}
bool VP8XChunk::xmp()
{ | CWE-20 | null | null |
12,785 | Chunk* Container::getExifChunk()
{
if (this->chunks[WEBP::WEBP_CHUNK_EXIF].size() == 0) {
return NULL;
}
return this->chunks[WEBP::WEBP_CHUNK_EXIF][0];
}
| DoS | 0 | Chunk* Container::getExifChunk()
{
if (this->chunks[WEBP::WEBP_CHUNK_EXIF].size() == 0) {
return NULL;
}
return this->chunks[WEBP::WEBP_CHUNK_EXIF][0];
}
| @@ -141,7 +141,7 @@ XMP_Uns32 VP8XChunk::width()
}
void VP8XChunk::width(XMP_Uns32 val)
{
- PutLE24(&this->data[4], val - 1);
+ PutLE24(&this->data[4], val > 0 ? val - 1 : 0);
}
XMP_Uns32 VP8XChunk::height()
{
@@ -149,7 +149,7 @@ XMP_Uns32 VP8XChunk::height()
}
void VP8XChunk::height(XMP_Uns32 val)
{
- PutLE24(&this->data[7], val - 1);
+ PutLE24(&this->data[7], val > 0 ? val - 1 : 0);
}
bool VP8XChunk::xmp()
{ | CWE-20 | null | null |
12,786 | XMP_Uns32 VP8XChunk::height()
{
return GetLE24(&this->data[7]) + 1;
}
| DoS | 0 | XMP_Uns32 VP8XChunk::height()
{
return GetLE24(&this->data[7]) + 1;
}
| @@ -141,7 +141,7 @@ XMP_Uns32 VP8XChunk::width()
}
void VP8XChunk::width(XMP_Uns32 val)
{
- PutLE24(&this->data[4], val - 1);
+ PutLE24(&this->data[4], val > 0 ? val - 1 : 0);
}
XMP_Uns32 VP8XChunk::height()
{
@@ -149,7 +149,7 @@ XMP_Uns32 VP8XChunk::height()
}
void VP8XChunk::height(XMP_Uns32 val)
{
- PutLE24(&this->data[7], val - 1);
+ PutLE24(&this->data[7], val > 0 ? val - 1 : 0);
}
bool VP8XChunk::xmp()
{ | CWE-20 | null | null |
12,787 | XMP_Uns32 VP8XChunk::width()
{
return GetLE24(&this->data[4]) + 1;
}
| DoS | 0 | XMP_Uns32 VP8XChunk::width()
{
return GetLE24(&this->data[4]) + 1;
}
| @@ -141,7 +141,7 @@ XMP_Uns32 VP8XChunk::width()
}
void VP8XChunk::width(XMP_Uns32 val)
{
- PutLE24(&this->data[4], val - 1);
+ PutLE24(&this->data[4], val > 0 ? val - 1 : 0);
}
XMP_Uns32 VP8XChunk::height()
{
@@ -149,7 +149,7 @@ XMP_Uns32 VP8XChunk::height()
}
void VP8XChunk::height(XMP_Uns32 val)
{
- PutLE24(&this->data[7], val - 1);
+ PutLE24(&this->data[7], val > 0 ? val - 1 : 0);
}
bool VP8XChunk::xmp()
{ | CWE-20 | null | null |
12,788 | void Container::write(WEBP_MetaHandler* handler)
{
XMP_IO* file = handler->parent->ioRef;
file->Rewind();
XIO::WriteUns32_LE(file, this->tag);
XIO::WriteUns32_LE(file, (XMP_Uns32) this->size);
XIO::WriteUns32_LE(file, kChunk_WEBP);
size_t i, j;
std::vector<Chunk*> chunkVect;
for (i = 0; i < WEBP_CHUNK_NIL; i++) {
chunkVect = this->chunks[i];
for (j = 0; j < chunkVect.size(); j++) {
chunkVect.at(j)->write(handler);
}
}
XMP_Int64 lastOffset = file->Offset();
this->size = lastOffset - 8;
file->Seek(this->pos + 4, kXMP_SeekFromStart);
XIO::WriteUns32_LE(file, (XMP_Uns32) this->size);
file->Seek(lastOffset, kXMP_SeekFromStart);
if (lastOffset < handler->initialFileSize) {
file->Truncate(lastOffset);
}
}
| DoS | 0 | void Container::write(WEBP_MetaHandler* handler)
{
XMP_IO* file = handler->parent->ioRef;
file->Rewind();
XIO::WriteUns32_LE(file, this->tag);
XIO::WriteUns32_LE(file, (XMP_Uns32) this->size);
XIO::WriteUns32_LE(file, kChunk_WEBP);
size_t i, j;
std::vector<Chunk*> chunkVect;
for (i = 0; i < WEBP_CHUNK_NIL; i++) {
chunkVect = this->chunks[i];
for (j = 0; j < chunkVect.size(); j++) {
chunkVect.at(j)->write(handler);
}
}
XMP_Int64 lastOffset = file->Offset();
this->size = lastOffset - 8;
file->Seek(this->pos + 4, kXMP_SeekFromStart);
XIO::WriteUns32_LE(file, (XMP_Uns32) this->size);
file->Seek(lastOffset, kXMP_SeekFromStart);
if (lastOffset < handler->initialFileSize) {
file->Truncate(lastOffset);
}
}
| @@ -141,7 +141,7 @@ XMP_Uns32 VP8XChunk::width()
}
void VP8XChunk::width(XMP_Uns32 val)
{
- PutLE24(&this->data[4], val - 1);
+ PutLE24(&this->data[4], val > 0 ? val - 1 : 0);
}
XMP_Uns32 VP8XChunk::height()
{
@@ -149,7 +149,7 @@ XMP_Uns32 VP8XChunk::height()
}
void VP8XChunk::height(XMP_Uns32 val)
{
- PutLE24(&this->data[7], val - 1);
+ PutLE24(&this->data[7], val > 0 ? val - 1 : 0);
}
bool VP8XChunk::xmp()
{ | CWE-20 | null | null |
12,789 | bool VP8XChunk::xmp()
{
XMP_Uns32 flags = GetLE32(&this->data[0]);
return (bool)((flags >> XMP_FLAG_BIT) & 1);
}
| DoS | 0 | bool VP8XChunk::xmp()
{
XMP_Uns32 flags = GetLE32(&this->data[0]);
return (bool)((flags >> XMP_FLAG_BIT) & 1);
}
| @@ -141,7 +141,7 @@ XMP_Uns32 VP8XChunk::width()
}
void VP8XChunk::width(XMP_Uns32 val)
{
- PutLE24(&this->data[4], val - 1);
+ PutLE24(&this->data[4], val > 0 ? val - 1 : 0);
}
XMP_Uns32 VP8XChunk::height()
{
@@ -149,7 +149,7 @@ XMP_Uns32 VP8XChunk::height()
}
void VP8XChunk::height(XMP_Uns32 val)
{
- PutLE24(&this->data[7], val - 1);
+ PutLE24(&this->data[7], val > 0 ? val - 1 : 0);
}
bool VP8XChunk::xmp()
{ | CWE-20 | null | null |
12,790 | void VP8XChunk::xmp(bool hasXMP)
{
XMP_Uns32 flags = GetLE32(&this->data[0]);
flags ^= (-hasXMP ^ flags) & (1 << XMP_FLAG_BIT);
PutLE32(&this->data[0], flags);
}
| DoS | 0 | void VP8XChunk::xmp(bool hasXMP)
{
XMP_Uns32 flags = GetLE32(&this->data[0]);
flags ^= (-hasXMP ^ flags) & (1 << XMP_FLAG_BIT);
PutLE32(&this->data[0], flags);
}
| @@ -141,7 +141,7 @@ XMP_Uns32 VP8XChunk::width()
}
void VP8XChunk::width(XMP_Uns32 val)
{
- PutLE24(&this->data[4], val - 1);
+ PutLE24(&this->data[4], val > 0 ? val - 1 : 0);
}
XMP_Uns32 VP8XChunk::height()
{
@@ -149,7 +149,7 @@ XMP_Uns32 VP8XChunk::height()
}
void VP8XChunk::height(XMP_Uns32 val)
{
- PutLE24(&this->data[7], val - 1);
+ PutLE24(&this->data[7], val > 0 ? val - 1 : 0);
}
bool VP8XChunk::xmp()
{ | CWE-20 | null | null |
12,791 | Container::~Container()
{
Chunk* chunk;
size_t i;
std::vector<Chunk*> chunkVect;
for (i = 0; i < WEBP_CHUNK_NIL; i++) {
chunkVect = this->chunks[i];
while (!chunkVect.empty()) {
chunk = chunkVect.back();
delete chunk;
chunkVect.pop_back();
}
}
}
| DoS | 0 | Container::~Container()
{
Chunk* chunk;
size_t i;
std::vector<Chunk*> chunkVect;
for (i = 0; i < WEBP_CHUNK_NIL; i++) {
chunkVect = this->chunks[i];
while (!chunkVect.empty()) {
chunk = chunkVect.back();
delete chunk;
chunkVect.pop_back();
}
}
}
| @@ -141,7 +141,7 @@ XMP_Uns32 VP8XChunk::width()
}
void VP8XChunk::width(XMP_Uns32 val)
{
- PutLE24(&this->data[4], val - 1);
+ PutLE24(&this->data[4], val > 0 ? val - 1 : 0);
}
XMP_Uns32 VP8XChunk::height()
{
@@ -149,7 +149,7 @@ XMP_Uns32 VP8XChunk::height()
}
void VP8XChunk::height(XMP_Uns32 val)
{
- PutLE24(&this->data[7], val - 1);
+ PutLE24(&this->data[7], val > 0 ? val - 1 : 0);
}
bool VP8XChunk::xmp()
{ | CWE-20 | null | null |
12,792 | static bool DecodeRational ( const char * ratio, XMP_Uns32 * num, XMP_Uns32 * denom ) {
unsigned long locNum, locDenom;
char nextChar; // Used to make sure sscanf consumes all of the string.
int items = sscanf ( ratio, "%lu/%lu%c", &locNum, &locDenom, &nextChar ); // AUDIT: This is safe, check the calls.
if ( items != 2 ) {
if ( items != 1 ) return false;
locDenom = 1; // The XMP was just an integer, assume a denominator of 1.
}
*num = (XMP_Uns32)locNum;
*denom = (XMP_Uns32)locDenom;
return true;
} // DecodeRational
| DoS | 0 | static bool DecodeRational ( const char * ratio, XMP_Uns32 * num, XMP_Uns32 * denom ) {
unsigned long locNum, locDenom;
char nextChar; // Used to make sure sscanf consumes all of the string.
int items = sscanf ( ratio, "%lu/%lu%c", &locNum, &locDenom, &nextChar ); // AUDIT: This is safe, check the calls.
if ( items != 2 ) {
if ( items != 1 ) return false;
locDenom = 1; // The XMP was just an integer, assume a denominator of 1.
}
*num = (XMP_Uns32)locNum;
*denom = (XMP_Uns32)locDenom;
return true;
} // DecodeRational
| @@ -233,7 +233,7 @@ static XMP_Uns32 GatherInt ( const char * strPtr, size_t count )
static size_t TrimTrailingSpaces ( char * firstChar, size_t origLen )
{
- if ( origLen == 0 ) return 0;
+ if ( !firstChar || origLen == 0 ) return 0;
char * lastChar = firstChar + origLen - 1;
if ( (*lastChar != ' ') && (*lastChar != 0) ) return origLen; // Nothing to do. | CWE-416 | null | null |
12,793 | ExportArrayTIFF ( TIFF_Manager * tiff, XMP_Uns8 ifd, const TIFF_MappingToXMP & mapInfo, bool nativeEndian,
const SXMPMeta & xmp, const char * xmpNS, const char * xmpArray )
{
XMP_Assert ( (mapInfo.count != 1) && (mapInfo.type != kTIFF_ASCIIType) );
XMP_Assert ( mapInfo.name[0] != 0 ); // Must be a standard mapping.
XMP_Assert ( (mapInfo.type == kTIFF_ShortType) || (mapInfo.type == kTIFF_RationalType) );
XMP_Assert ( xmp.DoesPropertyExist ( xmpNS, xmpArray ) );
size_t arraySize = xmp.CountArrayItems ( xmpNS, xmpArray );
if ( arraySize == 0 ) {
tiff->DeleteTag ( ifd, mapInfo.id );
return;
}
if ( mapInfo.type == kTIFF_ShortType ) {
std::vector<XMP_Uns16> shortVector;
shortVector.assign ( arraySize, 0 );
XMP_Uns16 * shortPtr = (XMP_Uns16*) &shortVector[0];
std::string itemPath;
XMP_Int32 int32;
XMP_Uns16 uns16;
for ( size_t i = 1; i <= arraySize; ++i, ++shortPtr ) {
SXMPUtils::ComposeArrayItemPath ( xmpNS, xmpArray, (XMP_Index)i, &itemPath );
xmp.GetProperty_Int ( xmpNS, itemPath.c_str(), &int32, 0 );
uns16 = (XMP_Uns16)int32;
if ( ! nativeEndian ) uns16 = Flip2 ( uns16 );
*shortPtr = uns16;
}
tiff->SetTag ( ifd, mapInfo.id, kTIFF_ShortType, (XMP_Uns32)arraySize, &shortVector[0] );
} else if ( mapInfo.type == kTIFF_RationalType ) {
std::vector<XMP_Uns32> rationalVector;
rationalVector.assign ( 2*arraySize, 0 );
XMP_Uns32 * rationalPtr = (XMP_Uns32*) &rationalVector[0];
std::string itemPath, xmpValue;
XMP_Uns32 num, denom;
for ( size_t i = 1; i <= arraySize; ++i, rationalPtr += 2 ) {
SXMPUtils::ComposeArrayItemPath ( xmpNS, xmpArray, (XMP_Index)i, &itemPath );
bool isPropoerty = xmp.GetProperty ( xmpNS, itemPath.c_str(), &xmpValue, 0 );
if ( ! isPropoerty ) return;
bool ok = DecodeRational ( xmpValue.c_str(), &num, &denom );
if ( ! ok ) return;
if ( ! nativeEndian ) { num = Flip4 ( num ); denom = Flip4 ( denom ); }
rationalPtr[0] = num;
rationalPtr[1] = denom;
}
tiff->SetTag ( ifd, mapInfo.id, kTIFF_RationalType, (XMP_Uns32)arraySize, &rationalVector[0] );
}
} // ExportArrayTIFF
| DoS | 0 | ExportArrayTIFF ( TIFF_Manager * tiff, XMP_Uns8 ifd, const TIFF_MappingToXMP & mapInfo, bool nativeEndian,
const SXMPMeta & xmp, const char * xmpNS, const char * xmpArray )
{
XMP_Assert ( (mapInfo.count != 1) && (mapInfo.type != kTIFF_ASCIIType) );
XMP_Assert ( mapInfo.name[0] != 0 ); // Must be a standard mapping.
XMP_Assert ( (mapInfo.type == kTIFF_ShortType) || (mapInfo.type == kTIFF_RationalType) );
XMP_Assert ( xmp.DoesPropertyExist ( xmpNS, xmpArray ) );
size_t arraySize = xmp.CountArrayItems ( xmpNS, xmpArray );
if ( arraySize == 0 ) {
tiff->DeleteTag ( ifd, mapInfo.id );
return;
}
if ( mapInfo.type == kTIFF_ShortType ) {
std::vector<XMP_Uns16> shortVector;
shortVector.assign ( arraySize, 0 );
XMP_Uns16 * shortPtr = (XMP_Uns16*) &shortVector[0];
std::string itemPath;
XMP_Int32 int32;
XMP_Uns16 uns16;
for ( size_t i = 1; i <= arraySize; ++i, ++shortPtr ) {
SXMPUtils::ComposeArrayItemPath ( xmpNS, xmpArray, (XMP_Index)i, &itemPath );
xmp.GetProperty_Int ( xmpNS, itemPath.c_str(), &int32, 0 );
uns16 = (XMP_Uns16)int32;
if ( ! nativeEndian ) uns16 = Flip2 ( uns16 );
*shortPtr = uns16;
}
tiff->SetTag ( ifd, mapInfo.id, kTIFF_ShortType, (XMP_Uns32)arraySize, &shortVector[0] );
} else if ( mapInfo.type == kTIFF_RationalType ) {
std::vector<XMP_Uns32> rationalVector;
rationalVector.assign ( 2*arraySize, 0 );
XMP_Uns32 * rationalPtr = (XMP_Uns32*) &rationalVector[0];
std::string itemPath, xmpValue;
XMP_Uns32 num, denom;
for ( size_t i = 1; i <= arraySize; ++i, rationalPtr += 2 ) {
SXMPUtils::ComposeArrayItemPath ( xmpNS, xmpArray, (XMP_Index)i, &itemPath );
bool isPropoerty = xmp.GetProperty ( xmpNS, itemPath.c_str(), &xmpValue, 0 );
if ( ! isPropoerty ) return;
bool ok = DecodeRational ( xmpValue.c_str(), &num, &denom );
if ( ! ok ) return;
if ( ! nativeEndian ) { num = Flip4 ( num ); denom = Flip4 ( denom ); }
rationalPtr[0] = num;
rationalPtr[1] = denom;
}
tiff->SetTag ( ifd, mapInfo.id, kTIFF_RationalType, (XMP_Uns32)arraySize, &rationalVector[0] );
}
} // ExportArrayTIFF
| @@ -233,7 +233,7 @@ static XMP_Uns32 GatherInt ( const char * strPtr, size_t count )
static size_t TrimTrailingSpaces ( char * firstChar, size_t origLen )
{
- if ( origLen == 0 ) return 0;
+ if ( !firstChar || origLen == 0 ) return 0;
char * lastChar = firstChar + origLen - 1;
if ( (*lastChar != ' ') && (*lastChar != 0) ) return origLen; // Nothing to do. | CWE-416 | null | null |
12,794 | PhotoDataUtils::ExportExif ( SXMPMeta * xmp, TIFF_Manager * exif )
{
bool haveXMP;
std::string xmpValue;
XMP_Int32 int32;
XMP_Uns8 uns8;
#if SupportOldExifProperties
XMP_OptionBits flags;
haveXMP = xmp->DoesPropertyExist ( kXMP_NS_ExifEX, "PhotographicSensitivity" );
if ( ! haveXMP ) {
haveXMP = xmp->GetProperty ( kXMP_NS_EXIF, "ISOSpeedRatings", 0, &flags );
if ( haveXMP && XMP_PropIsArray(flags) ) {
haveXMP = xmp->GetArrayItem ( kXMP_NS_EXIF, "ISOSpeedRatings", 1, &xmpValue, 0 );
if ( haveXMP ) xmp->SetProperty ( kXMP_NS_ExifEX, "PhotographicSensitivity", xmpValue.c_str() );
}
}
haveXMP = xmp->DoesPropertyExist ( kXMP_NS_ExifEX, "CameraOwnerName" );
if ( ! haveXMP ) {
haveXMP = xmp->GetProperty ( kXMP_NS_EXIF_Aux, "OwnerName", &xmpValue, 0 );
if ( haveXMP ) xmp->SetProperty ( kXMP_NS_ExifEX, "CameraOwnerName", xmpValue.c_str() );
}
haveXMP = xmp->DoesPropertyExist ( kXMP_NS_ExifEX, "BodySerialNumber" );
if ( ! haveXMP ) {
haveXMP = xmp->GetProperty ( kXMP_NS_EXIF_Aux, "SerialNumber", &xmpValue, 0 );
if ( haveXMP ) xmp->SetProperty ( kXMP_NS_ExifEX, "BodySerialNumber", xmpValue.c_str() );
}
haveXMP = xmp->DoesPropertyExist ( kXMP_NS_ExifEX, "LensModel" );
if ( ! haveXMP ) {
haveXMP = xmp->GetProperty ( kXMP_NS_EXIF_Aux, "Lens", &xmpValue, 0 );
if ( haveXMP ) xmp->SetProperty ( kXMP_NS_ExifEX, "LensModel", xmpValue.c_str() );
}
haveXMP = xmp->DoesPropertyExist ( kXMP_NS_ExifEX, "LensSpecification" );
if ( ! haveXMP ) {
haveXMP = xmp->GetProperty ( kXMP_NS_EXIF_Aux, "LensInfo", &xmpValue, 0 );
if ( haveXMP ) {
size_t start, end;
std::string nextItem;
for ( start = 0; start < xmpValue.size(); start = end + 1 ) {
end = xmpValue.find ( ' ', start );
if ( end == start ) continue;
if ( end == std::string::npos ) end = xmpValue.size();
nextItem = xmpValue.substr ( start, (end-start) );
xmp->AppendArrayItem ( kXMP_NS_ExifEX, "LensSpecification", kXMP_PropArrayIsOrdered, nextItem.c_str() );
}
}
}
#endif
ExportTIFF_StandardMappings ( kTIFF_PrimaryIFD, exif, *xmp );
ExportTIFF_StandardMappings ( kTIFF_ExifIFD, exif, *xmp );
ExportTIFF_StandardMappings ( kTIFF_GPSInfoIFD, exif, *xmp );
TIFF_Manager::Rational altValue;
bool haveExif = exif->GetTag_Rational ( kTIFF_GPSInfoIFD, kTIFF_GPSAltitude, &altValue );
if ( haveExif ) {
bool fixExif = false;
if ( altValue.denom >> 31 ) { // Shift the sign to the numerator.
altValue.denom = -altValue.denom;
altValue.num = -altValue.num;
fixExif = true;
}
if ( altValue.num >> 31 ) { // Fix the numerator and set GPSAltitudeRef.
exif->SetTag_Byte ( kTIFF_GPSInfoIFD, kTIFF_GPSAltitudeRef, 1 );
altValue.num = -altValue.num;
fixExif = true;
}
if ( fixExif ) exif->SetTag_Rational ( kTIFF_GPSInfoIFD, kTIFF_GPSAltitude, altValue.num, altValue.denom );
}
ExportTIFF_LocTextASCII ( *xmp, kXMP_NS_DC, "description",
exif, kTIFF_PrimaryIFD, kTIFF_ImageDescription );
ExportTIFF_EncodedString ( *xmp, kXMP_NS_EXIF, "UserComment",
exif, kTIFF_ExifIFD, kTIFF_UserComment, true /* isLangAlt */ );
if ( exif->GetTag ( kTIFF_ExifIFD, kTIFF_DateTimeDigitized, 0 ) ) {
ExportTIFF_Date ( *xmp, kXMP_NS_XMP, "CreateDate", exif, kTIFF_DateTimeDigitized );
}
ExportTIFF_Date ( *xmp, kXMP_NS_EXIF, "DateTimeOriginal", exif, kTIFF_DateTimeOriginal );
ExportTIFF_Date ( *xmp, kXMP_NS_XMP, "ModifyDate", exif, kTIFF_DateTime );
ExportTIFF_ArrayASCII ( *xmp, kXMP_NS_DC, "creator", exif, kTIFF_PrimaryIFD, kTIFF_Artist );
ExportTIFF_LocTextASCII ( *xmp, kXMP_NS_DC, "rights", exif, kTIFF_PrimaryIFD, kTIFF_Copyright );
haveXMP = xmp->GetProperty ( kXMP_NS_EXIF, "ExifVersion", &xmpValue, 0 );
if ( haveXMP && (xmpValue.size() == 4) && (! exif->GetTag ( kTIFF_ExifIFD, kTIFF_ExifVersion, 0 )) ) {
exif->SetTag ( kTIFF_ExifIFD, kTIFF_ExifVersion, kTIFF_UndefinedType, 4, xmpValue.data() );
}
ExportTIFF_PhotographicSensitivity ( xmp, exif );
haveXMP = xmp->DoesPropertyExist ( kXMP_NS_EXIF, "ComponentsConfiguration" );
if ( haveXMP && (xmp->CountArrayItems ( kXMP_NS_EXIF, "ComponentsConfiguration" ) == 4) &&
(! exif->GetTag ( kTIFF_ExifIFD, kTIFF_ComponentsConfiguration, 0 )) ) {
XMP_Uns8 compConfig[4];
xmp->GetProperty_Int ( kXMP_NS_EXIF, "ComponentsConfiguration[1]", &int32, 0 );
compConfig[0] = (XMP_Uns8)int32;
xmp->GetProperty_Int ( kXMP_NS_EXIF, "ComponentsConfiguration[2]", &int32, 0 );
compConfig[1] = (XMP_Uns8)int32;
xmp->GetProperty_Int ( kXMP_NS_EXIF, "ComponentsConfiguration[3]", &int32, 0 );
compConfig[2] = (XMP_Uns8)int32;
xmp->GetProperty_Int ( kXMP_NS_EXIF, "ComponentsConfiguration[4]", &int32, 0 );
compConfig[3] = (XMP_Uns8)int32;
exif->SetTag ( kTIFF_ExifIFD, kTIFF_ComponentsConfiguration, kTIFF_UndefinedType, 4, &compConfig[0] );
}
haveXMP = xmp->DoesPropertyExist ( kXMP_NS_EXIF, "Flash" );
if ( haveXMP && (! exif->GetTag ( kTIFF_ExifIFD, kTIFF_Flash, 0 )) ) {
XMP_Uns16 binFlash = 0;
bool field;
haveXMP = xmp->GetProperty_Bool ( kXMP_NS_EXIF, "Flash/exif:Fired", &field, 0 );
if ( haveXMP & field ) binFlash |= 0x0001;
haveXMP = xmp->GetProperty_Int ( kXMP_NS_EXIF, "Flash/exif:Return", &int32, 0 );
if ( haveXMP ) binFlash |= (int32 & 3) << 1;
haveXMP = xmp->GetProperty_Int ( kXMP_NS_EXIF, "Flash/exif:Mode", &int32, 0 );
if ( haveXMP ) binFlash |= (int32 & 3) << 3;
haveXMP = xmp->GetProperty_Bool ( kXMP_NS_EXIF, "Flash/exif:Function", &field, 0 );
if ( haveXMP & field ) binFlash |= 0x0020;
haveXMP = xmp->GetProperty_Bool ( kXMP_NS_EXIF, "Flash/exif:RedEyeMode", &field, 0 );
if ( haveXMP & field ) binFlash |= 0x0040;
exif->SetTag_Short ( kTIFF_ExifIFD, kTIFF_Flash, binFlash );
}
haveXMP = xmp->GetProperty_Int ( kXMP_NS_EXIF, "FileSource", &int32, 0 );
if ( haveXMP && (! exif->GetTag ( kTIFF_ExifIFD, kTIFF_FileSource, 0 )) ) {
uns8 = (XMP_Uns8)int32;
exif->SetTag ( kTIFF_ExifIFD, kTIFF_FileSource, kTIFF_UndefinedType, 1, &uns8 );
}
haveXMP = xmp->GetProperty_Int ( kXMP_NS_EXIF, "SceneType", &int32, 0 );
if ( haveXMP && (! exif->GetTag ( kTIFF_ExifIFD, kTIFF_SceneType, 0 )) ) {
uns8 = (XMP_Uns8)int32;
exif->SetTag ( kTIFF_ExifIFD, kTIFF_SceneType, kTIFF_UndefinedType, 1, &uns8 );
}
haveXMP = xmp->GetProperty ( kXMP_NS_EXIF, "GPSVersionID", &xmpValue, 0 ); // This is inject-only.
if ( haveXMP && (! exif->GetTag ( kTIFF_GPSInfoIFD, kTIFF_GPSVersionID, 0 )) ) {
XMP_Uns8 gpsID[4]; // 0 GPSVersionID is 4 UInt8 bytes and mapped in XMP as "n.n.n.n".
unsigned int fields[4]; // ! Need ints for output from sscanf.
int count = sscanf ( xmpValue.c_str(), "%u.%u.%u.%u", &fields[0], &fields[1], &fields[2], &fields[3] );
if ( (count == 4) && (fields[0] <= 255) && (fields[1] <= 255) && (fields[2] <= 255) && (fields[3] <= 255) ) {
gpsID[0] = fields[0]; gpsID[1] = fields[1]; gpsID[2] = fields[2]; gpsID[3] = fields[3];
exif->SetTag ( kTIFF_GPSInfoIFD, kTIFF_GPSVersionID, kTIFF_ByteType, 4, &gpsID[0] );
}
}
ExportTIFF_GPSCoordinate ( *xmp, kXMP_NS_EXIF, "GPSLatitude", exif, kTIFF_GPSInfoIFD, kTIFF_GPSLatitude );
ExportTIFF_GPSCoordinate ( *xmp, kXMP_NS_EXIF, "GPSLongitude", exif, kTIFF_GPSInfoIFD, kTIFF_GPSLongitude );
ExportTIFF_GPSTimeStamp ( *xmp, kXMP_NS_EXIF, "GPSTimeStamp", exif );
haveXMP = xmp->DoesPropertyExist ( kXMP_NS_EXIF, "GPSDestLatitude" );
if ( haveXMP && (! exif->GetTag ( kTIFF_GPSInfoIFD, kTIFF_GPSDestLatitude, 0 )) ) {
ExportTIFF_GPSCoordinate ( *xmp, kXMP_NS_EXIF, "GPSDestLatitude", exif, kTIFF_GPSInfoIFD, kTIFF_GPSDestLatitude );
}
haveXMP = xmp->DoesPropertyExist ( kXMP_NS_EXIF, "GPSDestLongitude" );
if ( haveXMP && (! exif->GetTag ( kTIFF_GPSInfoIFD, kTIFF_GPSDestLongitude, 0 )) ) {
ExportTIFF_GPSCoordinate ( *xmp, kXMP_NS_EXIF, "GPSDestLongitude", exif, kTIFF_GPSInfoIFD, kTIFF_GPSDestLongitude );
}
haveXMP = xmp->GetProperty ( kXMP_NS_EXIF, "GPSProcessingMethod", &xmpValue, 0 );
if ( haveXMP && (! xmpValue.empty()) && (! exif->GetTag ( kTIFF_GPSInfoIFD, kTIFF_GPSProcessingMethod, 0 )) ) {
ExportTIFF_EncodedString ( *xmp, kXMP_NS_EXIF, "GPSProcessingMethod", exif, kTIFF_GPSInfoIFD, kTIFF_GPSProcessingMethod );
}
haveXMP = xmp->GetProperty ( kXMP_NS_EXIF, "GPSAreaInformation", &xmpValue, 0 );
if ( haveXMP && (! xmpValue.empty()) && (! exif->GetTag ( kTIFF_GPSInfoIFD, kTIFF_GPSAreaInformation, 0 )) ) {
ExportTIFF_EncodedString ( *xmp, kXMP_NS_EXIF, "GPSAreaInformation", exif, kTIFF_GPSInfoIFD, kTIFF_GPSAreaInformation );
}
} // PhotoDataUtils::ExportExif
| DoS | 0 | PhotoDataUtils::ExportExif ( SXMPMeta * xmp, TIFF_Manager * exif )
{
bool haveXMP;
std::string xmpValue;
XMP_Int32 int32;
XMP_Uns8 uns8;
#if SupportOldExifProperties
XMP_OptionBits flags;
haveXMP = xmp->DoesPropertyExist ( kXMP_NS_ExifEX, "PhotographicSensitivity" );
if ( ! haveXMP ) {
haveXMP = xmp->GetProperty ( kXMP_NS_EXIF, "ISOSpeedRatings", 0, &flags );
if ( haveXMP && XMP_PropIsArray(flags) ) {
haveXMP = xmp->GetArrayItem ( kXMP_NS_EXIF, "ISOSpeedRatings", 1, &xmpValue, 0 );
if ( haveXMP ) xmp->SetProperty ( kXMP_NS_ExifEX, "PhotographicSensitivity", xmpValue.c_str() );
}
}
haveXMP = xmp->DoesPropertyExist ( kXMP_NS_ExifEX, "CameraOwnerName" );
if ( ! haveXMP ) {
haveXMP = xmp->GetProperty ( kXMP_NS_EXIF_Aux, "OwnerName", &xmpValue, 0 );
if ( haveXMP ) xmp->SetProperty ( kXMP_NS_ExifEX, "CameraOwnerName", xmpValue.c_str() );
}
haveXMP = xmp->DoesPropertyExist ( kXMP_NS_ExifEX, "BodySerialNumber" );
if ( ! haveXMP ) {
haveXMP = xmp->GetProperty ( kXMP_NS_EXIF_Aux, "SerialNumber", &xmpValue, 0 );
if ( haveXMP ) xmp->SetProperty ( kXMP_NS_ExifEX, "BodySerialNumber", xmpValue.c_str() );
}
haveXMP = xmp->DoesPropertyExist ( kXMP_NS_ExifEX, "LensModel" );
if ( ! haveXMP ) {
haveXMP = xmp->GetProperty ( kXMP_NS_EXIF_Aux, "Lens", &xmpValue, 0 );
if ( haveXMP ) xmp->SetProperty ( kXMP_NS_ExifEX, "LensModel", xmpValue.c_str() );
}
haveXMP = xmp->DoesPropertyExist ( kXMP_NS_ExifEX, "LensSpecification" );
if ( ! haveXMP ) {
haveXMP = xmp->GetProperty ( kXMP_NS_EXIF_Aux, "LensInfo", &xmpValue, 0 );
if ( haveXMP ) {
size_t start, end;
std::string nextItem;
for ( start = 0; start < xmpValue.size(); start = end + 1 ) {
end = xmpValue.find ( ' ', start );
if ( end == start ) continue;
if ( end == std::string::npos ) end = xmpValue.size();
nextItem = xmpValue.substr ( start, (end-start) );
xmp->AppendArrayItem ( kXMP_NS_ExifEX, "LensSpecification", kXMP_PropArrayIsOrdered, nextItem.c_str() );
}
}
}
#endif
ExportTIFF_StandardMappings ( kTIFF_PrimaryIFD, exif, *xmp );
ExportTIFF_StandardMappings ( kTIFF_ExifIFD, exif, *xmp );
ExportTIFF_StandardMappings ( kTIFF_GPSInfoIFD, exif, *xmp );
TIFF_Manager::Rational altValue;
bool haveExif = exif->GetTag_Rational ( kTIFF_GPSInfoIFD, kTIFF_GPSAltitude, &altValue );
if ( haveExif ) {
bool fixExif = false;
if ( altValue.denom >> 31 ) { // Shift the sign to the numerator.
altValue.denom = -altValue.denom;
altValue.num = -altValue.num;
fixExif = true;
}
if ( altValue.num >> 31 ) { // Fix the numerator and set GPSAltitudeRef.
exif->SetTag_Byte ( kTIFF_GPSInfoIFD, kTIFF_GPSAltitudeRef, 1 );
altValue.num = -altValue.num;
fixExif = true;
}
if ( fixExif ) exif->SetTag_Rational ( kTIFF_GPSInfoIFD, kTIFF_GPSAltitude, altValue.num, altValue.denom );
}
ExportTIFF_LocTextASCII ( *xmp, kXMP_NS_DC, "description",
exif, kTIFF_PrimaryIFD, kTIFF_ImageDescription );
ExportTIFF_EncodedString ( *xmp, kXMP_NS_EXIF, "UserComment",
exif, kTIFF_ExifIFD, kTIFF_UserComment, true /* isLangAlt */ );
if ( exif->GetTag ( kTIFF_ExifIFD, kTIFF_DateTimeDigitized, 0 ) ) {
ExportTIFF_Date ( *xmp, kXMP_NS_XMP, "CreateDate", exif, kTIFF_DateTimeDigitized );
}
ExportTIFF_Date ( *xmp, kXMP_NS_EXIF, "DateTimeOriginal", exif, kTIFF_DateTimeOriginal );
ExportTIFF_Date ( *xmp, kXMP_NS_XMP, "ModifyDate", exif, kTIFF_DateTime );
ExportTIFF_ArrayASCII ( *xmp, kXMP_NS_DC, "creator", exif, kTIFF_PrimaryIFD, kTIFF_Artist );
ExportTIFF_LocTextASCII ( *xmp, kXMP_NS_DC, "rights", exif, kTIFF_PrimaryIFD, kTIFF_Copyright );
haveXMP = xmp->GetProperty ( kXMP_NS_EXIF, "ExifVersion", &xmpValue, 0 );
if ( haveXMP && (xmpValue.size() == 4) && (! exif->GetTag ( kTIFF_ExifIFD, kTIFF_ExifVersion, 0 )) ) {
exif->SetTag ( kTIFF_ExifIFD, kTIFF_ExifVersion, kTIFF_UndefinedType, 4, xmpValue.data() );
}
ExportTIFF_PhotographicSensitivity ( xmp, exif );
haveXMP = xmp->DoesPropertyExist ( kXMP_NS_EXIF, "ComponentsConfiguration" );
if ( haveXMP && (xmp->CountArrayItems ( kXMP_NS_EXIF, "ComponentsConfiguration" ) == 4) &&
(! exif->GetTag ( kTIFF_ExifIFD, kTIFF_ComponentsConfiguration, 0 )) ) {
XMP_Uns8 compConfig[4];
xmp->GetProperty_Int ( kXMP_NS_EXIF, "ComponentsConfiguration[1]", &int32, 0 );
compConfig[0] = (XMP_Uns8)int32;
xmp->GetProperty_Int ( kXMP_NS_EXIF, "ComponentsConfiguration[2]", &int32, 0 );
compConfig[1] = (XMP_Uns8)int32;
xmp->GetProperty_Int ( kXMP_NS_EXIF, "ComponentsConfiguration[3]", &int32, 0 );
compConfig[2] = (XMP_Uns8)int32;
xmp->GetProperty_Int ( kXMP_NS_EXIF, "ComponentsConfiguration[4]", &int32, 0 );
compConfig[3] = (XMP_Uns8)int32;
exif->SetTag ( kTIFF_ExifIFD, kTIFF_ComponentsConfiguration, kTIFF_UndefinedType, 4, &compConfig[0] );
}
haveXMP = xmp->DoesPropertyExist ( kXMP_NS_EXIF, "Flash" );
if ( haveXMP && (! exif->GetTag ( kTIFF_ExifIFD, kTIFF_Flash, 0 )) ) {
XMP_Uns16 binFlash = 0;
bool field;
haveXMP = xmp->GetProperty_Bool ( kXMP_NS_EXIF, "Flash/exif:Fired", &field, 0 );
if ( haveXMP & field ) binFlash |= 0x0001;
haveXMP = xmp->GetProperty_Int ( kXMP_NS_EXIF, "Flash/exif:Return", &int32, 0 );
if ( haveXMP ) binFlash |= (int32 & 3) << 1;
haveXMP = xmp->GetProperty_Int ( kXMP_NS_EXIF, "Flash/exif:Mode", &int32, 0 );
if ( haveXMP ) binFlash |= (int32 & 3) << 3;
haveXMP = xmp->GetProperty_Bool ( kXMP_NS_EXIF, "Flash/exif:Function", &field, 0 );
if ( haveXMP & field ) binFlash |= 0x0020;
haveXMP = xmp->GetProperty_Bool ( kXMP_NS_EXIF, "Flash/exif:RedEyeMode", &field, 0 );
if ( haveXMP & field ) binFlash |= 0x0040;
exif->SetTag_Short ( kTIFF_ExifIFD, kTIFF_Flash, binFlash );
}
haveXMP = xmp->GetProperty_Int ( kXMP_NS_EXIF, "FileSource", &int32, 0 );
if ( haveXMP && (! exif->GetTag ( kTIFF_ExifIFD, kTIFF_FileSource, 0 )) ) {
uns8 = (XMP_Uns8)int32;
exif->SetTag ( kTIFF_ExifIFD, kTIFF_FileSource, kTIFF_UndefinedType, 1, &uns8 );
}
haveXMP = xmp->GetProperty_Int ( kXMP_NS_EXIF, "SceneType", &int32, 0 );
if ( haveXMP && (! exif->GetTag ( kTIFF_ExifIFD, kTIFF_SceneType, 0 )) ) {
uns8 = (XMP_Uns8)int32;
exif->SetTag ( kTIFF_ExifIFD, kTIFF_SceneType, kTIFF_UndefinedType, 1, &uns8 );
}
haveXMP = xmp->GetProperty ( kXMP_NS_EXIF, "GPSVersionID", &xmpValue, 0 ); // This is inject-only.
if ( haveXMP && (! exif->GetTag ( kTIFF_GPSInfoIFD, kTIFF_GPSVersionID, 0 )) ) {
XMP_Uns8 gpsID[4]; // 0 GPSVersionID is 4 UInt8 bytes and mapped in XMP as "n.n.n.n".
unsigned int fields[4]; // ! Need ints for output from sscanf.
int count = sscanf ( xmpValue.c_str(), "%u.%u.%u.%u", &fields[0], &fields[1], &fields[2], &fields[3] );
if ( (count == 4) && (fields[0] <= 255) && (fields[1] <= 255) && (fields[2] <= 255) && (fields[3] <= 255) ) {
gpsID[0] = fields[0]; gpsID[1] = fields[1]; gpsID[2] = fields[2]; gpsID[3] = fields[3];
exif->SetTag ( kTIFF_GPSInfoIFD, kTIFF_GPSVersionID, kTIFF_ByteType, 4, &gpsID[0] );
}
}
ExportTIFF_GPSCoordinate ( *xmp, kXMP_NS_EXIF, "GPSLatitude", exif, kTIFF_GPSInfoIFD, kTIFF_GPSLatitude );
ExportTIFF_GPSCoordinate ( *xmp, kXMP_NS_EXIF, "GPSLongitude", exif, kTIFF_GPSInfoIFD, kTIFF_GPSLongitude );
ExportTIFF_GPSTimeStamp ( *xmp, kXMP_NS_EXIF, "GPSTimeStamp", exif );
haveXMP = xmp->DoesPropertyExist ( kXMP_NS_EXIF, "GPSDestLatitude" );
if ( haveXMP && (! exif->GetTag ( kTIFF_GPSInfoIFD, kTIFF_GPSDestLatitude, 0 )) ) {
ExportTIFF_GPSCoordinate ( *xmp, kXMP_NS_EXIF, "GPSDestLatitude", exif, kTIFF_GPSInfoIFD, kTIFF_GPSDestLatitude );
}
haveXMP = xmp->DoesPropertyExist ( kXMP_NS_EXIF, "GPSDestLongitude" );
if ( haveXMP && (! exif->GetTag ( kTIFF_GPSInfoIFD, kTIFF_GPSDestLongitude, 0 )) ) {
ExportTIFF_GPSCoordinate ( *xmp, kXMP_NS_EXIF, "GPSDestLongitude", exif, kTIFF_GPSInfoIFD, kTIFF_GPSDestLongitude );
}
haveXMP = xmp->GetProperty ( kXMP_NS_EXIF, "GPSProcessingMethod", &xmpValue, 0 );
if ( haveXMP && (! xmpValue.empty()) && (! exif->GetTag ( kTIFF_GPSInfoIFD, kTIFF_GPSProcessingMethod, 0 )) ) {
ExportTIFF_EncodedString ( *xmp, kXMP_NS_EXIF, "GPSProcessingMethod", exif, kTIFF_GPSInfoIFD, kTIFF_GPSProcessingMethod );
}
haveXMP = xmp->GetProperty ( kXMP_NS_EXIF, "GPSAreaInformation", &xmpValue, 0 );
if ( haveXMP && (! xmpValue.empty()) && (! exif->GetTag ( kTIFF_GPSInfoIFD, kTIFF_GPSAreaInformation, 0 )) ) {
ExportTIFF_EncodedString ( *xmp, kXMP_NS_EXIF, "GPSAreaInformation", exif, kTIFF_GPSInfoIFD, kTIFF_GPSAreaInformation );
}
} // PhotoDataUtils::ExportExif
| @@ -233,7 +233,7 @@ static XMP_Uns32 GatherInt ( const char * strPtr, size_t count )
static size_t TrimTrailingSpaces ( char * firstChar, size_t origLen )
{
- if ( origLen == 0 ) return 0;
+ if ( !firstChar || origLen == 0 ) return 0;
char * lastChar = firstChar + origLen - 1;
if ( (*lastChar != ' ') && (*lastChar != 0) ) return origLen; // Nothing to do. | CWE-416 | null | null |
12,795 | ExportSingleTIFF ( TIFF_Manager * tiff, XMP_Uns8 ifd, const TIFF_MappingToXMP & mapInfo,
bool nativeEndian, const std::string & xmpValue )
{
XMP_Assert ( (mapInfo.count == 1) || (mapInfo.type == kTIFF_ASCIIType) );
XMP_Assert ( mapInfo.name[0] != 0 ); // Must be a standard mapping.
bool ok;
char nextChar; // Used to make sure sscanf consumes all of the string.
switch ( mapInfo.type ) {
case kTIFF_ByteType : {
unsigned short binValue;
int items = sscanf ( xmpValue.c_str(), "%hu%c", &binValue, &nextChar ); // AUDIT: Using xmpValue.c_str() is safe.
if ( items != 1 ) return; // ? complain? notify client?
tiff->SetTag_Byte ( ifd, mapInfo.id, (XMP_Uns8)binValue );
break;
}
case kTIFF_ShortType : {
unsigned long binValue;
int items = sscanf ( xmpValue.c_str(), "%lu%c", &binValue, &nextChar ); // AUDIT: Using xmpValue.c_str() is safe.
if ( items != 1 ) return; // ? complain? notify client?
tiff->SetTag_Short ( ifd, mapInfo.id, (XMP_Uns16)binValue );
break;
}
case kTIFF_LongType : {
unsigned long binValue;
int items = sscanf ( xmpValue.c_str(), "%lu%c", &binValue, &nextChar ); // AUDIT: Using xmpValue.c_str() is safe.
if ( items != 1 ) return; // ? complain? notify client?
tiff->SetTag_Long ( ifd, mapInfo.id, (XMP_Uns32)binValue );
break;
}
case kTIFF_ShortOrLongType : {
unsigned long binValue;
int items = sscanf ( xmpValue.c_str(), "%lu%c", &binValue, &nextChar ); // AUDIT: Using xmpValue.c_str() is safe.
if ( items != 1 ) return; // ? complain? notify client?
if ( binValue <= 0xFFFF ) {
tiff->SetTag_Short ( ifd, mapInfo.id, (XMP_Uns16)binValue );
} else {
tiff->SetTag_Long ( ifd, mapInfo.id, (XMP_Uns32)binValue );
}
break;
}
case kTIFF_RationalType : { // The XMP is formatted as "num/denom".
XMP_Uns32 num, denom;
ok = DecodeRational ( xmpValue.c_str(), &num, &denom );
if ( ! ok ) return; // ? complain? notify client?
tiff->SetTag_Rational ( ifd, mapInfo.id, num, denom );
break;
}
case kTIFF_SRationalType : { // The XMP is formatted as "num/denom".
signed long num, denom;
int items = sscanf ( xmpValue.c_str(), "%ld/%ld%c", &num, &denom, &nextChar ); // AUDIT: Using xmpValue.c_str() is safe.
if ( items != 2 ) {
if ( items != 1 ) return; // ? complain? notify client?
denom = 1; // The XMP was just an integer, assume a denominator of 1.
}
tiff->SetTag_SRational ( ifd, mapInfo.id, (XMP_Int32)num, (XMP_Int32)denom );
break;
}
case kTIFF_ASCIIType :
tiff->SetTag ( ifd, mapInfo.id, kTIFF_ASCIIType, (XMP_Uns32)(xmpValue.size()+1), xmpValue.c_str() );
break;
default:
XMP_Assert ( false ); // Force a debug assert for unexpected types.
}
} // ExportSingleTIFF
| DoS | 0 | ExportSingleTIFF ( TIFF_Manager * tiff, XMP_Uns8 ifd, const TIFF_MappingToXMP & mapInfo,
bool nativeEndian, const std::string & xmpValue )
{
XMP_Assert ( (mapInfo.count == 1) || (mapInfo.type == kTIFF_ASCIIType) );
XMP_Assert ( mapInfo.name[0] != 0 ); // Must be a standard mapping.
bool ok;
char nextChar; // Used to make sure sscanf consumes all of the string.
switch ( mapInfo.type ) {
case kTIFF_ByteType : {
unsigned short binValue;
int items = sscanf ( xmpValue.c_str(), "%hu%c", &binValue, &nextChar ); // AUDIT: Using xmpValue.c_str() is safe.
if ( items != 1 ) return; // ? complain? notify client?
tiff->SetTag_Byte ( ifd, mapInfo.id, (XMP_Uns8)binValue );
break;
}
case kTIFF_ShortType : {
unsigned long binValue;
int items = sscanf ( xmpValue.c_str(), "%lu%c", &binValue, &nextChar ); // AUDIT: Using xmpValue.c_str() is safe.
if ( items != 1 ) return; // ? complain? notify client?
tiff->SetTag_Short ( ifd, mapInfo.id, (XMP_Uns16)binValue );
break;
}
case kTIFF_LongType : {
unsigned long binValue;
int items = sscanf ( xmpValue.c_str(), "%lu%c", &binValue, &nextChar ); // AUDIT: Using xmpValue.c_str() is safe.
if ( items != 1 ) return; // ? complain? notify client?
tiff->SetTag_Long ( ifd, mapInfo.id, (XMP_Uns32)binValue );
break;
}
case kTIFF_ShortOrLongType : {
unsigned long binValue;
int items = sscanf ( xmpValue.c_str(), "%lu%c", &binValue, &nextChar ); // AUDIT: Using xmpValue.c_str() is safe.
if ( items != 1 ) return; // ? complain? notify client?
if ( binValue <= 0xFFFF ) {
tiff->SetTag_Short ( ifd, mapInfo.id, (XMP_Uns16)binValue );
} else {
tiff->SetTag_Long ( ifd, mapInfo.id, (XMP_Uns32)binValue );
}
break;
}
case kTIFF_RationalType : { // The XMP is formatted as "num/denom".
XMP_Uns32 num, denom;
ok = DecodeRational ( xmpValue.c_str(), &num, &denom );
if ( ! ok ) return; // ? complain? notify client?
tiff->SetTag_Rational ( ifd, mapInfo.id, num, denom );
break;
}
case kTIFF_SRationalType : { // The XMP is formatted as "num/denom".
signed long num, denom;
int items = sscanf ( xmpValue.c_str(), "%ld/%ld%c", &num, &denom, &nextChar ); // AUDIT: Using xmpValue.c_str() is safe.
if ( items != 2 ) {
if ( items != 1 ) return; // ? complain? notify client?
denom = 1; // The XMP was just an integer, assume a denominator of 1.
}
tiff->SetTag_SRational ( ifd, mapInfo.id, (XMP_Int32)num, (XMP_Int32)denom );
break;
}
case kTIFF_ASCIIType :
tiff->SetTag ( ifd, mapInfo.id, kTIFF_ASCIIType, (XMP_Uns32)(xmpValue.size()+1), xmpValue.c_str() );
break;
default:
XMP_Assert ( false ); // Force a debug assert for unexpected types.
}
} // ExportSingleTIFF
| @@ -233,7 +233,7 @@ static XMP_Uns32 GatherInt ( const char * strPtr, size_t count )
static size_t TrimTrailingSpaces ( char * firstChar, size_t origLen )
{
- if ( origLen == 0 ) return 0;
+ if ( !firstChar || origLen == 0 ) return 0;
char * lastChar = firstChar + origLen - 1;
if ( (*lastChar != ' ') && (*lastChar != 0) ) return origLen; // Nothing to do. | CWE-416 | null | null |
12,796 | ExportTIFF_Date ( const SXMPMeta & xmp, const char * xmpNS, const char * xmpProp, TIFF_Manager * tiff, XMP_Uns16 mainID )
{
XMP_Uns8 mainIFD = kTIFF_ExifIFD;
XMP_Uns16 fracID=0;
switch ( mainID ) {
case kTIFF_DateTime : mainIFD = kTIFF_PrimaryIFD; fracID = kTIFF_SubSecTime; break;
case kTIFF_DateTimeOriginal : fracID = kTIFF_SubSecTimeOriginal; break;
case kTIFF_DateTimeDigitized : fracID = kTIFF_SubSecTimeDigitized; break;
}
try { // Don't let errors with one stop the others.
std::string xmpStr;
bool foundXMP = xmp.GetProperty ( xmpNS, xmpProp, &xmpStr, 0 );
if ( ! foundXMP ) {
tiff->DeleteTag ( mainIFD, mainID );
tiff->DeleteTag ( kTIFF_ExifIFD, fracID ); // ! The subseconds are always in the Exif IFD.
return;
}
XMP_DateTime xmpBin;
SXMPUtils::ConvertToDate ( xmpStr.c_str(), &xmpBin );
char buffer[24];
snprintf ( buffer, sizeof(buffer), "%04d:%02d:%02d %02d:%02d:%02d", // AUDIT: Use of sizeof(buffer) is safe.
xmpBin.year, xmpBin.month, xmpBin.day, xmpBin.hour, xmpBin.minute, xmpBin.second );
size_t xmpLen = xmpStr.size();
if ( xmpLen < 18 ) {
buffer[17] = buffer[18] = ' ';
if ( xmpLen < 15 ) {
buffer[14] = buffer[15] = ' ';
if ( xmpLen < 12 ) {
buffer[11] = buffer[12] = ' ';
if ( xmpLen < 9 ) {
buffer[8] = buffer[9] = ' ';
if ( xmpLen < 6 ) {
buffer[5] = buffer[6] = ' ';
if ( xmpLen < 1 ) {
buffer[0] = buffer[1] = buffer[2] = buffer[3] = ' ';
}
}
}
}
}
}
tiff->SetTag_ASCII ( mainIFD, mainID, buffer );
if ( xmpBin.nanoSecond == 0 ) {
tiff->DeleteTag ( kTIFF_ExifIFD, fracID );
} else {
snprintf ( buffer, sizeof(buffer), "%09d", xmpBin.nanoSecond ); // AUDIT: Use of sizeof(buffer) is safe.
for ( size_t i = strlen(buffer)-1; i > 0; --i ) {
if ( buffer[i] != '0' ) break;
buffer[i] = 0; // Strip trailing zero digits.
}
tiff->SetTag_ASCII ( kTIFF_ExifIFD, fracID, buffer ); // ! The subseconds are always in the Exif IFD.
}
} catch ( ... ) {
}
} // ExportTIFF_Date
| DoS | 0 | ExportTIFF_Date ( const SXMPMeta & xmp, const char * xmpNS, const char * xmpProp, TIFF_Manager * tiff, XMP_Uns16 mainID )
{
XMP_Uns8 mainIFD = kTIFF_ExifIFD;
XMP_Uns16 fracID=0;
switch ( mainID ) {
case kTIFF_DateTime : mainIFD = kTIFF_PrimaryIFD; fracID = kTIFF_SubSecTime; break;
case kTIFF_DateTimeOriginal : fracID = kTIFF_SubSecTimeOriginal; break;
case kTIFF_DateTimeDigitized : fracID = kTIFF_SubSecTimeDigitized; break;
}
try { // Don't let errors with one stop the others.
std::string xmpStr;
bool foundXMP = xmp.GetProperty ( xmpNS, xmpProp, &xmpStr, 0 );
if ( ! foundXMP ) {
tiff->DeleteTag ( mainIFD, mainID );
tiff->DeleteTag ( kTIFF_ExifIFD, fracID ); // ! The subseconds are always in the Exif IFD.
return;
}
XMP_DateTime xmpBin;
SXMPUtils::ConvertToDate ( xmpStr.c_str(), &xmpBin );
char buffer[24];
snprintf ( buffer, sizeof(buffer), "%04d:%02d:%02d %02d:%02d:%02d", // AUDIT: Use of sizeof(buffer) is safe.
xmpBin.year, xmpBin.month, xmpBin.day, xmpBin.hour, xmpBin.minute, xmpBin.second );
size_t xmpLen = xmpStr.size();
if ( xmpLen < 18 ) {
buffer[17] = buffer[18] = ' ';
if ( xmpLen < 15 ) {
buffer[14] = buffer[15] = ' ';
if ( xmpLen < 12 ) {
buffer[11] = buffer[12] = ' ';
if ( xmpLen < 9 ) {
buffer[8] = buffer[9] = ' ';
if ( xmpLen < 6 ) {
buffer[5] = buffer[6] = ' ';
if ( xmpLen < 1 ) {
buffer[0] = buffer[1] = buffer[2] = buffer[3] = ' ';
}
}
}
}
}
}
tiff->SetTag_ASCII ( mainIFD, mainID, buffer );
if ( xmpBin.nanoSecond == 0 ) {
tiff->DeleteTag ( kTIFF_ExifIFD, fracID );
} else {
snprintf ( buffer, sizeof(buffer), "%09d", xmpBin.nanoSecond ); // AUDIT: Use of sizeof(buffer) is safe.
for ( size_t i = strlen(buffer)-1; i > 0; --i ) {
if ( buffer[i] != '0' ) break;
buffer[i] = 0; // Strip trailing zero digits.
}
tiff->SetTag_ASCII ( kTIFF_ExifIFD, fracID, buffer ); // ! The subseconds are always in the Exif IFD.
}
} catch ( ... ) {
}
} // ExportTIFF_Date
| @@ -233,7 +233,7 @@ static XMP_Uns32 GatherInt ( const char * strPtr, size_t count )
static size_t TrimTrailingSpaces ( char * firstChar, size_t origLen )
{
- if ( origLen == 0 ) return 0;
+ if ( !firstChar || origLen == 0 ) return 0;
char * lastChar = firstChar + origLen - 1;
if ( (*lastChar != ' ') && (*lastChar != 0) ) return origLen; // Nothing to do. | CWE-416 | null | null |
12,797 | ExportTIFF_EncodedString ( const SXMPMeta & xmp, const char * xmpNS, const char * xmpProp,
TIFF_Manager * tiff, XMP_Uns8 ifd, XMP_Uns16 id, bool isLangAlt = false )
{
try { // Don't let errors with one stop the others.
std::string xmpValue;
XMP_OptionBits xmpFlags;
bool foundXMP = xmp.GetProperty ( xmpNS, xmpProp, &xmpValue, &xmpFlags );
if ( ! foundXMP ) {
tiff->DeleteTag ( ifd, id );
return;
}
if ( ! isLangAlt ) {
if ( ! XMP_PropIsSimple ( xmpFlags ) ) return; // ? Complain? Delete the tag?
} else {
if ( ! XMP_ArrayIsAltText ( xmpFlags ) ) return; // ? Complain? Delete the tag?
bool ok = xmp.GetLocalizedText ( xmpNS, xmpProp, "", "x-default", 0, &xmpValue, 0 );
if ( ! ok ) return; // ? Complain? Delete the tag?
}
XMP_Uns8 encoding = kTIFF_EncodeASCII;
for ( size_t i = 0; i < xmpValue.size(); ++i ) {
if ( (XMP_Uns8)xmpValue[i] >= 0x80 ) {
encoding = kTIFF_EncodeUnicode;
break;
}
}
tiff->SetTag_EncodedString ( ifd, id, xmpValue.c_str(), encoding );
} catch ( ... ) {
}
} // ExportTIFF_EncodedString
| DoS | 0 | ExportTIFF_EncodedString ( const SXMPMeta & xmp, const char * xmpNS, const char * xmpProp,
TIFF_Manager * tiff, XMP_Uns8 ifd, XMP_Uns16 id, bool isLangAlt = false )
{
try { // Don't let errors with one stop the others.
std::string xmpValue;
XMP_OptionBits xmpFlags;
bool foundXMP = xmp.GetProperty ( xmpNS, xmpProp, &xmpValue, &xmpFlags );
if ( ! foundXMP ) {
tiff->DeleteTag ( ifd, id );
return;
}
if ( ! isLangAlt ) {
if ( ! XMP_PropIsSimple ( xmpFlags ) ) return; // ? Complain? Delete the tag?
} else {
if ( ! XMP_ArrayIsAltText ( xmpFlags ) ) return; // ? Complain? Delete the tag?
bool ok = xmp.GetLocalizedText ( xmpNS, xmpProp, "", "x-default", 0, &xmpValue, 0 );
if ( ! ok ) return; // ? Complain? Delete the tag?
}
XMP_Uns8 encoding = kTIFF_EncodeASCII;
for ( size_t i = 0; i < xmpValue.size(); ++i ) {
if ( (XMP_Uns8)xmpValue[i] >= 0x80 ) {
encoding = kTIFF_EncodeUnicode;
break;
}
}
tiff->SetTag_EncodedString ( ifd, id, xmpValue.c_str(), encoding );
} catch ( ... ) {
}
} // ExportTIFF_EncodedString
| @@ -233,7 +233,7 @@ static XMP_Uns32 GatherInt ( const char * strPtr, size_t count )
static size_t TrimTrailingSpaces ( char * firstChar, size_t origLen )
{
- if ( origLen == 0 ) return 0;
+ if ( !firstChar || origLen == 0 ) return 0;
char * lastChar = firstChar + origLen - 1;
if ( (*lastChar != ' ') && (*lastChar != 0) ) return origLen; // Nothing to do. | CWE-416 | null | null |
12,798 | ExportTIFF_GPSCoordinate ( const SXMPMeta & xmp, const char * xmpNS, const char * xmpProp,
TIFF_Manager * tiff, XMP_Uns8 ifd, XMP_Uns16 _id )
{
XMP_Uns16 refID = _id-1; // ! The GPS refs and locations are all tag N-1 and N pairs.
XMP_Uns16 locID = _id;
XMP_Assert ( (locID & 1) == 0 );
try { // Don't let errors with one stop the others. Tolerate ill-formed values where reasonable.
std::string xmpValue;
XMP_OptionBits xmpFlags;
bool foundXMP = xmp.GetProperty ( xmpNS, xmpProp, &xmpValue, &xmpFlags );
if ( ! foundXMP ) {
tiff->DeleteTag ( ifd, refID );
tiff->DeleteTag ( ifd, locID );
return;
}
if ( ! XMP_PropIsSimple ( xmpFlags ) ) return;
const char * chPtr = xmpValue.c_str(); // Guaranteed to have a nul terminator.
XMP_Uns32 deg=0, minNum=0, minDenom=1, sec=0;
while ( (*chPtr == ' ') || (*chPtr == '\t') ) ++chPtr;
if ( (*chPtr < '0') || (*chPtr > '9') ) return; // Bad XMP string.
for ( ; ('0' <= *chPtr) && (*chPtr <= '9'); ++chPtr ) deg = deg*10 + (*chPtr - '0');
while ( (*chPtr == ' ') || (*chPtr == '\t') ) ++chPtr;
if ( (*chPtr == ',') || (*chPtr == ';') ) ++chPtr;
while ( (*chPtr == ' ') || (*chPtr == '\t') ) ++chPtr;
if ( ('0' <= *chPtr) && (*chPtr <= '9') ) {
for ( ; ('0' <= *chPtr) && (*chPtr <= '9'); ++chPtr ) minNum = minNum*10 + (*chPtr - '0');
if ( *chPtr == '.' ) {
++chPtr; // Skip the period.
for ( ; ('0' <= *chPtr) && (*chPtr <= '9'); ++chPtr ) {
if ( minDenom > 100*1000 ) continue; // Don't accumulate any more digits.
minDenom *= 10;
minNum = minNum*10 + (*chPtr - '0');
}
} else {
while ( (*chPtr == ' ') || (*chPtr == '\t') ) ++chPtr;
if ( (*chPtr == ',') || (*chPtr == ';') ) ++chPtr;
while ( (*chPtr == ' ') || (*chPtr == '\t') ) ++chPtr;
for ( ; ('0' <= *chPtr) && (*chPtr <= '9'); ++chPtr ) sec = sec*10 + (*chPtr - '0');
}
}
while ( (*chPtr == ' ') || (*chPtr == '\t') ) ++chPtr;
if ( (*chPtr == ',') || (*chPtr == ';') ) ++chPtr; // Tolerate ',' or ';' here also.
while ( (*chPtr == ' ') || (*chPtr == '\t') ) ++chPtr;
char ref[2];
ref[0] = *chPtr;
ref[1] = 0;
if ( ('a' <= ref[0]) && (ref[0] <= 'z') ) ref[0] -= 0x20;
if ( (ref[0] != 'N') && (ref[0] != 'S') && (ref[0] != 'E') && (ref[0] != 'W') ) return;
tiff->SetTag ( ifd, refID, kTIFF_ASCIIType, 2, &ref[0] );
XMP_Uns32 loc[6];
tiff->PutUns32 ( deg, &loc[0] );
tiff->PutUns32 ( 1, &loc[1] );
tiff->PutUns32 ( minNum, &loc[2] );
tiff->PutUns32 ( minDenom, &loc[3] );
tiff->PutUns32 ( sec, &loc[4] );
tiff->PutUns32 ( 1, &loc[5] );
tiff->SetTag ( ifd, locID, kTIFF_RationalType, 3, &loc[0] );
} catch ( ... ) {
}
} // ExportTIFF_GPSCoordinate
| DoS | 0 | ExportTIFF_GPSCoordinate ( const SXMPMeta & xmp, const char * xmpNS, const char * xmpProp,
TIFF_Manager * tiff, XMP_Uns8 ifd, XMP_Uns16 _id )
{
XMP_Uns16 refID = _id-1; // ! The GPS refs and locations are all tag N-1 and N pairs.
XMP_Uns16 locID = _id;
XMP_Assert ( (locID & 1) == 0 );
try { // Don't let errors with one stop the others. Tolerate ill-formed values where reasonable.
std::string xmpValue;
XMP_OptionBits xmpFlags;
bool foundXMP = xmp.GetProperty ( xmpNS, xmpProp, &xmpValue, &xmpFlags );
if ( ! foundXMP ) {
tiff->DeleteTag ( ifd, refID );
tiff->DeleteTag ( ifd, locID );
return;
}
if ( ! XMP_PropIsSimple ( xmpFlags ) ) return;
const char * chPtr = xmpValue.c_str(); // Guaranteed to have a nul terminator.
XMP_Uns32 deg=0, minNum=0, minDenom=1, sec=0;
while ( (*chPtr == ' ') || (*chPtr == '\t') ) ++chPtr;
if ( (*chPtr < '0') || (*chPtr > '9') ) return; // Bad XMP string.
for ( ; ('0' <= *chPtr) && (*chPtr <= '9'); ++chPtr ) deg = deg*10 + (*chPtr - '0');
while ( (*chPtr == ' ') || (*chPtr == '\t') ) ++chPtr;
if ( (*chPtr == ',') || (*chPtr == ';') ) ++chPtr;
while ( (*chPtr == ' ') || (*chPtr == '\t') ) ++chPtr;
if ( ('0' <= *chPtr) && (*chPtr <= '9') ) {
for ( ; ('0' <= *chPtr) && (*chPtr <= '9'); ++chPtr ) minNum = minNum*10 + (*chPtr - '0');
if ( *chPtr == '.' ) {
++chPtr; // Skip the period.
for ( ; ('0' <= *chPtr) && (*chPtr <= '9'); ++chPtr ) {
if ( minDenom > 100*1000 ) continue; // Don't accumulate any more digits.
minDenom *= 10;
minNum = minNum*10 + (*chPtr - '0');
}
} else {
while ( (*chPtr == ' ') || (*chPtr == '\t') ) ++chPtr;
if ( (*chPtr == ',') || (*chPtr == ';') ) ++chPtr;
while ( (*chPtr == ' ') || (*chPtr == '\t') ) ++chPtr;
for ( ; ('0' <= *chPtr) && (*chPtr <= '9'); ++chPtr ) sec = sec*10 + (*chPtr - '0');
}
}
while ( (*chPtr == ' ') || (*chPtr == '\t') ) ++chPtr;
if ( (*chPtr == ',') || (*chPtr == ';') ) ++chPtr; // Tolerate ',' or ';' here also.
while ( (*chPtr == ' ') || (*chPtr == '\t') ) ++chPtr;
char ref[2];
ref[0] = *chPtr;
ref[1] = 0;
if ( ('a' <= ref[0]) && (ref[0] <= 'z') ) ref[0] -= 0x20;
if ( (ref[0] != 'N') && (ref[0] != 'S') && (ref[0] != 'E') && (ref[0] != 'W') ) return;
tiff->SetTag ( ifd, refID, kTIFF_ASCIIType, 2, &ref[0] );
XMP_Uns32 loc[6];
tiff->PutUns32 ( deg, &loc[0] );
tiff->PutUns32 ( 1, &loc[1] );
tiff->PutUns32 ( minNum, &loc[2] );
tiff->PutUns32 ( minDenom, &loc[3] );
tiff->PutUns32 ( sec, &loc[4] );
tiff->PutUns32 ( 1, &loc[5] );
tiff->SetTag ( ifd, locID, kTIFF_RationalType, 3, &loc[0] );
} catch ( ... ) {
}
} // ExportTIFF_GPSCoordinate
| @@ -233,7 +233,7 @@ static XMP_Uns32 GatherInt ( const char * strPtr, size_t count )
static size_t TrimTrailingSpaces ( char * firstChar, size_t origLen )
{
- if ( origLen == 0 ) return 0;
+ if ( !firstChar || origLen == 0 ) return 0;
char * lastChar = firstChar + origLen - 1;
if ( (*lastChar != ' ') && (*lastChar != 0) ) return origLen; // Nothing to do. | CWE-416 | null | null |
12,799 | ExportTIFF_GPSTimeStamp ( const SXMPMeta & xmp, const char * xmpNS, const char * xmpProp, TIFF_Manager * tiff )
{
try { // Don't let errors with one stop the others.
XMP_DateTime binXMP;
bool foundXMP = xmp.GetProperty_Date ( xmpNS, xmpProp, &binXMP, 0 );
if ( ! foundXMP ) {
tiff->DeleteTag ( kTIFF_GPSInfoIFD, kTIFF_GPSTimeStamp );
tiff->DeleteTag ( kTIFF_GPSInfoIFD, kTIFF_GPSDateStamp );
return;
}
SXMPUtils::ConvertToUTCTime ( &binXMP );
XMP_Uns32 exifTime[6];
tiff->PutUns32 ( binXMP.hour, &exifTime[0] );
tiff->PutUns32 ( 1, &exifTime[1] );
tiff->PutUns32 ( binXMP.minute, &exifTime[2] );
tiff->PutUns32 ( 1, &exifTime[3] );
if ( binXMP.nanoSecond == 0 ) {
tiff->PutUns32 ( binXMP.second, &exifTime[4] );
tiff->PutUns32 ( 1, &exifTime[5] );
} else {
double fSec = (double)binXMP.second + ((double)binXMP.nanoSecond / kBillion );
XMP_Uns32 denom = 1000*1000; // Choose microsecond resolution by default.
TIFF_Manager::TagInfo oldInfo;
bool hadExif = tiff->GetTag ( kTIFF_GPSInfoIFD, kTIFF_GPSTimeStamp, &oldInfo );
if ( hadExif && (oldInfo.type == kTIFF_RationalType) && (oldInfo.count == 3) ) {
XMP_Uns32 oldDenom = tiff->GetUns32 ( &(((XMP_Uns32*)oldInfo.dataPtr)[5]) );
if ( oldDenom != 1 ) denom = oldDenom;
}
fSec *= denom;
while ( fSec > mMaxSec ) { fSec /= 10; denom /= 10; }
tiff->PutUns32 ( (XMP_Uns32)fSec, &exifTime[4] );
tiff->PutUns32 ( denom, &exifTime[5] );
}
tiff->SetTag ( kTIFF_GPSInfoIFD, kTIFF_GPSTimeStamp, kTIFF_RationalType, 3, &exifTime[0] );
char exifDate[16]; // AUDIT: Long enough, only need 11.
snprintf ( exifDate, 12, "%04d:%02d:%02d", binXMP.year, binXMP.month, binXMP.day );
if ( exifDate[10] == 0 ) { // Make sure there is no value overflow.
tiff->SetTag ( kTIFF_GPSInfoIFD, kTIFF_GPSDateStamp, kTIFF_ASCIIType, 11, exifDate );
}
} catch ( ... ) {
}
} // ExportTIFF_GPSTimeStamp
| DoS | 0 | ExportTIFF_GPSTimeStamp ( const SXMPMeta & xmp, const char * xmpNS, const char * xmpProp, TIFF_Manager * tiff )
{
try { // Don't let errors with one stop the others.
XMP_DateTime binXMP;
bool foundXMP = xmp.GetProperty_Date ( xmpNS, xmpProp, &binXMP, 0 );
if ( ! foundXMP ) {
tiff->DeleteTag ( kTIFF_GPSInfoIFD, kTIFF_GPSTimeStamp );
tiff->DeleteTag ( kTIFF_GPSInfoIFD, kTIFF_GPSDateStamp );
return;
}
SXMPUtils::ConvertToUTCTime ( &binXMP );
XMP_Uns32 exifTime[6];
tiff->PutUns32 ( binXMP.hour, &exifTime[0] );
tiff->PutUns32 ( 1, &exifTime[1] );
tiff->PutUns32 ( binXMP.minute, &exifTime[2] );
tiff->PutUns32 ( 1, &exifTime[3] );
if ( binXMP.nanoSecond == 0 ) {
tiff->PutUns32 ( binXMP.second, &exifTime[4] );
tiff->PutUns32 ( 1, &exifTime[5] );
} else {
double fSec = (double)binXMP.second + ((double)binXMP.nanoSecond / kBillion );
XMP_Uns32 denom = 1000*1000; // Choose microsecond resolution by default.
TIFF_Manager::TagInfo oldInfo;
bool hadExif = tiff->GetTag ( kTIFF_GPSInfoIFD, kTIFF_GPSTimeStamp, &oldInfo );
if ( hadExif && (oldInfo.type == kTIFF_RationalType) && (oldInfo.count == 3) ) {
XMP_Uns32 oldDenom = tiff->GetUns32 ( &(((XMP_Uns32*)oldInfo.dataPtr)[5]) );
if ( oldDenom != 1 ) denom = oldDenom;
}
fSec *= denom;
while ( fSec > mMaxSec ) { fSec /= 10; denom /= 10; }
tiff->PutUns32 ( (XMP_Uns32)fSec, &exifTime[4] );
tiff->PutUns32 ( denom, &exifTime[5] );
}
tiff->SetTag ( kTIFF_GPSInfoIFD, kTIFF_GPSTimeStamp, kTIFF_RationalType, 3, &exifTime[0] );
char exifDate[16]; // AUDIT: Long enough, only need 11.
snprintf ( exifDate, 12, "%04d:%02d:%02d", binXMP.year, binXMP.month, binXMP.day );
if ( exifDate[10] == 0 ) { // Make sure there is no value overflow.
tiff->SetTag ( kTIFF_GPSInfoIFD, kTIFF_GPSDateStamp, kTIFF_ASCIIType, 11, exifDate );
}
} catch ( ... ) {
}
} // ExportTIFF_GPSTimeStamp
| @@ -233,7 +233,7 @@ static XMP_Uns32 GatherInt ( const char * strPtr, size_t count )
static size_t TrimTrailingSpaces ( char * firstChar, size_t origLen )
{
- if ( origLen == 0 ) return 0;
+ if ( !firstChar || origLen == 0 ) return 0;
char * lastChar = firstChar + origLen - 1;
if ( (*lastChar != ' ') && (*lastChar != 0) ) return origLen; // Nothing to do. | CWE-416 | null | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.