idx int64 | func_before string | Vulnerability Classification string | vul int64 | func_after string | patch string | CWE ID string | lines_before string | lines_after string |
|---|---|---|---|---|---|---|---|---|
10,500 | static void ahci_port_write(AHCIState *s, int port, int offset, uint32_t val)
{
AHCIPortRegs *pr = &s->dev[port].port_regs;
DPRINTF(port, "offset: 0x%x val: 0x%x\n", offset, val);
switch (offset) {
case PORT_LST_ADDR:
pr->lst_addr = val;
break;
case PORT_LST_ADDR_HI:
pr->lst_addr_hi = val;
break;
case PORT_FIS_ADDR:
pr->fis_addr = val;
break;
case PORT_FIS_ADDR_HI:
pr->fis_addr_hi = val;
break;
case PORT_IRQ_STAT:
pr->irq_stat &= ~val;
ahci_check_irq(s);
break;
case PORT_IRQ_MASK:
pr->irq_mask = val & 0xfdc000ff;
ahci_check_irq(s);
break;
case PORT_CMD:
/* Block any Read-only fields from being set;
* including LIST_ON and FIS_ON.
* The spec requires to set ICC bits to zero after the ICC change
* is done. We don't support ICC state changes, therefore always
* force the ICC bits to zero.
*/
pr->cmd = (pr->cmd & PORT_CMD_RO_MASK) |
(val & ~(PORT_CMD_RO_MASK|PORT_CMD_ICC_MASK));
/* Check FIS RX and CLB engines, allow transition to false: */
ahci_cond_start_engines(&s->dev[port], true);
/* XXX usually the FIS would be pending on the bus here and
issuing deferred until the OS enables FIS receival.
Instead, we only submit it once - which works in most
cases, but is a hack. */
if ((pr->cmd & PORT_CMD_FIS_ON) &&
!s->dev[port].init_d2h_sent) {
ahci_init_d2h(&s->dev[port]);
}
check_cmd(s, port);
break;
case PORT_TFDATA:
/* Read Only. */
break;
case PORT_SIG:
/* Read Only */
break;
case PORT_SCR_STAT:
/* Read Only */
break;
case PORT_SCR_CTL:
if (((pr->scr_ctl & AHCI_SCR_SCTL_DET) == 1) &&
((val & AHCI_SCR_SCTL_DET) == 0)) {
ahci_reset_port(s, port);
}
pr->scr_ctl = val;
break;
case PORT_SCR_ERR:
pr->scr_err &= ~val;
break;
case PORT_SCR_ACT:
/* RW1 */
pr->scr_act |= val;
break;
case PORT_CMD_ISSUE:
pr->cmd_issue |= val;
check_cmd(s, port);
break;
default:
break;
}
}
| DoS Exec Code | 0 | static void ahci_port_write(AHCIState *s, int port, int offset, uint32_t val)
{
AHCIPortRegs *pr = &s->dev[port].port_regs;
DPRINTF(port, "offset: 0x%x val: 0x%x\n", offset, val);
switch (offset) {
case PORT_LST_ADDR:
pr->lst_addr = val;
break;
case PORT_LST_ADDR_HI:
pr->lst_addr_hi = val;
break;
case PORT_FIS_ADDR:
pr->fis_addr = val;
break;
case PORT_FIS_ADDR_HI:
pr->fis_addr_hi = val;
break;
case PORT_IRQ_STAT:
pr->irq_stat &= ~val;
ahci_check_irq(s);
break;
case PORT_IRQ_MASK:
pr->irq_mask = val & 0xfdc000ff;
ahci_check_irq(s);
break;
case PORT_CMD:
/* Block any Read-only fields from being set;
* including LIST_ON and FIS_ON.
* The spec requires to set ICC bits to zero after the ICC change
* is done. We don't support ICC state changes, therefore always
* force the ICC bits to zero.
*/
pr->cmd = (pr->cmd & PORT_CMD_RO_MASK) |
(val & ~(PORT_CMD_RO_MASK|PORT_CMD_ICC_MASK));
/* Check FIS RX and CLB engines, allow transition to false: */
ahci_cond_start_engines(&s->dev[port], true);
/* XXX usually the FIS would be pending on the bus here and
issuing deferred until the OS enables FIS receival.
Instead, we only submit it once - which works in most
cases, but is a hack. */
if ((pr->cmd & PORT_CMD_FIS_ON) &&
!s->dev[port].init_d2h_sent) {
ahci_init_d2h(&s->dev[port]);
}
check_cmd(s, port);
break;
case PORT_TFDATA:
/* Read Only. */
break;
case PORT_SIG:
/* Read Only */
break;
case PORT_SCR_STAT:
/* Read Only */
break;
case PORT_SCR_CTL:
if (((pr->scr_ctl & AHCI_SCR_SCTL_DET) == 1) &&
((val & AHCI_SCR_SCTL_DET) == 0)) {
ahci_reset_port(s, port);
}
pr->scr_ctl = val;
break;
case PORT_SCR_ERR:
pr->scr_err &= ~val;
break;
case PORT_SCR_ACT:
/* RW1 */
pr->scr_act |= val;
break;
case PORT_CMD_ISSUE:
pr->cmd_issue |= val;
check_cmd(s, port);
break;
default:
break;
}
}
| @@ -910,6 +910,7 @@ static void ncq_err(NCQTransferState *ncq_tfs)
ide_state->error = ABRT_ERR;
ide_state->status = READY_STAT | ERR_STAT;
ncq_tfs->drive->port_regs.scr_err |= (1 << ncq_tfs->tag);
+ ncq_tfs->used = 0;
}
static void ncq_finish(NCQTransferState *ncq_tfs) | null | null | null |
10,501 | static void ahci_unmap_clb_address(AHCIDevice *ad)
{
dma_memory_unmap(ad->hba->as, ad->lst, 1024,
DMA_DIRECTION_FROM_DEVICE, 1024);
ad->lst = NULL;
}
| DoS Exec Code | 0 | static void ahci_unmap_clb_address(AHCIDevice *ad)
{
dma_memory_unmap(ad->hba->as, ad->lst, 1024,
DMA_DIRECTION_FROM_DEVICE, 1024);
ad->lst = NULL;
}
| @@ -910,6 +910,7 @@ static void ncq_err(NCQTransferState *ncq_tfs)
ide_state->error = ABRT_ERR;
ide_state->status = READY_STAT | ERR_STAT;
ncq_tfs->drive->port_regs.scr_err |= (1 << ncq_tfs->tag);
+ ncq_tfs->used = 0;
}
static void ncq_finish(NCQTransferState *ncq_tfs) | null | null | null |
10,502 | static NOINLINE void attach_option(
struct option_set **opt_list,
const struct dhcp_optflag *optflag,
char *buffer,
int length,
bool dhcpv6)
{
IF_NOT_UDHCPC6(bool dhcpv6 = 0;)
struct option_set *existing;
char *allocated = NULL;
if ((optflag->flags & OPTION_TYPE_MASK) == OPTION_BIN) {
const char *end;
allocated = xstrdup(buffer); /* more than enough */
end = hex2bin(allocated, buffer, 255);
if (errno)
bb_error_msg_and_die("malformed hex string '%s'", buffer);
length = end - allocated;
}
#if ENABLE_FEATURE_UDHCP_RFC3397
if ((optflag->flags & OPTION_TYPE_MASK) == OPTION_DNS_STRING) {
/* reuse buffer and length for RFC1035-formatted string */
allocated = buffer = (char *)dname_enc(NULL, 0, buffer, &length);
}
#endif
existing = udhcp_find_option(*opt_list, optflag->code);
if (!existing) {
struct option_set *new, **curr;
/* make a new option */
log2("attaching option %02x to list", optflag->code);
new = xmalloc(sizeof(*new));
if (!dhcpv6) {
new->data = xmalloc(length + OPT_DATA);
new->data[OPT_CODE] = optflag->code;
new->data[OPT_LEN] = length;
memcpy(new->data + OPT_DATA, (allocated ? allocated : buffer),
length);
} else {
new->data = xmalloc(length + D6_OPT_DATA);
new->data[D6_OPT_CODE] = optflag->code >> 8;
new->data[D6_OPT_CODE + 1] = optflag->code & 0xff;
new->data[D6_OPT_LEN] = length >> 8;
new->data[D6_OPT_LEN + 1] = length & 0xff;
memcpy(new->data + D6_OPT_DATA, (allocated ? allocated : buffer),
length);
}
curr = opt_list;
while (*curr && (*curr)->data[OPT_CODE] < optflag->code)
curr = &(*curr)->next;
new->next = *curr;
*curr = new;
goto ret;
}
if (optflag->flags & OPTION_LIST) {
unsigned old_len;
/* add it to an existing option */
log2("attaching option %02x to existing member of list", optflag->code);
old_len = existing->data[OPT_LEN];
if (old_len + length < 255) {
/* actually 255 is ok too, but adding a space can overlow it */
existing->data = xrealloc(existing->data, OPT_DATA + 1 + old_len + length);
if ((optflag->flags & OPTION_TYPE_MASK) == OPTION_STRING
|| (optflag->flags & OPTION_TYPE_MASK) == OPTION_STRING_HOST
) {
/* add space separator between STRING options in a list */
existing->data[OPT_DATA + old_len] = ' ';
old_len++;
}
memcpy(existing->data + OPT_DATA + old_len, (allocated ? allocated : buffer), length);
existing->data[OPT_LEN] = old_len + length;
} /* else, ignore the data, we could put this in a second option in the future */
} /* else, ignore the new data */
ret:
free(allocated);
}
| +Info | 0 | static NOINLINE void attach_option(
struct option_set **opt_list,
const struct dhcp_optflag *optflag,
char *buffer,
int length,
bool dhcpv6)
{
IF_NOT_UDHCPC6(bool dhcpv6 = 0;)
struct option_set *existing;
char *allocated = NULL;
if ((optflag->flags & OPTION_TYPE_MASK) == OPTION_BIN) {
const char *end;
allocated = xstrdup(buffer); /* more than enough */
end = hex2bin(allocated, buffer, 255);
if (errno)
bb_error_msg_and_die("malformed hex string '%s'", buffer);
length = end - allocated;
}
#if ENABLE_FEATURE_UDHCP_RFC3397
if ((optflag->flags & OPTION_TYPE_MASK) == OPTION_DNS_STRING) {
/* reuse buffer and length for RFC1035-formatted string */
allocated = buffer = (char *)dname_enc(NULL, 0, buffer, &length);
}
#endif
existing = udhcp_find_option(*opt_list, optflag->code);
if (!existing) {
struct option_set *new, **curr;
/* make a new option */
log2("attaching option %02x to list", optflag->code);
new = xmalloc(sizeof(*new));
if (!dhcpv6) {
new->data = xmalloc(length + OPT_DATA);
new->data[OPT_CODE] = optflag->code;
new->data[OPT_LEN] = length;
memcpy(new->data + OPT_DATA, (allocated ? allocated : buffer),
length);
} else {
new->data = xmalloc(length + D6_OPT_DATA);
new->data[D6_OPT_CODE] = optflag->code >> 8;
new->data[D6_OPT_CODE + 1] = optflag->code & 0xff;
new->data[D6_OPT_LEN] = length >> 8;
new->data[D6_OPT_LEN + 1] = length & 0xff;
memcpy(new->data + D6_OPT_DATA, (allocated ? allocated : buffer),
length);
}
curr = opt_list;
while (*curr && (*curr)->data[OPT_CODE] < optflag->code)
curr = &(*curr)->next;
new->next = *curr;
*curr = new;
goto ret;
}
if (optflag->flags & OPTION_LIST) {
unsigned old_len;
/* add it to an existing option */
log2("attaching option %02x to existing member of list", optflag->code);
old_len = existing->data[OPT_LEN];
if (old_len + length < 255) {
/* actually 255 is ok too, but adding a space can overlow it */
existing->data = xrealloc(existing->data, OPT_DATA + 1 + old_len + length);
if ((optflag->flags & OPTION_TYPE_MASK) == OPTION_STRING
|| (optflag->flags & OPTION_TYPE_MASK) == OPTION_STRING_HOST
) {
/* add space separator between STRING options in a list */
existing->data[OPT_DATA + old_len] = ' ';
old_len++;
}
memcpy(existing->data + OPT_DATA + old_len, (allocated ? allocated : buffer), length);
existing->data[OPT_LEN] = old_len + length;
} /* else, ignore the data, we could put this in a second option in the future */
} /* else, ignore the new data */
ret:
free(allocated);
}
| @@ -272,6 +272,15 @@ uint8_t* FAST_FUNC udhcp_get_option(struct dhcp_packet *packet, int code)
goto complain; /* complain and return NULL */
if (optionptr[OPT_CODE] == code) {
+ if (optionptr[OPT_LEN] == 0) {
+ /* So far no valid option with length 0 known.
+ * Having this check means that searching
+ * for DHCP_MESSAGE_TYPE need not worry
+ * that returned pointer might be unsafe
+ * to dereference.
+ */
+ goto complain; /* complain and return NULL */
+ }
log_option("option found", optionptr);
return optionptr + OPT_DATA;
}
@@ -289,6 +298,16 @@ uint8_t* FAST_FUNC udhcp_get_option(struct dhcp_packet *packet, int code)
return NULL;
}
+uint8_t* FAST_FUNC udhcp_get_option32(struct dhcp_packet *packet, int code)
+{
+ uint8_t *r = udhcp_get_option(packet, code);
+ if (r) {
+ if (r[-1] != 4)
+ r = NULL;
+ }
+ return r;
+}
+
/* Return the position of the 'end' option (no bounds checking) */
int FAST_FUNC udhcp_end_option(uint8_t *optionptr)
{ | CWE-125 | null | null |
10,503 | static char **fill_envp(struct dhcp_packet *packet)
{
int envc;
int i;
char **envp, **curr;
const char *opt_name;
uint8_t *temp;
uint8_t overload = 0;
#define BITMAP unsigned
#define BBITS (sizeof(BITMAP) * 8)
#define BMASK(i) (1 << (i & (sizeof(BITMAP) * 8 - 1)))
#define FOUND_OPTS(i) (found_opts[(unsigned)i / BBITS])
BITMAP found_opts[256 / BBITS];
memset(found_opts, 0, sizeof(found_opts));
/* We need 6 elements for:
* "interface=IFACE"
* "ip=N.N.N.N" from packet->yiaddr
* "siaddr=IP" from packet->siaddr_nip (unless 0)
* "boot_file=FILE" from packet->file (unless overloaded)
* "sname=SERVER_HOSTNAME" from packet->sname (unless overloaded)
* terminating NULL
*/
envc = 6;
/* +1 element for each option, +2 for subnet option: */
if (packet) {
/* note: do not search for "pad" (0) and "end" (255) options */
for (i = 1; i < 255; i++) {
temp = udhcp_get_option(packet, i);
if (temp) {
if (i == DHCP_OPTION_OVERLOAD)
overload |= *temp;
else if (i == DHCP_SUBNET)
envc++; /* for $mask */
envc++;
/*if (i != DHCP_MESSAGE_TYPE)*/
FOUND_OPTS(i) |= BMASK(i);
}
}
}
curr = envp = xzalloc(sizeof(envp[0]) * envc);
*curr = xasprintf("interface=%s", client_config.interface);
putenv(*curr++);
if (!packet)
return envp;
/* Export BOOTP fields. Fields we don't (yet?) export:
* uint8_t op; // always BOOTREPLY
* uint8_t htype; // hardware address type. 1 = 10mb ethernet
* uint8_t hlen; // hardware address length
* uint8_t hops; // used by relay agents only
* uint32_t xid;
* uint16_t secs; // elapsed since client began acquisition/renewal
* uint16_t flags; // only one flag so far: bcast. Never set by server
* uint32_t ciaddr; // client IP (usually == yiaddr. can it be different
* // if during renew server wants to give us different IP?)
* uint32_t gateway_nip; // relay agent IP address
* uint8_t chaddr[16]; // link-layer client hardware address (MAC)
* TODO: export gateway_nip as $giaddr?
*/
/* Most important one: yiaddr as $ip */
*curr = xmalloc(sizeof("ip=255.255.255.255"));
sprint_nip(*curr, "ip=", (uint8_t *) &packet->yiaddr);
putenv(*curr++);
if (packet->siaddr_nip) {
/* IP address of next server to use in bootstrap */
*curr = xmalloc(sizeof("siaddr=255.255.255.255"));
sprint_nip(*curr, "siaddr=", (uint8_t *) &packet->siaddr_nip);
putenv(*curr++);
}
if (!(overload & FILE_FIELD) && packet->file[0]) {
/* watch out for invalid packets */
*curr = xasprintf("boot_file=%."DHCP_PKT_FILE_LEN_STR"s", packet->file);
putenv(*curr++);
}
if (!(overload & SNAME_FIELD) && packet->sname[0]) {
/* watch out for invalid packets */
*curr = xasprintf("sname=%."DHCP_PKT_SNAME_LEN_STR"s", packet->sname);
putenv(*curr++);
}
/* Export known DHCP options */
opt_name = dhcp_option_strings;
i = 0;
while (*opt_name) {
uint8_t code = dhcp_optflags[i].code;
BITMAP *found_ptr = &FOUND_OPTS(code);
BITMAP found_mask = BMASK(code);
if (!(*found_ptr & found_mask))
goto next;
*found_ptr &= ~found_mask; /* leave only unknown options */
temp = udhcp_get_option(packet, code);
*curr = xmalloc_optname_optval(temp, &dhcp_optflags[i], opt_name);
putenv(*curr++);
if (code == DHCP_SUBNET) {
/* Subnet option: make things like "$ip/$mask" possible */
uint32_t subnet;
move_from_unaligned32(subnet, temp);
*curr = xasprintf("mask=%u", mton(subnet));
putenv(*curr++);
}
next:
opt_name += strlen(opt_name) + 1;
i++;
}
/* Export unknown options */
for (i = 0; i < 256;) {
BITMAP bitmap = FOUND_OPTS(i);
if (!bitmap) {
i += BBITS;
continue;
}
if (bitmap & BMASK(i)) {
unsigned len, ofs;
temp = udhcp_get_option(packet, i);
/* udhcp_get_option returns ptr to data portion,
* need to go back to get len
*/
len = temp[-OPT_DATA + OPT_LEN];
*curr = xmalloc(sizeof("optNNN=") + 1 + len*2);
ofs = sprintf(*curr, "opt%u=", i);
*bin2hex(*curr + ofs, (void*) temp, len) = '\0';
putenv(*curr++);
}
i++;
}
return envp;
}
| +Info | 0 | static char **fill_envp(struct dhcp_packet *packet)
{
int envc;
int i;
char **envp, **curr;
const char *opt_name;
uint8_t *temp;
uint8_t overload = 0;
#define BITMAP unsigned
#define BBITS (sizeof(BITMAP) * 8)
#define BMASK(i) (1 << (i & (sizeof(BITMAP) * 8 - 1)))
#define FOUND_OPTS(i) (found_opts[(unsigned)i / BBITS])
BITMAP found_opts[256 / BBITS];
memset(found_opts, 0, sizeof(found_opts));
/* We need 6 elements for:
* "interface=IFACE"
* "ip=N.N.N.N" from packet->yiaddr
* "siaddr=IP" from packet->siaddr_nip (unless 0)
* "boot_file=FILE" from packet->file (unless overloaded)
* "sname=SERVER_HOSTNAME" from packet->sname (unless overloaded)
* terminating NULL
*/
envc = 6;
/* +1 element for each option, +2 for subnet option: */
if (packet) {
/* note: do not search for "pad" (0) and "end" (255) options */
for (i = 1; i < 255; i++) {
temp = udhcp_get_option(packet, i);
if (temp) {
if (i == DHCP_OPTION_OVERLOAD)
overload |= *temp;
else if (i == DHCP_SUBNET)
envc++; /* for $mask */
envc++;
/*if (i != DHCP_MESSAGE_TYPE)*/
FOUND_OPTS(i) |= BMASK(i);
}
}
}
curr = envp = xzalloc(sizeof(envp[0]) * envc);
*curr = xasprintf("interface=%s", client_config.interface);
putenv(*curr++);
if (!packet)
return envp;
/* Export BOOTP fields. Fields we don't (yet?) export:
* uint8_t op; // always BOOTREPLY
* uint8_t htype; // hardware address type. 1 = 10mb ethernet
* uint8_t hlen; // hardware address length
* uint8_t hops; // used by relay agents only
* uint32_t xid;
* uint16_t secs; // elapsed since client began acquisition/renewal
* uint16_t flags; // only one flag so far: bcast. Never set by server
* uint32_t ciaddr; // client IP (usually == yiaddr. can it be different
* // if during renew server wants to give us different IP?)
* uint32_t gateway_nip; // relay agent IP address
* uint8_t chaddr[16]; // link-layer client hardware address (MAC)
* TODO: export gateway_nip as $giaddr?
*/
/* Most important one: yiaddr as $ip */
*curr = xmalloc(sizeof("ip=255.255.255.255"));
sprint_nip(*curr, "ip=", (uint8_t *) &packet->yiaddr);
putenv(*curr++);
if (packet->siaddr_nip) {
/* IP address of next server to use in bootstrap */
*curr = xmalloc(sizeof("siaddr=255.255.255.255"));
sprint_nip(*curr, "siaddr=", (uint8_t *) &packet->siaddr_nip);
putenv(*curr++);
}
if (!(overload & FILE_FIELD) && packet->file[0]) {
/* watch out for invalid packets */
*curr = xasprintf("boot_file=%."DHCP_PKT_FILE_LEN_STR"s", packet->file);
putenv(*curr++);
}
if (!(overload & SNAME_FIELD) && packet->sname[0]) {
/* watch out for invalid packets */
*curr = xasprintf("sname=%."DHCP_PKT_SNAME_LEN_STR"s", packet->sname);
putenv(*curr++);
}
/* Export known DHCP options */
opt_name = dhcp_option_strings;
i = 0;
while (*opt_name) {
uint8_t code = dhcp_optflags[i].code;
BITMAP *found_ptr = &FOUND_OPTS(code);
BITMAP found_mask = BMASK(code);
if (!(*found_ptr & found_mask))
goto next;
*found_ptr &= ~found_mask; /* leave only unknown options */
temp = udhcp_get_option(packet, code);
*curr = xmalloc_optname_optval(temp, &dhcp_optflags[i], opt_name);
putenv(*curr++);
if (code == DHCP_SUBNET) {
/* Subnet option: make things like "$ip/$mask" possible */
uint32_t subnet;
move_from_unaligned32(subnet, temp);
*curr = xasprintf("mask=%u", mton(subnet));
putenv(*curr++);
}
next:
opt_name += strlen(opt_name) + 1;
i++;
}
/* Export unknown options */
for (i = 0; i < 256;) {
BITMAP bitmap = FOUND_OPTS(i);
if (!bitmap) {
i += BBITS;
continue;
}
if (bitmap & BMASK(i)) {
unsigned len, ofs;
temp = udhcp_get_option(packet, i);
/* udhcp_get_option returns ptr to data portion,
* need to go back to get len
*/
len = temp[-OPT_DATA + OPT_LEN];
*curr = xmalloc(sizeof("optNNN=") + 1 + len*2);
ofs = sprintf(*curr, "opt%u=", i);
*bin2hex(*curr + ofs, (void*) temp, len) = '\0';
putenv(*curr++);
}
i++;
}
return envp;
}
| @@ -1691,7 +1691,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
* They say ISC DHCP client supports this case.
*/
server_addr = 0;
- temp = udhcp_get_option(&packet, DHCP_SERVER_ID);
+ temp = udhcp_get_option32(&packet, DHCP_SERVER_ID);
if (!temp) {
bb_error_msg("no server ID, using 0.0.0.0");
} else {
@@ -1718,7 +1718,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
struct in_addr temp_addr;
uint8_t *temp;
- temp = udhcp_get_option(&packet, DHCP_LEASE_TIME);
+ temp = udhcp_get_option32(&packet, DHCP_LEASE_TIME);
if (!temp) {
bb_error_msg("no lease time with ACK, using 1 hour lease");
lease_seconds = 60 * 60;
@@ -1813,7 +1813,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
uint32_t svid;
uint8_t *temp;
- temp = udhcp_get_option(&packet, DHCP_SERVER_ID);
+ temp = udhcp_get_option32(&packet, DHCP_SERVER_ID);
if (!temp) {
non_matching_svid:
log1("received DHCP NAK with wrong" | CWE-125 | null | null |
10,504 | static struct dyn_lease *add_lease(
const uint8_t *chaddr, uint32_t yiaddr,
leasetime_t leasetime,
const char *hostname, int hostname_len)
{
struct dyn_lease *oldest;
/* clean out any old ones */
clear_leases(chaddr, yiaddr);
oldest = oldest_expired_lease();
if (oldest) {
memset(oldest, 0, sizeof(*oldest));
if (hostname) {
char *p;
hostname_len++; /* include NUL */
if (hostname_len > sizeof(oldest->hostname))
hostname_len = sizeof(oldest->hostname);
p = safe_strncpy(oldest->hostname, hostname, hostname_len);
/*
* Sanitization (s/bad_char/./g).
* The intent is not to allow only "DNS-valid" hostnames,
* but merely make dumpleases output safe for shells to use.
* We accept "0-9A-Za-z._-", all other chars turn to dots.
*/
while (*p) {
if (!isalnum(*p) && *p != '-' && *p != '_')
*p = '.';
p++;
}
}
if (chaddr)
memcpy(oldest->lease_mac, chaddr, 6);
oldest->lease_nip = yiaddr;
oldest->expires = time(NULL) + leasetime;
}
return oldest;
}
| +Info | 0 | static struct dyn_lease *add_lease(
const uint8_t *chaddr, uint32_t yiaddr,
leasetime_t leasetime,
const char *hostname, int hostname_len)
{
struct dyn_lease *oldest;
/* clean out any old ones */
clear_leases(chaddr, yiaddr);
oldest = oldest_expired_lease();
if (oldest) {
memset(oldest, 0, sizeof(*oldest));
if (hostname) {
char *p;
hostname_len++; /* include NUL */
if (hostname_len > sizeof(oldest->hostname))
hostname_len = sizeof(oldest->hostname);
p = safe_strncpy(oldest->hostname, hostname, hostname_len);
/*
* Sanitization (s/bad_char/./g).
* The intent is not to allow only "DNS-valid" hostnames,
* but merely make dumpleases output safe for shells to use.
* We accept "0-9A-Za-z._-", all other chars turn to dots.
*/
while (*p) {
if (!isalnum(*p) && *p != '-' && *p != '_')
*p = '.';
p++;
}
}
if (chaddr)
memcpy(oldest->lease_mac, chaddr, 6);
oldest->lease_nip = yiaddr;
oldest->expires = time(NULL) + leasetime;
}
return oldest;
}
| @@ -640,7 +640,7 @@ static void add_server_options(struct dhcp_packet *packet)
static uint32_t select_lease_time(struct dhcp_packet *packet)
{
uint32_t lease_time_sec = server_config.max_lease_sec;
- uint8_t *lease_time_opt = udhcp_get_option(packet, DHCP_LEASE_TIME);
+ uint8_t *lease_time_opt = udhcp_get_option32(packet, DHCP_LEASE_TIME);
if (lease_time_opt) {
move_from_unaligned32(lease_time_sec, lease_time_opt);
lease_time_sec = ntohl(lease_time_sec);
@@ -987,7 +987,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
}
/* Get SERVER_ID if present */
- server_id_opt = udhcp_get_option(&packet, DHCP_SERVER_ID);
+ server_id_opt = udhcp_get_option32(&packet, DHCP_SERVER_ID);
if (server_id_opt) {
uint32_t server_id_network_order;
move_from_unaligned32(server_id_network_order, server_id_opt);
@@ -1011,7 +1011,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
}
/* Get REQUESTED_IP if present */
- requested_ip_opt = udhcp_get_option(&packet, DHCP_REQUESTED_IP);
+ requested_ip_opt = udhcp_get_option32(&packet, DHCP_REQUESTED_IP);
if (requested_ip_opt) {
move_from_unaligned32(requested_nip, requested_ip_opt);
} | CWE-125 | null | null |
10,505 | static void add_server_options(struct dhcp_packet *packet)
{
struct option_set *curr = server_config.options;
while (curr) {
if (curr->data[OPT_CODE] != DHCP_LEASE_TIME)
udhcp_add_binary_option(packet, curr->data);
curr = curr->next;
}
packet->siaddr_nip = server_config.siaddr_nip;
if (server_config.sname)
strncpy((char*)packet->sname, server_config.sname, sizeof(packet->sname) - 1);
if (server_config.boot_file)
strncpy((char*)packet->file, server_config.boot_file, sizeof(packet->file) - 1);
}
| +Info | 0 | static void add_server_options(struct dhcp_packet *packet)
{
struct option_set *curr = server_config.options;
while (curr) {
if (curr->data[OPT_CODE] != DHCP_LEASE_TIME)
udhcp_add_binary_option(packet, curr->data);
curr = curr->next;
}
packet->siaddr_nip = server_config.siaddr_nip;
if (server_config.sname)
strncpy((char*)packet->sname, server_config.sname, sizeof(packet->sname) - 1);
if (server_config.boot_file)
strncpy((char*)packet->file, server_config.boot_file, sizeof(packet->file) - 1);
}
| @@ -640,7 +640,7 @@ static void add_server_options(struct dhcp_packet *packet)
static uint32_t select_lease_time(struct dhcp_packet *packet)
{
uint32_t lease_time_sec = server_config.max_lease_sec;
- uint8_t *lease_time_opt = udhcp_get_option(packet, DHCP_LEASE_TIME);
+ uint8_t *lease_time_opt = udhcp_get_option32(packet, DHCP_LEASE_TIME);
if (lease_time_opt) {
move_from_unaligned32(lease_time_sec, lease_time_opt);
lease_time_sec = ntohl(lease_time_sec);
@@ -987,7 +987,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
}
/* Get SERVER_ID if present */
- server_id_opt = udhcp_get_option(&packet, DHCP_SERVER_ID);
+ server_id_opt = udhcp_get_option32(&packet, DHCP_SERVER_ID);
if (server_id_opt) {
uint32_t server_id_network_order;
move_from_unaligned32(server_id_network_order, server_id_opt);
@@ -1011,7 +1011,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
}
/* Get REQUESTED_IP if present */
- requested_ip_opt = udhcp_get_option(&packet, DHCP_REQUESTED_IP);
+ requested_ip_opt = udhcp_get_option32(&packet, DHCP_REQUESTED_IP);
if (requested_ip_opt) {
move_from_unaligned32(requested_nip, requested_ip_opt);
} | CWE-125 | null | null |
10,506 | static void clear_leases(const uint8_t *chaddr, uint32_t yiaddr)
{
unsigned i;
for (i = 0; i < server_config.max_leases; i++) {
if ((chaddr && memcmp(g_leases[i].lease_mac, chaddr, 6) == 0)
|| (yiaddr && g_leases[i].lease_nip == yiaddr)
) {
memset(&g_leases[i], 0, sizeof(g_leases[i]));
}
}
}
| +Info | 0 | static void clear_leases(const uint8_t *chaddr, uint32_t yiaddr)
{
unsigned i;
for (i = 0; i < server_config.max_leases; i++) {
if ((chaddr && memcmp(g_leases[i].lease_mac, chaddr, 6) == 0)
|| (yiaddr && g_leases[i].lease_nip == yiaddr)
) {
memset(&g_leases[i], 0, sizeof(g_leases[i]));
}
}
}
| @@ -640,7 +640,7 @@ static void add_server_options(struct dhcp_packet *packet)
static uint32_t select_lease_time(struct dhcp_packet *packet)
{
uint32_t lease_time_sec = server_config.max_lease_sec;
- uint8_t *lease_time_opt = udhcp_get_option(packet, DHCP_LEASE_TIME);
+ uint8_t *lease_time_opt = udhcp_get_option32(packet, DHCP_LEASE_TIME);
if (lease_time_opt) {
move_from_unaligned32(lease_time_sec, lease_time_opt);
lease_time_sec = ntohl(lease_time_sec);
@@ -987,7 +987,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
}
/* Get SERVER_ID if present */
- server_id_opt = udhcp_get_option(&packet, DHCP_SERVER_ID);
+ server_id_opt = udhcp_get_option32(&packet, DHCP_SERVER_ID);
if (server_id_opt) {
uint32_t server_id_network_order;
move_from_unaligned32(server_id_network_order, server_id_opt);
@@ -1011,7 +1011,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
}
/* Get REQUESTED_IP if present */
- requested_ip_opt = udhcp_get_option(&packet, DHCP_REQUESTED_IP);
+ requested_ip_opt = udhcp_get_option32(&packet, DHCP_REQUESTED_IP);
if (requested_ip_opt) {
move_from_unaligned32(requested_nip, requested_ip_opt);
} | CWE-125 | null | null |
10,507 | static struct dyn_lease *find_lease_by_nip(uint32_t nip)
{
unsigned i;
for (i = 0; i < server_config.max_leases; i++)
if (g_leases[i].lease_nip == nip)
return &g_leases[i];
return NULL;
}
| +Info | 0 | static struct dyn_lease *find_lease_by_nip(uint32_t nip)
{
unsigned i;
for (i = 0; i < server_config.max_leases; i++)
if (g_leases[i].lease_nip == nip)
return &g_leases[i];
return NULL;
}
| @@ -640,7 +640,7 @@ static void add_server_options(struct dhcp_packet *packet)
static uint32_t select_lease_time(struct dhcp_packet *packet)
{
uint32_t lease_time_sec = server_config.max_lease_sec;
- uint8_t *lease_time_opt = udhcp_get_option(packet, DHCP_LEASE_TIME);
+ uint8_t *lease_time_opt = udhcp_get_option32(packet, DHCP_LEASE_TIME);
if (lease_time_opt) {
move_from_unaligned32(lease_time_sec, lease_time_opt);
lease_time_sec = ntohl(lease_time_sec);
@@ -987,7 +987,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
}
/* Get SERVER_ID if present */
- server_id_opt = udhcp_get_option(&packet, DHCP_SERVER_ID);
+ server_id_opt = udhcp_get_option32(&packet, DHCP_SERVER_ID);
if (server_id_opt) {
uint32_t server_id_network_order;
move_from_unaligned32(server_id_network_order, server_id_opt);
@@ -1011,7 +1011,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
}
/* Get REQUESTED_IP if present */
- requested_ip_opt = udhcp_get_option(&packet, DHCP_REQUESTED_IP);
+ requested_ip_opt = udhcp_get_option32(&packet, DHCP_REQUESTED_IP);
if (requested_ip_opt) {
move_from_unaligned32(requested_nip, requested_ip_opt);
} | CWE-125 | null | null |
10,508 | static uint32_t get_static_nip_by_mac(struct static_lease *st_lease, void *mac)
{
while (st_lease) {
if (memcmp(st_lease->mac, mac, 6) == 0)
return st_lease->nip;
st_lease = st_lease->next;
}
return 0;
}
| +Info | 0 | static uint32_t get_static_nip_by_mac(struct static_lease *st_lease, void *mac)
{
while (st_lease) {
if (memcmp(st_lease->mac, mac, 6) == 0)
return st_lease->nip;
st_lease = st_lease->next;
}
return 0;
}
| @@ -640,7 +640,7 @@ static void add_server_options(struct dhcp_packet *packet)
static uint32_t select_lease_time(struct dhcp_packet *packet)
{
uint32_t lease_time_sec = server_config.max_lease_sec;
- uint8_t *lease_time_opt = udhcp_get_option(packet, DHCP_LEASE_TIME);
+ uint8_t *lease_time_opt = udhcp_get_option32(packet, DHCP_LEASE_TIME);
if (lease_time_opt) {
move_from_unaligned32(lease_time_sec, lease_time_opt);
lease_time_sec = ntohl(lease_time_sec);
@@ -987,7 +987,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
}
/* Get SERVER_ID if present */
- server_id_opt = udhcp_get_option(&packet, DHCP_SERVER_ID);
+ server_id_opt = udhcp_get_option32(&packet, DHCP_SERVER_ID);
if (server_id_opt) {
uint32_t server_id_network_order;
move_from_unaligned32(server_id_network_order, server_id_opt);
@@ -1011,7 +1011,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
}
/* Get REQUESTED_IP if present */
- requested_ip_opt = udhcp_get_option(&packet, DHCP_REQUESTED_IP);
+ requested_ip_opt = udhcp_get_option32(&packet, DHCP_REQUESTED_IP);
if (requested_ip_opt) {
move_from_unaligned32(requested_nip, requested_ip_opt);
} | CWE-125 | null | null |
10,509 | static void init_packet(struct dhcp_packet *packet, struct dhcp_packet *oldpacket, char type)
{
/* Sets op, htype, hlen, cookie fields
* and adds DHCP_MESSAGE_TYPE option */
udhcp_init_header(packet, type);
packet->xid = oldpacket->xid;
memcpy(packet->chaddr, oldpacket->chaddr, sizeof(oldpacket->chaddr));
packet->flags = oldpacket->flags;
packet->gateway_nip = oldpacket->gateway_nip;
packet->ciaddr = oldpacket->ciaddr;
udhcp_add_simple_option(packet, DHCP_SERVER_ID, server_config.server_nip);
}
| +Info | 0 | static void init_packet(struct dhcp_packet *packet, struct dhcp_packet *oldpacket, char type)
{
/* Sets op, htype, hlen, cookie fields
* and adds DHCP_MESSAGE_TYPE option */
udhcp_init_header(packet, type);
packet->xid = oldpacket->xid;
memcpy(packet->chaddr, oldpacket->chaddr, sizeof(oldpacket->chaddr));
packet->flags = oldpacket->flags;
packet->gateway_nip = oldpacket->gateway_nip;
packet->ciaddr = oldpacket->ciaddr;
udhcp_add_simple_option(packet, DHCP_SERVER_ID, server_config.server_nip);
}
| @@ -640,7 +640,7 @@ static void add_server_options(struct dhcp_packet *packet)
static uint32_t select_lease_time(struct dhcp_packet *packet)
{
uint32_t lease_time_sec = server_config.max_lease_sec;
- uint8_t *lease_time_opt = udhcp_get_option(packet, DHCP_LEASE_TIME);
+ uint8_t *lease_time_opt = udhcp_get_option32(packet, DHCP_LEASE_TIME);
if (lease_time_opt) {
move_from_unaligned32(lease_time_sec, lease_time_opt);
lease_time_sec = ntohl(lease_time_sec);
@@ -987,7 +987,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
}
/* Get SERVER_ID if present */
- server_id_opt = udhcp_get_option(&packet, DHCP_SERVER_ID);
+ server_id_opt = udhcp_get_option32(&packet, DHCP_SERVER_ID);
if (server_id_opt) {
uint32_t server_id_network_order;
move_from_unaligned32(server_id_network_order, server_id_opt);
@@ -1011,7 +1011,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
}
/* Get REQUESTED_IP if present */
- requested_ip_opt = udhcp_get_option(&packet, DHCP_REQUESTED_IP);
+ requested_ip_opt = udhcp_get_option32(&packet, DHCP_REQUESTED_IP);
if (requested_ip_opt) {
move_from_unaligned32(requested_nip, requested_ip_opt);
} | CWE-125 | null | null |
10,510 | static int is_expired_lease(struct dyn_lease *lease)
{
return (lease->expires < (leasetime_t) time(NULL));
}
| +Info | 0 | static int is_expired_lease(struct dyn_lease *lease)
{
return (lease->expires < (leasetime_t) time(NULL));
}
| @@ -640,7 +640,7 @@ static void add_server_options(struct dhcp_packet *packet)
static uint32_t select_lease_time(struct dhcp_packet *packet)
{
uint32_t lease_time_sec = server_config.max_lease_sec;
- uint8_t *lease_time_opt = udhcp_get_option(packet, DHCP_LEASE_TIME);
+ uint8_t *lease_time_opt = udhcp_get_option32(packet, DHCP_LEASE_TIME);
if (lease_time_opt) {
move_from_unaligned32(lease_time_sec, lease_time_opt);
lease_time_sec = ntohl(lease_time_sec);
@@ -987,7 +987,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
}
/* Get SERVER_ID if present */
- server_id_opt = udhcp_get_option(&packet, DHCP_SERVER_ID);
+ server_id_opt = udhcp_get_option32(&packet, DHCP_SERVER_ID);
if (server_id_opt) {
uint32_t server_id_network_order;
move_from_unaligned32(server_id_network_order, server_id_opt);
@@ -1011,7 +1011,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
}
/* Get REQUESTED_IP if present */
- requested_ip_opt = udhcp_get_option(&packet, DHCP_REQUESTED_IP);
+ requested_ip_opt = udhcp_get_option32(&packet, DHCP_REQUESTED_IP);
if (requested_ip_opt) {
move_from_unaligned32(requested_nip, requested_ip_opt);
} | CWE-125 | null | null |
10,511 | static void log_static_leases(struct static_lease **st_lease_pp)
{
struct static_lease *cur;
if (dhcp_verbose < 2)
return;
cur = *st_lease_pp;
while (cur) {
bb_error_msg("static lease: mac:%02x:%02x:%02x:%02x:%02x:%02x nip:%x",
cur->mac[0], cur->mac[1], cur->mac[2],
cur->mac[3], cur->mac[4], cur->mac[5],
cur->nip
);
cur = cur->next;
}
}
| +Info | 0 | static void log_static_leases(struct static_lease **st_lease_pp)
{
struct static_lease *cur;
if (dhcp_verbose < 2)
return;
cur = *st_lease_pp;
while (cur) {
bb_error_msg("static lease: mac:%02x:%02x:%02x:%02x:%02x:%02x nip:%x",
cur->mac[0], cur->mac[1], cur->mac[2],
cur->mac[3], cur->mac[4], cur->mac[5],
cur->nip
);
cur = cur->next;
}
}
| @@ -640,7 +640,7 @@ static void add_server_options(struct dhcp_packet *packet)
static uint32_t select_lease_time(struct dhcp_packet *packet)
{
uint32_t lease_time_sec = server_config.max_lease_sec;
- uint8_t *lease_time_opt = udhcp_get_option(packet, DHCP_LEASE_TIME);
+ uint8_t *lease_time_opt = udhcp_get_option32(packet, DHCP_LEASE_TIME);
if (lease_time_opt) {
move_from_unaligned32(lease_time_sec, lease_time_opt);
lease_time_sec = ntohl(lease_time_sec);
@@ -987,7 +987,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
}
/* Get SERVER_ID if present */
- server_id_opt = udhcp_get_option(&packet, DHCP_SERVER_ID);
+ server_id_opt = udhcp_get_option32(&packet, DHCP_SERVER_ID);
if (server_id_opt) {
uint32_t server_id_network_order;
move_from_unaligned32(server_id_network_order, server_id_opt);
@@ -1011,7 +1011,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
}
/* Get REQUESTED_IP if present */
- requested_ip_opt = udhcp_get_option(&packet, DHCP_REQUESTED_IP);
+ requested_ip_opt = udhcp_get_option32(&packet, DHCP_REQUESTED_IP);
if (requested_ip_opt) {
move_from_unaligned32(requested_nip, requested_ip_opt);
} | CWE-125 | null | null |
10,512 | static int nobody_responds_to_arp(uint32_t nip, const uint8_t *safe_mac, unsigned arpping_ms)
{
struct in_addr temp;
int r;
r = arpping(nip, safe_mac,
server_config.server_nip,
server_config.server_mac,
server_config.interface,
arpping_ms);
if (r)
return r;
temp.s_addr = nip;
bb_error_msg("%s belongs to someone, reserving it for %u seconds",
inet_ntoa(temp), (unsigned)server_config.conflict_time);
add_lease(NULL, nip, server_config.conflict_time, NULL, 0);
return 0;
}
| +Info | 0 | static int nobody_responds_to_arp(uint32_t nip, const uint8_t *safe_mac, unsigned arpping_ms)
{
struct in_addr temp;
int r;
r = arpping(nip, safe_mac,
server_config.server_nip,
server_config.server_mac,
server_config.interface,
arpping_ms);
if (r)
return r;
temp.s_addr = nip;
bb_error_msg("%s belongs to someone, reserving it for %u seconds",
inet_ntoa(temp), (unsigned)server_config.conflict_time);
add_lease(NULL, nip, server_config.conflict_time, NULL, 0);
return 0;
}
| @@ -640,7 +640,7 @@ static void add_server_options(struct dhcp_packet *packet)
static uint32_t select_lease_time(struct dhcp_packet *packet)
{
uint32_t lease_time_sec = server_config.max_lease_sec;
- uint8_t *lease_time_opt = udhcp_get_option(packet, DHCP_LEASE_TIME);
+ uint8_t *lease_time_opt = udhcp_get_option32(packet, DHCP_LEASE_TIME);
if (lease_time_opt) {
move_from_unaligned32(lease_time_sec, lease_time_opt);
lease_time_sec = ntohl(lease_time_sec);
@@ -987,7 +987,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
}
/* Get SERVER_ID if present */
- server_id_opt = udhcp_get_option(&packet, DHCP_SERVER_ID);
+ server_id_opt = udhcp_get_option32(&packet, DHCP_SERVER_ID);
if (server_id_opt) {
uint32_t server_id_network_order;
move_from_unaligned32(server_id_network_order, server_id_opt);
@@ -1011,7 +1011,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
}
/* Get REQUESTED_IP if present */
- requested_ip_opt = udhcp_get_option(&packet, DHCP_REQUESTED_IP);
+ requested_ip_opt = udhcp_get_option32(&packet, DHCP_REQUESTED_IP);
if (requested_ip_opt) {
move_from_unaligned32(requested_nip, requested_ip_opt);
} | CWE-125 | null | null |
10,513 | static struct dyn_lease *oldest_expired_lease(void)
{
struct dyn_lease *oldest_lease = NULL;
leasetime_t oldest_time = time(NULL);
unsigned i;
/* Unexpired leases have g_leases[i].expires >= current time
* and therefore can't ever match */
for (i = 0; i < server_config.max_leases; i++) {
if (g_leases[i].expires == 0 /* empty entry */
|| g_leases[i].expires < oldest_time
) {
oldest_time = g_leases[i].expires;
oldest_lease = &g_leases[i];
}
}
return oldest_lease;
}
| +Info | 0 | static struct dyn_lease *oldest_expired_lease(void)
{
struct dyn_lease *oldest_lease = NULL;
leasetime_t oldest_time = time(NULL);
unsigned i;
/* Unexpired leases have g_leases[i].expires >= current time
* and therefore can't ever match */
for (i = 0; i < server_config.max_leases; i++) {
if (g_leases[i].expires == 0 /* empty entry */
|| g_leases[i].expires < oldest_time
) {
oldest_time = g_leases[i].expires;
oldest_lease = &g_leases[i];
}
}
return oldest_lease;
}
| @@ -640,7 +640,7 @@ static void add_server_options(struct dhcp_packet *packet)
static uint32_t select_lease_time(struct dhcp_packet *packet)
{
uint32_t lease_time_sec = server_config.max_lease_sec;
- uint8_t *lease_time_opt = udhcp_get_option(packet, DHCP_LEASE_TIME);
+ uint8_t *lease_time_opt = udhcp_get_option32(packet, DHCP_LEASE_TIME);
if (lease_time_opt) {
move_from_unaligned32(lease_time_sec, lease_time_opt);
lease_time_sec = ntohl(lease_time_sec);
@@ -987,7 +987,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
}
/* Get SERVER_ID if present */
- server_id_opt = udhcp_get_option(&packet, DHCP_SERVER_ID);
+ server_id_opt = udhcp_get_option32(&packet, DHCP_SERVER_ID);
if (server_id_opt) {
uint32_t server_id_network_order;
move_from_unaligned32(server_id_network_order, server_id_opt);
@@ -1011,7 +1011,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
}
/* Get REQUESTED_IP if present */
- requested_ip_opt = udhcp_get_option(&packet, DHCP_REQUESTED_IP);
+ requested_ip_opt = udhcp_get_option32(&packet, DHCP_REQUESTED_IP);
if (requested_ip_opt) {
move_from_unaligned32(requested_nip, requested_ip_opt);
} | CWE-125 | null | null |
10,514 | static NOINLINE void read_config(const char *file)
{
parser_t *parser;
const struct config_keyword *k;
unsigned i;
char *token[2];
for (i = 0; i < KWS_WITH_DEFAULTS; i++)
keywords[i].handler(keywords[i].def, (char*)&server_config + keywords[i].ofs);
parser = config_open(file);
while (config_read(parser, token, 2, 2, "# \t", PARSE_NORMAL)) {
for (k = keywords, i = 0; i < ARRAY_SIZE(keywords); k++, i++) {
if (strcasecmp(token[0], k->keyword) == 0) {
if (!k->handler(token[1], (char*)&server_config + k->ofs)) {
bb_error_msg("can't parse line %u in %s",
parser->lineno, file);
/* reset back to the default value */
k->handler(k->def, (char*)&server_config + k->ofs);
}
break;
}
}
}
config_close(parser);
server_config.start_ip = ntohl(server_config.start_ip);
server_config.end_ip = ntohl(server_config.end_ip);
}
| +Info | 0 | static NOINLINE void read_config(const char *file)
{
parser_t *parser;
const struct config_keyword *k;
unsigned i;
char *token[2];
for (i = 0; i < KWS_WITH_DEFAULTS; i++)
keywords[i].handler(keywords[i].def, (char*)&server_config + keywords[i].ofs);
parser = config_open(file);
while (config_read(parser, token, 2, 2, "# \t", PARSE_NORMAL)) {
for (k = keywords, i = 0; i < ARRAY_SIZE(keywords); k++, i++) {
if (strcasecmp(token[0], k->keyword) == 0) {
if (!k->handler(token[1], (char*)&server_config + k->ofs)) {
bb_error_msg("can't parse line %u in %s",
parser->lineno, file);
/* reset back to the default value */
k->handler(k->def, (char*)&server_config + k->ofs);
}
break;
}
}
}
config_close(parser);
server_config.start_ip = ntohl(server_config.start_ip);
server_config.end_ip = ntohl(server_config.end_ip);
}
| @@ -640,7 +640,7 @@ static void add_server_options(struct dhcp_packet *packet)
static uint32_t select_lease_time(struct dhcp_packet *packet)
{
uint32_t lease_time_sec = server_config.max_lease_sec;
- uint8_t *lease_time_opt = udhcp_get_option(packet, DHCP_LEASE_TIME);
+ uint8_t *lease_time_opt = udhcp_get_option32(packet, DHCP_LEASE_TIME);
if (lease_time_opt) {
move_from_unaligned32(lease_time_sec, lease_time_opt);
lease_time_sec = ntohl(lease_time_sec);
@@ -987,7 +987,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
}
/* Get SERVER_ID if present */
- server_id_opt = udhcp_get_option(&packet, DHCP_SERVER_ID);
+ server_id_opt = udhcp_get_option32(&packet, DHCP_SERVER_ID);
if (server_id_opt) {
uint32_t server_id_network_order;
move_from_unaligned32(server_id_network_order, server_id_opt);
@@ -1011,7 +1011,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
}
/* Get REQUESTED_IP if present */
- requested_ip_opt = udhcp_get_option(&packet, DHCP_REQUESTED_IP);
+ requested_ip_opt = udhcp_get_option32(&packet, DHCP_REQUESTED_IP);
if (requested_ip_opt) {
move_from_unaligned32(requested_nip, requested_ip_opt);
} | CWE-125 | null | null |
10,515 | static NOINLINE void read_leases(const char *file)
{
struct dyn_lease lease;
int64_t written_at, time_passed;
int fd;
#if defined CONFIG_UDHCP_DEBUG && CONFIG_UDHCP_DEBUG >= 1
unsigned i = 0;
#endif
fd = open_or_warn(file, O_RDONLY);
if (fd < 0)
return;
if (full_read(fd, &written_at, sizeof(written_at)) != sizeof(written_at))
goto ret;
written_at = SWAP_BE64(written_at);
time_passed = time(NULL) - written_at;
/* Strange written_at, or lease file from old version of udhcpd
* which had no "written_at" field? */
if ((uint64_t)time_passed > 12 * 60 * 60)
goto ret;
while (full_read(fd, &lease, sizeof(lease)) == sizeof(lease)) {
uint32_t y = ntohl(lease.lease_nip);
if (y >= server_config.start_ip && y <= server_config.end_ip) {
signed_leasetime_t expires = ntohl(lease.expires) - (signed_leasetime_t)time_passed;
uint32_t static_nip;
if (expires <= 0)
/* We keep expired leases: add_lease() will add
* a lease with 0 seconds remaining.
* Fewer IP address changes this way for mass reboot scenario.
*/
expires = 0;
/* Check if there is a different static lease for this IP or MAC */
static_nip = get_static_nip_by_mac(server_config.static_leases, lease.lease_mac);
if (static_nip) {
/* NB: we do not add lease even if static_nip == lease.lease_nip.
*/
continue;
}
if (is_nip_reserved(server_config.static_leases, lease.lease_nip))
continue;
/* NB: add_lease takes "relative time", IOW,
* lease duration, not lease deadline. */
if (add_lease(lease.lease_mac, lease.lease_nip,
expires,
lease.hostname, sizeof(lease.hostname)
) == 0
) {
bb_error_msg("too many leases while loading %s", file);
break;
}
#if defined CONFIG_UDHCP_DEBUG && CONFIG_UDHCP_DEBUG >= 1
i++;
#endif
}
}
log1("read %d leases", i);
ret:
close(fd);
}
| +Info | 0 | static NOINLINE void read_leases(const char *file)
{
struct dyn_lease lease;
int64_t written_at, time_passed;
int fd;
#if defined CONFIG_UDHCP_DEBUG && CONFIG_UDHCP_DEBUG >= 1
unsigned i = 0;
#endif
fd = open_or_warn(file, O_RDONLY);
if (fd < 0)
return;
if (full_read(fd, &written_at, sizeof(written_at)) != sizeof(written_at))
goto ret;
written_at = SWAP_BE64(written_at);
time_passed = time(NULL) - written_at;
/* Strange written_at, or lease file from old version of udhcpd
* which had no "written_at" field? */
if ((uint64_t)time_passed > 12 * 60 * 60)
goto ret;
while (full_read(fd, &lease, sizeof(lease)) == sizeof(lease)) {
uint32_t y = ntohl(lease.lease_nip);
if (y >= server_config.start_ip && y <= server_config.end_ip) {
signed_leasetime_t expires = ntohl(lease.expires) - (signed_leasetime_t)time_passed;
uint32_t static_nip;
if (expires <= 0)
/* We keep expired leases: add_lease() will add
* a lease with 0 seconds remaining.
* Fewer IP address changes this way for mass reboot scenario.
*/
expires = 0;
/* Check if there is a different static lease for this IP or MAC */
static_nip = get_static_nip_by_mac(server_config.static_leases, lease.lease_mac);
if (static_nip) {
/* NB: we do not add lease even if static_nip == lease.lease_nip.
*/
continue;
}
if (is_nip_reserved(server_config.static_leases, lease.lease_nip))
continue;
/* NB: add_lease takes "relative time", IOW,
* lease duration, not lease deadline. */
if (add_lease(lease.lease_mac, lease.lease_nip,
expires,
lease.hostname, sizeof(lease.hostname)
) == 0
) {
bb_error_msg("too many leases while loading %s", file);
break;
}
#if defined CONFIG_UDHCP_DEBUG && CONFIG_UDHCP_DEBUG >= 1
i++;
#endif
}
}
log1("read %d leases", i);
ret:
close(fd);
}
| @@ -640,7 +640,7 @@ static void add_server_options(struct dhcp_packet *packet)
static uint32_t select_lease_time(struct dhcp_packet *packet)
{
uint32_t lease_time_sec = server_config.max_lease_sec;
- uint8_t *lease_time_opt = udhcp_get_option(packet, DHCP_LEASE_TIME);
+ uint8_t *lease_time_opt = udhcp_get_option32(packet, DHCP_LEASE_TIME);
if (lease_time_opt) {
move_from_unaligned32(lease_time_sec, lease_time_opt);
lease_time_sec = ntohl(lease_time_sec);
@@ -987,7 +987,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
}
/* Get SERVER_ID if present */
- server_id_opt = udhcp_get_option(&packet, DHCP_SERVER_ID);
+ server_id_opt = udhcp_get_option32(&packet, DHCP_SERVER_ID);
if (server_id_opt) {
uint32_t server_id_network_order;
move_from_unaligned32(server_id_network_order, server_id_opt);
@@ -1011,7 +1011,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
}
/* Get REQUESTED_IP if present */
- requested_ip_opt = udhcp_get_option(&packet, DHCP_REQUESTED_IP);
+ requested_ip_opt = udhcp_get_option32(&packet, DHCP_REQUESTED_IP);
if (requested_ip_opt) {
move_from_unaligned32(requested_nip, requested_ip_opt);
} | CWE-125 | null | null |
10,516 | static int FAST_FUNC read_staticlease(const char *const_line, void *arg)
{
char *line;
char *mac_string;
char *ip_string;
struct ether_addr mac_bytes; /* it's "struct { uint8_t mac[6]; }" */
uint32_t nip;
/* Read mac */
line = (char *) const_line;
mac_string = strtok_r(line, " \t", &line);
if (!mac_string || !ether_aton_r(mac_string, &mac_bytes))
return 0;
/* Read ip */
ip_string = strtok_r(NULL, " \t", &line);
if (!ip_string || !udhcp_str2nip(ip_string, &nip))
return 0;
add_static_lease(arg, (uint8_t*) &mac_bytes, nip);
log_static_leases(arg);
return 1;
}
| +Info | 0 | static int FAST_FUNC read_staticlease(const char *const_line, void *arg)
{
char *line;
char *mac_string;
char *ip_string;
struct ether_addr mac_bytes; /* it's "struct { uint8_t mac[6]; }" */
uint32_t nip;
/* Read mac */
line = (char *) const_line;
mac_string = strtok_r(line, " \t", &line);
if (!mac_string || !ether_aton_r(mac_string, &mac_bytes))
return 0;
/* Read ip */
ip_string = strtok_r(NULL, " \t", &line);
if (!ip_string || !udhcp_str2nip(ip_string, &nip))
return 0;
add_static_lease(arg, (uint8_t*) &mac_bytes, nip);
log_static_leases(arg);
return 1;
}
| @@ -640,7 +640,7 @@ static void add_server_options(struct dhcp_packet *packet)
static uint32_t select_lease_time(struct dhcp_packet *packet)
{
uint32_t lease_time_sec = server_config.max_lease_sec;
- uint8_t *lease_time_opt = udhcp_get_option(packet, DHCP_LEASE_TIME);
+ uint8_t *lease_time_opt = udhcp_get_option32(packet, DHCP_LEASE_TIME);
if (lease_time_opt) {
move_from_unaligned32(lease_time_sec, lease_time_opt);
lease_time_sec = ntohl(lease_time_sec);
@@ -987,7 +987,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
}
/* Get SERVER_ID if present */
- server_id_opt = udhcp_get_option(&packet, DHCP_SERVER_ID);
+ server_id_opt = udhcp_get_option32(&packet, DHCP_SERVER_ID);
if (server_id_opt) {
uint32_t server_id_network_order;
move_from_unaligned32(server_id_network_order, server_id_opt);
@@ -1011,7 +1011,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
}
/* Get REQUESTED_IP if present */
- requested_ip_opt = udhcp_get_option(&packet, DHCP_REQUESTED_IP);
+ requested_ip_opt = udhcp_get_option32(&packet, DHCP_REQUESTED_IP);
if (requested_ip_opt) {
move_from_unaligned32(requested_nip, requested_ip_opt);
} | CWE-125 | null | null |
10,517 | static int FAST_FUNC read_str(const char *line, void *arg)
{
char **dest = arg;
free(*dest);
*dest = xstrdup(line);
return 1;
}
| +Info | 0 | static int FAST_FUNC read_str(const char *line, void *arg)
{
char **dest = arg;
free(*dest);
*dest = xstrdup(line);
return 1;
}
| @@ -640,7 +640,7 @@ static void add_server_options(struct dhcp_packet *packet)
static uint32_t select_lease_time(struct dhcp_packet *packet)
{
uint32_t lease_time_sec = server_config.max_lease_sec;
- uint8_t *lease_time_opt = udhcp_get_option(packet, DHCP_LEASE_TIME);
+ uint8_t *lease_time_opt = udhcp_get_option32(packet, DHCP_LEASE_TIME);
if (lease_time_opt) {
move_from_unaligned32(lease_time_sec, lease_time_opt);
lease_time_sec = ntohl(lease_time_sec);
@@ -987,7 +987,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
}
/* Get SERVER_ID if present */
- server_id_opt = udhcp_get_option(&packet, DHCP_SERVER_ID);
+ server_id_opt = udhcp_get_option32(&packet, DHCP_SERVER_ID);
if (server_id_opt) {
uint32_t server_id_network_order;
move_from_unaligned32(server_id_network_order, server_id_opt);
@@ -1011,7 +1011,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
}
/* Get REQUESTED_IP if present */
- requested_ip_opt = udhcp_get_option(&packet, DHCP_REQUESTED_IP);
+ requested_ip_opt = udhcp_get_option32(&packet, DHCP_REQUESTED_IP);
if (requested_ip_opt) {
move_from_unaligned32(requested_nip, requested_ip_opt);
} | CWE-125 | null | null |
10,518 | static NOINLINE void send_NAK(struct dhcp_packet *oldpacket)
{
struct dhcp_packet packet;
init_packet(&packet, oldpacket, DHCPNAK);
log1("sending %s", "NAK");
send_packet(&packet, /*force_bcast:*/ 1);
}
| +Info | 0 | static NOINLINE void send_NAK(struct dhcp_packet *oldpacket)
{
struct dhcp_packet packet;
init_packet(&packet, oldpacket, DHCPNAK);
log1("sending %s", "NAK");
send_packet(&packet, /*force_bcast:*/ 1);
}
| @@ -640,7 +640,7 @@ static void add_server_options(struct dhcp_packet *packet)
static uint32_t select_lease_time(struct dhcp_packet *packet)
{
uint32_t lease_time_sec = server_config.max_lease_sec;
- uint8_t *lease_time_opt = udhcp_get_option(packet, DHCP_LEASE_TIME);
+ uint8_t *lease_time_opt = udhcp_get_option32(packet, DHCP_LEASE_TIME);
if (lease_time_opt) {
move_from_unaligned32(lease_time_sec, lease_time_opt);
lease_time_sec = ntohl(lease_time_sec);
@@ -987,7 +987,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
}
/* Get SERVER_ID if present */
- server_id_opt = udhcp_get_option(&packet, DHCP_SERVER_ID);
+ server_id_opt = udhcp_get_option32(&packet, DHCP_SERVER_ID);
if (server_id_opt) {
uint32_t server_id_network_order;
move_from_unaligned32(server_id_network_order, server_id_opt);
@@ -1011,7 +1011,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
}
/* Get REQUESTED_IP if present */
- requested_ip_opt = udhcp_get_option(&packet, DHCP_REQUESTED_IP);
+ requested_ip_opt = udhcp_get_option32(&packet, DHCP_REQUESTED_IP);
if (requested_ip_opt) {
move_from_unaligned32(requested_nip, requested_ip_opt);
} | CWE-125 | null | null |
10,519 | static NOINLINE void send_offer(struct dhcp_packet *oldpacket,
uint32_t static_lease_nip,
struct dyn_lease *lease,
uint8_t *requested_ip_opt,
unsigned arpping_ms)
{
struct dhcp_packet packet;
uint32_t lease_time_sec;
struct in_addr addr;
init_packet(&packet, oldpacket, DHCPOFFER);
/* If it is a static lease, use its IP */
packet.yiaddr = static_lease_nip;
/* Else: */
if (!static_lease_nip) {
/* We have no static lease for client's chaddr */
uint32_t req_nip;
const char *p_host_name;
if (lease) {
/* We have a dynamic lease for client's chaddr.
* Reuse its IP (even if lease is expired).
* Note that we ignore requested IP in this case.
*/
packet.yiaddr = lease->lease_nip;
}
/* Or: if client has requested an IP */
else if (requested_ip_opt != NULL
/* (read IP) */
&& (move_from_unaligned32(req_nip, requested_ip_opt), 1)
/* and the IP is in the lease range */
&& ntohl(req_nip) >= server_config.start_ip
&& ntohl(req_nip) <= server_config.end_ip
/* and */
&& ( !(lease = find_lease_by_nip(req_nip)) /* is not already taken */
|| is_expired_lease(lease) /* or is taken, but expired */
)
) {
packet.yiaddr = req_nip;
}
else {
/* Otherwise, find a free IP */
packet.yiaddr = find_free_or_expired_nip(oldpacket->chaddr, arpping_ms);
}
if (!packet.yiaddr) {
bb_error_msg("no free IP addresses. OFFER abandoned");
return;
}
/* Reserve the IP for a short time hoping to get DHCPREQUEST soon */
p_host_name = (const char*) udhcp_get_option(oldpacket, DHCP_HOST_NAME);
lease = add_lease(packet.chaddr, packet.yiaddr,
server_config.offer_time,
p_host_name,
p_host_name ? (unsigned char)p_host_name[OPT_LEN - OPT_DATA] : 0
);
if (!lease) {
bb_error_msg("no free IP addresses. OFFER abandoned");
return;
}
}
lease_time_sec = select_lease_time(oldpacket);
udhcp_add_simple_option(&packet, DHCP_LEASE_TIME, htonl(lease_time_sec));
add_server_options(&packet);
addr.s_addr = packet.yiaddr;
bb_error_msg("sending OFFER of %s", inet_ntoa(addr));
/* send_packet emits error message itself if it detects failure */
send_packet(&packet, /*force_bcast:*/ 0);
}
| +Info | 0 | static NOINLINE void send_offer(struct dhcp_packet *oldpacket,
uint32_t static_lease_nip,
struct dyn_lease *lease,
uint8_t *requested_ip_opt,
unsigned arpping_ms)
{
struct dhcp_packet packet;
uint32_t lease_time_sec;
struct in_addr addr;
init_packet(&packet, oldpacket, DHCPOFFER);
/* If it is a static lease, use its IP */
packet.yiaddr = static_lease_nip;
/* Else: */
if (!static_lease_nip) {
/* We have no static lease for client's chaddr */
uint32_t req_nip;
const char *p_host_name;
if (lease) {
/* We have a dynamic lease for client's chaddr.
* Reuse its IP (even if lease is expired).
* Note that we ignore requested IP in this case.
*/
packet.yiaddr = lease->lease_nip;
}
/* Or: if client has requested an IP */
else if (requested_ip_opt != NULL
/* (read IP) */
&& (move_from_unaligned32(req_nip, requested_ip_opt), 1)
/* and the IP is in the lease range */
&& ntohl(req_nip) >= server_config.start_ip
&& ntohl(req_nip) <= server_config.end_ip
/* and */
&& ( !(lease = find_lease_by_nip(req_nip)) /* is not already taken */
|| is_expired_lease(lease) /* or is taken, but expired */
)
) {
packet.yiaddr = req_nip;
}
else {
/* Otherwise, find a free IP */
packet.yiaddr = find_free_or_expired_nip(oldpacket->chaddr, arpping_ms);
}
if (!packet.yiaddr) {
bb_error_msg("no free IP addresses. OFFER abandoned");
return;
}
/* Reserve the IP for a short time hoping to get DHCPREQUEST soon */
p_host_name = (const char*) udhcp_get_option(oldpacket, DHCP_HOST_NAME);
lease = add_lease(packet.chaddr, packet.yiaddr,
server_config.offer_time,
p_host_name,
p_host_name ? (unsigned char)p_host_name[OPT_LEN - OPT_DATA] : 0
);
if (!lease) {
bb_error_msg("no free IP addresses. OFFER abandoned");
return;
}
}
lease_time_sec = select_lease_time(oldpacket);
udhcp_add_simple_option(&packet, DHCP_LEASE_TIME, htonl(lease_time_sec));
add_server_options(&packet);
addr.s_addr = packet.yiaddr;
bb_error_msg("sending OFFER of %s", inet_ntoa(addr));
/* send_packet emits error message itself if it detects failure */
send_packet(&packet, /*force_bcast:*/ 0);
}
| @@ -640,7 +640,7 @@ static void add_server_options(struct dhcp_packet *packet)
static uint32_t select_lease_time(struct dhcp_packet *packet)
{
uint32_t lease_time_sec = server_config.max_lease_sec;
- uint8_t *lease_time_opt = udhcp_get_option(packet, DHCP_LEASE_TIME);
+ uint8_t *lease_time_opt = udhcp_get_option32(packet, DHCP_LEASE_TIME);
if (lease_time_opt) {
move_from_unaligned32(lease_time_sec, lease_time_opt);
lease_time_sec = ntohl(lease_time_sec);
@@ -987,7 +987,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
}
/* Get SERVER_ID if present */
- server_id_opt = udhcp_get_option(&packet, DHCP_SERVER_ID);
+ server_id_opt = udhcp_get_option32(&packet, DHCP_SERVER_ID);
if (server_id_opt) {
uint32_t server_id_network_order;
move_from_unaligned32(server_id_network_order, server_id_opt);
@@ -1011,7 +1011,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
}
/* Get REQUESTED_IP if present */
- requested_ip_opt = udhcp_get_option(&packet, DHCP_REQUESTED_IP);
+ requested_ip_opt = udhcp_get_option32(&packet, DHCP_REQUESTED_IP);
if (requested_ip_opt) {
move_from_unaligned32(requested_nip, requested_ip_opt);
} | CWE-125 | null | null |
10,520 | static void send_packet(struct dhcp_packet *dhcp_pkt, int force_broadcast)
{
if (dhcp_pkt->gateway_nip)
send_packet_to_relay(dhcp_pkt);
else
send_packet_to_client(dhcp_pkt, force_broadcast);
}
| +Info | 0 | static void send_packet(struct dhcp_packet *dhcp_pkt, int force_broadcast)
{
if (dhcp_pkt->gateway_nip)
send_packet_to_relay(dhcp_pkt);
else
send_packet_to_client(dhcp_pkt, force_broadcast);
}
| @@ -640,7 +640,7 @@ static void add_server_options(struct dhcp_packet *packet)
static uint32_t select_lease_time(struct dhcp_packet *packet)
{
uint32_t lease_time_sec = server_config.max_lease_sec;
- uint8_t *lease_time_opt = udhcp_get_option(packet, DHCP_LEASE_TIME);
+ uint8_t *lease_time_opt = udhcp_get_option32(packet, DHCP_LEASE_TIME);
if (lease_time_opt) {
move_from_unaligned32(lease_time_sec, lease_time_opt);
lease_time_sec = ntohl(lease_time_sec);
@@ -987,7 +987,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
}
/* Get SERVER_ID if present */
- server_id_opt = udhcp_get_option(&packet, DHCP_SERVER_ID);
+ server_id_opt = udhcp_get_option32(&packet, DHCP_SERVER_ID);
if (server_id_opt) {
uint32_t server_id_network_order;
move_from_unaligned32(server_id_network_order, server_id_opt);
@@ -1011,7 +1011,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
}
/* Get REQUESTED_IP if present */
- requested_ip_opt = udhcp_get_option(&packet, DHCP_REQUESTED_IP);
+ requested_ip_opt = udhcp_get_option32(&packet, DHCP_REQUESTED_IP);
if (requested_ip_opt) {
move_from_unaligned32(requested_nip, requested_ip_opt);
} | CWE-125 | null | null |
10,521 | static void send_packet_to_client(struct dhcp_packet *dhcp_pkt, int force_broadcast)
{
const uint8_t *chaddr;
uint32_t ciaddr;
if (force_broadcast
|| (dhcp_pkt->flags & htons(BROADCAST_FLAG))
|| dhcp_pkt->ciaddr == 0
) {
log1("broadcasting packet to client");
ciaddr = INADDR_BROADCAST;
chaddr = MAC_BCAST_ADDR;
} else {
log1("unicasting packet to client ciaddr");
ciaddr = dhcp_pkt->ciaddr;
chaddr = dhcp_pkt->chaddr;
}
udhcp_send_raw_packet(dhcp_pkt,
/*src*/ server_config.server_nip, SERVER_PORT,
/*dst*/ ciaddr, CLIENT_PORT, chaddr,
server_config.ifindex);
}
| +Info | 0 | static void send_packet_to_client(struct dhcp_packet *dhcp_pkt, int force_broadcast)
{
const uint8_t *chaddr;
uint32_t ciaddr;
if (force_broadcast
|| (dhcp_pkt->flags & htons(BROADCAST_FLAG))
|| dhcp_pkt->ciaddr == 0
) {
log1("broadcasting packet to client");
ciaddr = INADDR_BROADCAST;
chaddr = MAC_BCAST_ADDR;
} else {
log1("unicasting packet to client ciaddr");
ciaddr = dhcp_pkt->ciaddr;
chaddr = dhcp_pkt->chaddr;
}
udhcp_send_raw_packet(dhcp_pkt,
/*src*/ server_config.server_nip, SERVER_PORT,
/*dst*/ ciaddr, CLIENT_PORT, chaddr,
server_config.ifindex);
}
| @@ -640,7 +640,7 @@ static void add_server_options(struct dhcp_packet *packet)
static uint32_t select_lease_time(struct dhcp_packet *packet)
{
uint32_t lease_time_sec = server_config.max_lease_sec;
- uint8_t *lease_time_opt = udhcp_get_option(packet, DHCP_LEASE_TIME);
+ uint8_t *lease_time_opt = udhcp_get_option32(packet, DHCP_LEASE_TIME);
if (lease_time_opt) {
move_from_unaligned32(lease_time_sec, lease_time_opt);
lease_time_sec = ntohl(lease_time_sec);
@@ -987,7 +987,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
}
/* Get SERVER_ID if present */
- server_id_opt = udhcp_get_option(&packet, DHCP_SERVER_ID);
+ server_id_opt = udhcp_get_option32(&packet, DHCP_SERVER_ID);
if (server_id_opt) {
uint32_t server_id_network_order;
move_from_unaligned32(server_id_network_order, server_id_opt);
@@ -1011,7 +1011,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
}
/* Get REQUESTED_IP if present */
- requested_ip_opt = udhcp_get_option(&packet, DHCP_REQUESTED_IP);
+ requested_ip_opt = udhcp_get_option32(&packet, DHCP_REQUESTED_IP);
if (requested_ip_opt) {
move_from_unaligned32(requested_nip, requested_ip_opt);
} | CWE-125 | null | null |
10,522 | static void send_packet_to_relay(struct dhcp_packet *dhcp_pkt)
{
log1("forwarding packet to relay");
udhcp_send_kernel_packet(dhcp_pkt,
server_config.server_nip, SERVER_PORT,
dhcp_pkt->gateway_nip, SERVER_PORT);
}
| +Info | 0 | static void send_packet_to_relay(struct dhcp_packet *dhcp_pkt)
{
log1("forwarding packet to relay");
udhcp_send_kernel_packet(dhcp_pkt,
server_config.server_nip, SERVER_PORT,
dhcp_pkt->gateway_nip, SERVER_PORT);
}
| @@ -640,7 +640,7 @@ static void add_server_options(struct dhcp_packet *packet)
static uint32_t select_lease_time(struct dhcp_packet *packet)
{
uint32_t lease_time_sec = server_config.max_lease_sec;
- uint8_t *lease_time_opt = udhcp_get_option(packet, DHCP_LEASE_TIME);
+ uint8_t *lease_time_opt = udhcp_get_option32(packet, DHCP_LEASE_TIME);
if (lease_time_opt) {
move_from_unaligned32(lease_time_sec, lease_time_opt);
lease_time_sec = ntohl(lease_time_sec);
@@ -987,7 +987,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
}
/* Get SERVER_ID if present */
- server_id_opt = udhcp_get_option(&packet, DHCP_SERVER_ID);
+ server_id_opt = udhcp_get_option32(&packet, DHCP_SERVER_ID);
if (server_id_opt) {
uint32_t server_id_network_order;
move_from_unaligned32(server_id_network_order, server_id_opt);
@@ -1011,7 +1011,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
}
/* Get REQUESTED_IP if present */
- requested_ip_opt = udhcp_get_option(&packet, DHCP_REQUESTED_IP);
+ requested_ip_opt = udhcp_get_option32(&packet, DHCP_REQUESTED_IP);
if (requested_ip_opt) {
move_from_unaligned32(requested_nip, requested_ip_opt);
} | CWE-125 | null | null |
10,523 | static void write_leases(void)
{
int fd;
unsigned i;
leasetime_t curr;
int64_t written_at;
fd = open_or_warn(server_config.lease_file, O_WRONLY|O_CREAT|O_TRUNC);
if (fd < 0)
return;
curr = written_at = time(NULL);
written_at = SWAP_BE64(written_at);
full_write(fd, &written_at, sizeof(written_at));
for (i = 0; i < server_config.max_leases; i++) {
leasetime_t tmp_time;
if (g_leases[i].lease_nip == 0)
continue;
/* Screw with the time in the struct, for easier writing */
tmp_time = g_leases[i].expires;
g_leases[i].expires -= curr;
if ((signed_leasetime_t) g_leases[i].expires < 0)
g_leases[i].expires = 0;
g_leases[i].expires = htonl(g_leases[i].expires);
/* No error check. If the file gets truncated,
* we lose some leases on restart. Oh well. */
full_write(fd, &g_leases[i], sizeof(g_leases[i]));
/* Then restore it when done */
g_leases[i].expires = tmp_time;
}
close(fd);
if (server_config.notify_file) {
char *argv[3];
argv[0] = server_config.notify_file;
argv[1] = server_config.lease_file;
argv[2] = NULL;
spawn_and_wait(argv);
}
}
| +Info | 0 | static void write_leases(void)
{
int fd;
unsigned i;
leasetime_t curr;
int64_t written_at;
fd = open_or_warn(server_config.lease_file, O_WRONLY|O_CREAT|O_TRUNC);
if (fd < 0)
return;
curr = written_at = time(NULL);
written_at = SWAP_BE64(written_at);
full_write(fd, &written_at, sizeof(written_at));
for (i = 0; i < server_config.max_leases; i++) {
leasetime_t tmp_time;
if (g_leases[i].lease_nip == 0)
continue;
/* Screw with the time in the struct, for easier writing */
tmp_time = g_leases[i].expires;
g_leases[i].expires -= curr;
if ((signed_leasetime_t) g_leases[i].expires < 0)
g_leases[i].expires = 0;
g_leases[i].expires = htonl(g_leases[i].expires);
/* No error check. If the file gets truncated,
* we lose some leases on restart. Oh well. */
full_write(fd, &g_leases[i], sizeof(g_leases[i]));
/* Then restore it when done */
g_leases[i].expires = tmp_time;
}
close(fd);
if (server_config.notify_file) {
char *argv[3];
argv[0] = server_config.notify_file;
argv[1] = server_config.lease_file;
argv[2] = NULL;
spawn_and_wait(argv);
}
}
| @@ -640,7 +640,7 @@ static void add_server_options(struct dhcp_packet *packet)
static uint32_t select_lease_time(struct dhcp_packet *packet)
{
uint32_t lease_time_sec = server_config.max_lease_sec;
- uint8_t *lease_time_opt = udhcp_get_option(packet, DHCP_LEASE_TIME);
+ uint8_t *lease_time_opt = udhcp_get_option32(packet, DHCP_LEASE_TIME);
if (lease_time_opt) {
move_from_unaligned32(lease_time_sec, lease_time_opt);
lease_time_sec = ntohl(lease_time_sec);
@@ -987,7 +987,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
}
/* Get SERVER_ID if present */
- server_id_opt = udhcp_get_option(&packet, DHCP_SERVER_ID);
+ server_id_opt = udhcp_get_option32(&packet, DHCP_SERVER_ID);
if (server_id_opt) {
uint32_t server_id_network_order;
move_from_unaligned32(server_id_network_order, server_id_opt);
@@ -1011,7 +1011,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
}
/* Get REQUESTED_IP if present */
- requested_ip_opt = udhcp_get_option(&packet, DHCP_REQUESTED_IP);
+ requested_ip_opt = udhcp_get_option32(&packet, DHCP_REQUESTED_IP);
if (requested_ip_opt) {
move_from_unaligned32(requested_nip, requested_ip_opt);
} | CWE-125 | null | null |
10,524 | static int count_commas(char *s)
{
int n = 0;
while (*s)
{
if (*s == ',')
n ++;
s ++;
}
return n;
}
| Exec Code Overflow | 0 | static int count_commas(char *s)
{
int n = 0;
while (*s)
{
if (*s == ',')
n ++;
s ++;
}
return n;
}
| @@ -89,7 +89,7 @@ xps_begin_opacity(xps_document *doc, const fz_matrix *ctm, const fz_rect *area,
if (scb_color_att)
{
fz_colorspace *colorspace;
- float samples[32];
+ float samples[FZ_MAX_COLORS];
xps_parse_color(doc, base_uri, scb_color_att, &colorspace, samples);
opacity = opacity * samples[0];
}
@@ -208,12 +208,13 @@ void
xps_parse_color(xps_document *doc, char *base_uri, char *string,
fz_colorspace **csp, float *samples)
{
+ fz_context *ctx = doc->ctx;
char *p;
int i, n;
char buf[1024];
char *profile;
- *csp = fz_device_rgb(doc->ctx);
+ *csp = fz_device_rgb(ctx);
samples[0] = 1;
samples[1] = 0;
@@ -259,7 +260,7 @@ xps_parse_color(xps_document *doc, char *base_uri, char *string,
profile = strchr(buf, ' ');
if (!profile)
{
- fz_warn(doc->ctx, "cannot find icc profile uri in '%s'", string);
+ fz_warn(ctx, "cannot find icc profile uri in '%s'", string);
return;
}
@@ -267,12 +268,17 @@ xps_parse_color(xps_document *doc, char *base_uri, char *string,
p = strchr(profile, ' ');
if (!p)
{
- fz_warn(doc->ctx, "cannot find component values in '%s'", profile);
+ fz_warn(ctx, "cannot find component values in '%s'", profile);
return;
}
*p++ = 0;
n = count_commas(p) + 1;
+ if (n > FZ_MAX_COLORS)
+ {
+ fz_warn(ctx, "ignoring %d color components (max %d allowed)", n - FZ_MAX_COLORS, FZ_MAX_COLORS);
+ n = FZ_MAX_COLORS;
+ }
i = 0;
while (i < n)
{
@@ -292,10 +298,10 @@ xps_parse_color(xps_document *doc, char *base_uri, char *string,
/* TODO: load ICC profile */
switch (n)
{
- case 2: *csp = fz_device_gray(doc->ctx); break;
- case 4: *csp = fz_device_rgb(doc->ctx); break;
- case 5: *csp = fz_device_cmyk(doc->ctx); break;
- default: *csp = fz_device_gray(doc->ctx); break;
+ case 2: *csp = fz_device_gray(ctx); break;
+ case 4: *csp = fz_device_rgb(ctx); break;
+ case 5: *csp = fz_device_cmyk(ctx); break;
+ default: *csp = fz_device_gray(ctx); break;
}
}
} | CWE-119 | null | null |
10,525 | static inline int unhex(int a)
{
if (a >= 'A' && a <= 'F') return a - 'A' + 0xA;
if (a >= 'a' && a <= 'f') return a - 'a' + 0xA;
if (a >= '0' && a <= '9') return a - '0';
return 0;
}
| Exec Code Overflow | 0 | static inline int unhex(int a)
{
if (a >= 'A' && a <= 'F') return a - 'A' + 0xA;
if (a >= 'a' && a <= 'f') return a - 'a' + 0xA;
if (a >= '0' && a <= '9') return a - '0';
return 0;
}
| @@ -89,7 +89,7 @@ xps_begin_opacity(xps_document *doc, const fz_matrix *ctm, const fz_rect *area,
if (scb_color_att)
{
fz_colorspace *colorspace;
- float samples[32];
+ float samples[FZ_MAX_COLORS];
xps_parse_color(doc, base_uri, scb_color_att, &colorspace, samples);
opacity = opacity * samples[0];
}
@@ -208,12 +208,13 @@ void
xps_parse_color(xps_document *doc, char *base_uri, char *string,
fz_colorspace **csp, float *samples)
{
+ fz_context *ctx = doc->ctx;
char *p;
int i, n;
char buf[1024];
char *profile;
- *csp = fz_device_rgb(doc->ctx);
+ *csp = fz_device_rgb(ctx);
samples[0] = 1;
samples[1] = 0;
@@ -259,7 +260,7 @@ xps_parse_color(xps_document *doc, char *base_uri, char *string,
profile = strchr(buf, ' ');
if (!profile)
{
- fz_warn(doc->ctx, "cannot find icc profile uri in '%s'", string);
+ fz_warn(ctx, "cannot find icc profile uri in '%s'", string);
return;
}
@@ -267,12 +268,17 @@ xps_parse_color(xps_document *doc, char *base_uri, char *string,
p = strchr(profile, ' ');
if (!p)
{
- fz_warn(doc->ctx, "cannot find component values in '%s'", profile);
+ fz_warn(ctx, "cannot find component values in '%s'", profile);
return;
}
*p++ = 0;
n = count_commas(p) + 1;
+ if (n > FZ_MAX_COLORS)
+ {
+ fz_warn(ctx, "ignoring %d color components (max %d allowed)", n - FZ_MAX_COLORS, FZ_MAX_COLORS);
+ n = FZ_MAX_COLORS;
+ }
i = 0;
while (i < n)
{
@@ -292,10 +298,10 @@ xps_parse_color(xps_document *doc, char *base_uri, char *string,
/* TODO: load ICC profile */
switch (n)
{
- case 2: *csp = fz_device_gray(doc->ctx); break;
- case 4: *csp = fz_device_rgb(doc->ctx); break;
- case 5: *csp = fz_device_cmyk(doc->ctx); break;
- default: *csp = fz_device_gray(doc->ctx); break;
+ case 2: *csp = fz_device_gray(ctx); break;
+ case 4: *csp = fz_device_rgb(ctx); break;
+ case 5: *csp = fz_device_cmyk(ctx); break;
+ default: *csp = fz_device_gray(ctx); break;
}
}
} | CWE-119 | null | null |
10,526 | xps_end_opacity(xps_document *doc, char *base_uri, xps_resource *dict,
char *opacity_att, fz_xml *opacity_mask_tag)
{
if (!opacity_att && !opacity_mask_tag)
return;
if (doc->opacity_top > 0)
doc->opacity_top--;
if (opacity_mask_tag)
{
if (strcmp(fz_xml_tag(opacity_mask_tag), "SolidColorBrush"))
fz_pop_clip(doc->dev);
}
}
| Exec Code Overflow | 0 | xps_end_opacity(xps_document *doc, char *base_uri, xps_resource *dict,
char *opacity_att, fz_xml *opacity_mask_tag)
{
if (!opacity_att && !opacity_mask_tag)
return;
if (doc->opacity_top > 0)
doc->opacity_top--;
if (opacity_mask_tag)
{
if (strcmp(fz_xml_tag(opacity_mask_tag), "SolidColorBrush"))
fz_pop_clip(doc->dev);
}
}
| @@ -89,7 +89,7 @@ xps_begin_opacity(xps_document *doc, const fz_matrix *ctm, const fz_rect *area,
if (scb_color_att)
{
fz_colorspace *colorspace;
- float samples[32];
+ float samples[FZ_MAX_COLORS];
xps_parse_color(doc, base_uri, scb_color_att, &colorspace, samples);
opacity = opacity * samples[0];
}
@@ -208,12 +208,13 @@ void
xps_parse_color(xps_document *doc, char *base_uri, char *string,
fz_colorspace **csp, float *samples)
{
+ fz_context *ctx = doc->ctx;
char *p;
int i, n;
char buf[1024];
char *profile;
- *csp = fz_device_rgb(doc->ctx);
+ *csp = fz_device_rgb(ctx);
samples[0] = 1;
samples[1] = 0;
@@ -259,7 +260,7 @@ xps_parse_color(xps_document *doc, char *base_uri, char *string,
profile = strchr(buf, ' ');
if (!profile)
{
- fz_warn(doc->ctx, "cannot find icc profile uri in '%s'", string);
+ fz_warn(ctx, "cannot find icc profile uri in '%s'", string);
return;
}
@@ -267,12 +268,17 @@ xps_parse_color(xps_document *doc, char *base_uri, char *string,
p = strchr(profile, ' ');
if (!p)
{
- fz_warn(doc->ctx, "cannot find component values in '%s'", profile);
+ fz_warn(ctx, "cannot find component values in '%s'", profile);
return;
}
*p++ = 0;
n = count_commas(p) + 1;
+ if (n > FZ_MAX_COLORS)
+ {
+ fz_warn(ctx, "ignoring %d color components (max %d allowed)", n - FZ_MAX_COLORS, FZ_MAX_COLORS);
+ n = FZ_MAX_COLORS;
+ }
i = 0;
while (i < n)
{
@@ -292,10 +298,10 @@ xps_parse_color(xps_document *doc, char *base_uri, char *string,
/* TODO: load ICC profile */
switch (n)
{
- case 2: *csp = fz_device_gray(doc->ctx); break;
- case 4: *csp = fz_device_rgb(doc->ctx); break;
- case 5: *csp = fz_device_cmyk(doc->ctx); break;
- default: *csp = fz_device_gray(doc->ctx); break;
+ case 2: *csp = fz_device_gray(ctx); break;
+ case 4: *csp = fz_device_rgb(ctx); break;
+ case 5: *csp = fz_device_cmyk(ctx); break;
+ default: *csp = fz_device_gray(ctx); break;
}
}
} | CWE-119 | null | null |
10,527 | xps_parse_element(xps_document *doc, const fz_matrix *ctm, const fz_rect *area, char *base_uri, xps_resource *dict, fz_xml *node)
{
if (doc->cookie && doc->cookie->abort)
return;
if (!strcmp(fz_xml_tag(node), "Path"))
xps_parse_path(doc, ctm, base_uri, dict, node);
if (!strcmp(fz_xml_tag(node), "Glyphs"))
xps_parse_glyphs(doc, ctm, base_uri, dict, node);
if (!strcmp(fz_xml_tag(node), "Canvas"))
xps_parse_canvas(doc, ctm, area, base_uri, dict, node);
if (!strcmp(fz_xml_tag(node), "mc:AlternateContent"))
{
node = xps_lookup_alternate_content(node);
if (node)
xps_parse_element(doc, ctm, area, base_uri, dict, node);
}
/* skip unknown tags (like Foo.Resources and similar) */
}
| Exec Code Overflow | 0 | xps_parse_element(xps_document *doc, const fz_matrix *ctm, const fz_rect *area, char *base_uri, xps_resource *dict, fz_xml *node)
{
if (doc->cookie && doc->cookie->abort)
return;
if (!strcmp(fz_xml_tag(node), "Path"))
xps_parse_path(doc, ctm, base_uri, dict, node);
if (!strcmp(fz_xml_tag(node), "Glyphs"))
xps_parse_glyphs(doc, ctm, base_uri, dict, node);
if (!strcmp(fz_xml_tag(node), "Canvas"))
xps_parse_canvas(doc, ctm, area, base_uri, dict, node);
if (!strcmp(fz_xml_tag(node), "mc:AlternateContent"))
{
node = xps_lookup_alternate_content(node);
if (node)
xps_parse_element(doc, ctm, area, base_uri, dict, node);
}
/* skip unknown tags (like Foo.Resources and similar) */
}
| @@ -89,7 +89,7 @@ xps_begin_opacity(xps_document *doc, const fz_matrix *ctm, const fz_rect *area,
if (scb_color_att)
{
fz_colorspace *colorspace;
- float samples[32];
+ float samples[FZ_MAX_COLORS];
xps_parse_color(doc, base_uri, scb_color_att, &colorspace, samples);
opacity = opacity * samples[0];
}
@@ -208,12 +208,13 @@ void
xps_parse_color(xps_document *doc, char *base_uri, char *string,
fz_colorspace **csp, float *samples)
{
+ fz_context *ctx = doc->ctx;
char *p;
int i, n;
char buf[1024];
char *profile;
- *csp = fz_device_rgb(doc->ctx);
+ *csp = fz_device_rgb(ctx);
samples[0] = 1;
samples[1] = 0;
@@ -259,7 +260,7 @@ xps_parse_color(xps_document *doc, char *base_uri, char *string,
profile = strchr(buf, ' ');
if (!profile)
{
- fz_warn(doc->ctx, "cannot find icc profile uri in '%s'", string);
+ fz_warn(ctx, "cannot find icc profile uri in '%s'", string);
return;
}
@@ -267,12 +268,17 @@ xps_parse_color(xps_document *doc, char *base_uri, char *string,
p = strchr(profile, ' ');
if (!p)
{
- fz_warn(doc->ctx, "cannot find component values in '%s'", profile);
+ fz_warn(ctx, "cannot find component values in '%s'", profile);
return;
}
*p++ = 0;
n = count_commas(p) + 1;
+ if (n > FZ_MAX_COLORS)
+ {
+ fz_warn(ctx, "ignoring %d color components (max %d allowed)", n - FZ_MAX_COLORS, FZ_MAX_COLORS);
+ n = FZ_MAX_COLORS;
+ }
i = 0;
while (i < n)
{
@@ -292,10 +298,10 @@ xps_parse_color(xps_document *doc, char *base_uri, char *string,
/* TODO: load ICC profile */
switch (n)
{
- case 2: *csp = fz_device_gray(doc->ctx); break;
- case 4: *csp = fz_device_rgb(doc->ctx); break;
- case 5: *csp = fz_device_cmyk(doc->ctx); break;
- default: *csp = fz_device_gray(doc->ctx); break;
+ case 2: *csp = fz_device_gray(ctx); break;
+ case 4: *csp = fz_device_rgb(ctx); break;
+ case 5: *csp = fz_device_cmyk(ctx); break;
+ default: *csp = fz_device_gray(ctx); break;
}
}
} | CWE-119 | null | null |
10,528 | xps_parse_rectangle(xps_document *doc, char *text, fz_rect *rect)
{
float args[4];
char *s = text;
int i;
args[0] = 0; args[1] = 0;
args[2] = 1; args[3] = 1;
for (i = 0; i < 4 && *s; i++)
{
args[i] = fz_atof(s);
while (*s && *s != ',')
s++;
if (*s == ',')
s++;
}
rect->x0 = args[0];
rect->y0 = args[1];
rect->x1 = args[0] + args[2];
rect->y1 = args[1] + args[3];
}
| Exec Code Overflow | 0 | xps_parse_rectangle(xps_document *doc, char *text, fz_rect *rect)
{
float args[4];
char *s = text;
int i;
args[0] = 0; args[1] = 0;
args[2] = 1; args[3] = 1;
for (i = 0; i < 4 && *s; i++)
{
args[i] = fz_atof(s);
while (*s && *s != ',')
s++;
if (*s == ',')
s++;
}
rect->x0 = args[0];
rect->y0 = args[1];
rect->x1 = args[0] + args[2];
rect->y1 = args[1] + args[3];
}
| @@ -89,7 +89,7 @@ xps_begin_opacity(xps_document *doc, const fz_matrix *ctm, const fz_rect *area,
if (scb_color_att)
{
fz_colorspace *colorspace;
- float samples[32];
+ float samples[FZ_MAX_COLORS];
xps_parse_color(doc, base_uri, scb_color_att, &colorspace, samples);
opacity = opacity * samples[0];
}
@@ -208,12 +208,13 @@ void
xps_parse_color(xps_document *doc, char *base_uri, char *string,
fz_colorspace **csp, float *samples)
{
+ fz_context *ctx = doc->ctx;
char *p;
int i, n;
char buf[1024];
char *profile;
- *csp = fz_device_rgb(doc->ctx);
+ *csp = fz_device_rgb(ctx);
samples[0] = 1;
samples[1] = 0;
@@ -259,7 +260,7 @@ xps_parse_color(xps_document *doc, char *base_uri, char *string,
profile = strchr(buf, ' ');
if (!profile)
{
- fz_warn(doc->ctx, "cannot find icc profile uri in '%s'", string);
+ fz_warn(ctx, "cannot find icc profile uri in '%s'", string);
return;
}
@@ -267,12 +268,17 @@ xps_parse_color(xps_document *doc, char *base_uri, char *string,
p = strchr(profile, ' ');
if (!p)
{
- fz_warn(doc->ctx, "cannot find component values in '%s'", profile);
+ fz_warn(ctx, "cannot find component values in '%s'", profile);
return;
}
*p++ = 0;
n = count_commas(p) + 1;
+ if (n > FZ_MAX_COLORS)
+ {
+ fz_warn(ctx, "ignoring %d color components (max %d allowed)", n - FZ_MAX_COLORS, FZ_MAX_COLORS);
+ n = FZ_MAX_COLORS;
+ }
i = 0;
while (i < n)
{
@@ -292,10 +298,10 @@ xps_parse_color(xps_document *doc, char *base_uri, char *string,
/* TODO: load ICC profile */
switch (n)
{
- case 2: *csp = fz_device_gray(doc->ctx); break;
- case 4: *csp = fz_device_rgb(doc->ctx); break;
- case 5: *csp = fz_device_cmyk(doc->ctx); break;
- default: *csp = fz_device_gray(doc->ctx); break;
+ case 2: *csp = fz_device_gray(ctx); break;
+ case 4: *csp = fz_device_rgb(ctx); break;
+ case 5: *csp = fz_device_cmyk(ctx); break;
+ default: *csp = fz_device_gray(ctx); break;
}
}
} | CWE-119 | null | null |
10,529 | static inline int is_real_num_char(int c)
{
return (c >= '0' && c <= '9') ||
c == 'e' || c == 'E' || c == '+' || c == '-' || c == '.';
}
| Exec Code Overflow | 0 | static inline int is_real_num_char(int c)
{
return (c >= '0' && c <= '9') ||
c == 'e' || c == 'E' || c == '+' || c == '-' || c == '.';
}
| @@ -590,7 +590,7 @@ xps_parse_glyphs(xps_document *doc, const fz_matrix *ctm,
if (fill_att)
{
- float samples[32];
+ float samples[FZ_MAX_COLORS];
fz_colorspace *colorspace;
xps_parse_color(doc, base_uri, fill_att, &colorspace, samples); | CWE-119 | null | null |
10,530 | xps_count_font_encodings(fz_font *font)
{
FT_Face face = font->ft_face;
return face->num_charmaps;
}
| Exec Code Overflow | 0 | xps_count_font_encodings(fz_font *font)
{
FT_Face face = font->ft_face;
return face->num_charmaps;
}
| @@ -590,7 +590,7 @@ xps_parse_glyphs(xps_document *doc, const fz_matrix *ctm,
if (fill_att)
{
- float samples[32];
+ float samples[FZ_MAX_COLORS];
fz_colorspace *colorspace;
xps_parse_color(doc, base_uri, fill_att, &colorspace, samples); | CWE-119 | null | null |
10,531 | xps_deobfuscate_font_resource(xps_document *doc, xps_part *part)
{
unsigned char buf[33];
unsigned char key[16];
char *p;
int i;
p = strrchr(part->name, '/');
if (!p)
p = part->name;
for (i = 0; i < 32 && *p; p++)
{
if (ishex(*p))
buf[i++] = *p;
}
buf[i] = 0;
if (i != 32)
{
fz_warn(doc->ctx, "cannot extract GUID from obfuscated font part name");
return;
}
for (i = 0; i < 16; i++)
key[i] = unhex(buf[i*2+0]) * 16 + unhex(buf[i*2+1]);
for (i = 0; i < 16; i++)
{
part->data[i] ^= key[15-i];
part->data[i+16] ^= key[15-i];
}
}
| Exec Code Overflow | 0 | xps_deobfuscate_font_resource(xps_document *doc, xps_part *part)
{
unsigned char buf[33];
unsigned char key[16];
char *p;
int i;
p = strrchr(part->name, '/');
if (!p)
p = part->name;
for (i = 0; i < 32 && *p; p++)
{
if (ishex(*p))
buf[i++] = *p;
}
buf[i] = 0;
if (i != 32)
{
fz_warn(doc->ctx, "cannot extract GUID from obfuscated font part name");
return;
}
for (i = 0; i < 16; i++)
key[i] = unhex(buf[i*2+0]) * 16 + unhex(buf[i*2+1]);
for (i = 0; i < 16; i++)
{
part->data[i] ^= key[15-i];
part->data[i+16] ^= key[15-i];
}
}
| @@ -590,7 +590,7 @@ xps_parse_glyphs(xps_document *doc, const fz_matrix *ctm,
if (fill_att)
{
- float samples[32];
+ float samples[FZ_MAX_COLORS];
fz_colorspace *colorspace;
xps_parse_color(doc, base_uri, fill_att, &colorspace, samples); | CWE-119 | null | null |
10,532 | xps_encode_font_char(fz_font *font, int code)
{
FT_Face face = font->ft_face;
int gid = FT_Get_Char_Index(face, code);
if (gid == 0 && face->charmap && face->charmap->platform_id == 3 && face->charmap->encoding_id == 0)
gid = FT_Get_Char_Index(face, 0xF000 | code);
return gid;
}
| Exec Code Overflow | 0 | xps_encode_font_char(fz_font *font, int code)
{
FT_Face face = font->ft_face;
int gid = FT_Get_Char_Index(face, code);
if (gid == 0 && face->charmap && face->charmap->platform_id == 3 && face->charmap->encoding_id == 0)
gid = FT_Get_Char_Index(face, 0xF000 | code);
return gid;
}
| @@ -590,7 +590,7 @@ xps_parse_glyphs(xps_document *doc, const fz_matrix *ctm,
if (fill_att)
{
- float samples[32];
+ float samples[FZ_MAX_COLORS];
fz_colorspace *colorspace;
xps_parse_color(doc, base_uri, fill_att, &colorspace, samples); | CWE-119 | null | null |
10,533 | xps_identify_font_encoding(fz_font *font, int idx, int *pid, int *eid)
{
FT_Face face = font->ft_face;
*pid = face->charmaps[idx]->platform_id;
*eid = face->charmaps[idx]->encoding_id;
}
| Exec Code Overflow | 0 | xps_identify_font_encoding(fz_font *font, int idx, int *pid, int *eid)
{
FT_Face face = font->ft_face;
*pid = face->charmaps[idx]->platform_id;
*eid = face->charmaps[idx]->encoding_id;
}
| @@ -590,7 +590,7 @@ xps_parse_glyphs(xps_document *doc, const fz_matrix *ctm,
if (fill_att)
{
- float samples[32];
+ float samples[FZ_MAX_COLORS];
fz_colorspace *colorspace;
xps_parse_color(doc, base_uri, fill_att, &colorspace, samples); | CWE-119 | null | null |
10,534 | xps_lookup_font(xps_document *doc, char *name)
{
xps_font_cache *cache;
for (cache = doc->font_table; cache; cache = cache->next)
if (!xps_strcasecmp(cache->name, name))
return fz_keep_font(doc->ctx, cache->font);
return NULL;
}
| Exec Code Overflow | 0 | xps_lookup_font(xps_document *doc, char *name)
{
xps_font_cache *cache;
for (cache = doc->font_table; cache; cache = cache->next)
if (!xps_strcasecmp(cache->name, name))
return fz_keep_font(doc->ctx, cache->font);
return NULL;
}
| @@ -590,7 +590,7 @@ xps_parse_glyphs(xps_document *doc, const fz_matrix *ctm,
if (fill_att)
{
- float samples[32];
+ float samples[FZ_MAX_COLORS];
fz_colorspace *colorspace;
xps_parse_color(doc, base_uri, fill_att, &colorspace, samples); | CWE-119 | null | null |
10,535 | xps_measure_font_glyph(xps_document *doc, fz_font *font, int gid, xps_glyph_metrics *mtx)
{
int mask = FT_LOAD_NO_SCALE | FT_LOAD_IGNORE_TRANSFORM;
FT_Face face = font->ft_face;
FT_Fixed hadv, vadv;
fz_context *ctx = doc->ctx;
fz_lock(ctx, FZ_LOCK_FREETYPE);
FT_Get_Advance(face, gid, mask, &hadv);
FT_Get_Advance(face, gid, mask | FT_LOAD_VERTICAL_LAYOUT, &vadv);
fz_unlock(ctx, FZ_LOCK_FREETYPE);
mtx->hadv = hadv / (float)face->units_per_EM;
mtx->vadv = vadv / (float)face->units_per_EM;
mtx->vorg = face->ascender / (float) face->units_per_EM;
}
| Exec Code Overflow | 0 | xps_measure_font_glyph(xps_document *doc, fz_font *font, int gid, xps_glyph_metrics *mtx)
{
int mask = FT_LOAD_NO_SCALE | FT_LOAD_IGNORE_TRANSFORM;
FT_Face face = font->ft_face;
FT_Fixed hadv, vadv;
fz_context *ctx = doc->ctx;
fz_lock(ctx, FZ_LOCK_FREETYPE);
FT_Get_Advance(face, gid, mask, &hadv);
FT_Get_Advance(face, gid, mask | FT_LOAD_VERTICAL_LAYOUT, &vadv);
fz_unlock(ctx, FZ_LOCK_FREETYPE);
mtx->hadv = hadv / (float)face->units_per_EM;
mtx->vadv = vadv / (float)face->units_per_EM;
mtx->vorg = face->ascender / (float) face->units_per_EM;
}
| @@ -590,7 +590,7 @@ xps_parse_glyphs(xps_document *doc, const fz_matrix *ctm,
if (fill_att)
{
- float samples[32];
+ float samples[FZ_MAX_COLORS];
fz_colorspace *colorspace;
xps_parse_color(doc, base_uri, fill_att, &colorspace, samples); | CWE-119 | null | null |
10,536 | xps_parse_cluster_mapping(char *s, int *code_count, int *glyph_count)
{
if (*s == '(')
s = xps_parse_digits(s + 1, code_count);
if (*s == ':')
s = xps_parse_digits(s + 1, glyph_count);
if (*s == ')')
s ++;
return s;
}
| Exec Code Overflow | 0 | xps_parse_cluster_mapping(char *s, int *code_count, int *glyph_count)
{
if (*s == '(')
s = xps_parse_digits(s + 1, code_count);
if (*s == ':')
s = xps_parse_digits(s + 1, glyph_count);
if (*s == ')')
s ++;
return s;
}
| @@ -590,7 +590,7 @@ xps_parse_glyphs(xps_document *doc, const fz_matrix *ctm,
if (fill_att)
{
- float samples[32];
+ float samples[FZ_MAX_COLORS];
fz_colorspace *colorspace;
xps_parse_color(doc, base_uri, fill_att, &colorspace, samples); | CWE-119 | null | null |
10,537 | xps_parse_glyph_index(char *s, int *glyph_index)
{
if (*s >= '0' && *s <= '9')
s = xps_parse_digits(s, glyph_index);
return s;
}
| Exec Code Overflow | 0 | xps_parse_glyph_index(char *s, int *glyph_index)
{
if (*s >= '0' && *s <= '9')
s = xps_parse_digits(s, glyph_index);
return s;
}
| @@ -590,7 +590,7 @@ xps_parse_glyphs(xps_document *doc, const fz_matrix *ctm,
if (fill_att)
{
- float samples[32];
+ float samples[FZ_MAX_COLORS];
fz_colorspace *colorspace;
xps_parse_color(doc, base_uri, fill_att, &colorspace, samples); | CWE-119 | null | null |
10,538 | xps_parse_glyph_metrics(char *s, float *advance, float *uofs, float *vofs)
{
if (*s == ',')
s = xps_parse_real_num(s + 1, advance);
if (*s == ',')
s = xps_parse_real_num(s + 1, uofs);
if (*s == ',')
s = xps_parse_real_num(s + 1, vofs);
return s;
}
| Exec Code Overflow | 0 | xps_parse_glyph_metrics(char *s, float *advance, float *uofs, float *vofs)
{
if (*s == ',')
s = xps_parse_real_num(s + 1, advance);
if (*s == ',')
s = xps_parse_real_num(s + 1, uofs);
if (*s == ',')
s = xps_parse_real_num(s + 1, vofs);
return s;
}
| @@ -590,7 +590,7 @@ xps_parse_glyphs(xps_document *doc, const fz_matrix *ctm,
if (fill_att)
{
- float samples[32];
+ float samples[FZ_MAX_COLORS];
fz_colorspace *colorspace;
xps_parse_color(doc, base_uri, fill_att, &colorspace, samples); | CWE-119 | null | null |
10,539 | xps_parse_glyphs_imp(xps_document *doc, const fz_matrix *ctm,
fz_font *font, float size, float originx, float originy,
int is_sideways, int bidi_level,
char *indices, char *unicode)
{
xps_glyph_metrics mtx;
fz_text *text;
fz_matrix tm;
float e, f;
float x = originx;
float y = originy;
char *us = unicode;
char *is = indices;
int un = 0;
if (!unicode && !indices)
fz_warn(doc->ctx, "glyphs element with neither characters nor indices");
if (us)
{
if (us[0] == '{' && us[1] == '}')
us = us + 2;
un = strlen(us);
}
if (is_sideways)
{
fz_pre_scale(fz_rotate(&tm, 90), -size, size);
}
else
fz_scale(&tm, size, -size);
text = fz_new_text(doc->ctx, font, &tm, is_sideways);
while ((us && un > 0) || (is && *is))
{
int char_code = '?';
int code_count = 1;
int glyph_count = 1;
if (is && *is)
{
is = xps_parse_cluster_mapping(is, &code_count, &glyph_count);
}
if (code_count < 1)
code_count = 1;
if (glyph_count < 1)
glyph_count = 1;
/* TODO: add code chars with cluster mappings for text extraction */
while (code_count--)
{
if (us && un > 0)
{
int t = fz_chartorune(&char_code, us);
us += t; un -= t;
}
}
while (glyph_count--)
{
int glyph_index = -1;
float u_offset = 0;
float v_offset = 0;
float advance;
if (is && *is)
is = xps_parse_glyph_index(is, &glyph_index);
if (glyph_index == -1)
glyph_index = xps_encode_font_char(font, char_code);
xps_measure_font_glyph(doc, font, glyph_index, &mtx);
if (is_sideways)
advance = mtx.vadv * 100;
else if (bidi_level & 1)
advance = -mtx.hadv * 100;
else
advance = mtx.hadv * 100;
if (font->ft_bold)
advance *= 1.02f;
if (is && *is)
{
is = xps_parse_glyph_metrics(is, &advance, &u_offset, &v_offset);
if (*is == ';')
is ++;
}
if (bidi_level & 1)
u_offset = -mtx.hadv * 100 - u_offset;
u_offset = u_offset * 0.01f * size;
v_offset = v_offset * 0.01f * size;
if (is_sideways)
{
e = x + u_offset + (mtx.vorg * size);
f = y - v_offset + (mtx.hadv * 0.5f * size);
}
else
{
e = x + u_offset;
f = y - v_offset;
}
fz_add_text(doc->ctx, text, glyph_index, char_code, e, f);
x += advance * 0.01f * size;
}
}
return text;
}
| Exec Code Overflow | 0 | xps_parse_glyphs_imp(xps_document *doc, const fz_matrix *ctm,
fz_font *font, float size, float originx, float originy,
int is_sideways, int bidi_level,
char *indices, char *unicode)
{
xps_glyph_metrics mtx;
fz_text *text;
fz_matrix tm;
float e, f;
float x = originx;
float y = originy;
char *us = unicode;
char *is = indices;
int un = 0;
if (!unicode && !indices)
fz_warn(doc->ctx, "glyphs element with neither characters nor indices");
if (us)
{
if (us[0] == '{' && us[1] == '}')
us = us + 2;
un = strlen(us);
}
if (is_sideways)
{
fz_pre_scale(fz_rotate(&tm, 90), -size, size);
}
else
fz_scale(&tm, size, -size);
text = fz_new_text(doc->ctx, font, &tm, is_sideways);
while ((us && un > 0) || (is && *is))
{
int char_code = '?';
int code_count = 1;
int glyph_count = 1;
if (is && *is)
{
is = xps_parse_cluster_mapping(is, &code_count, &glyph_count);
}
if (code_count < 1)
code_count = 1;
if (glyph_count < 1)
glyph_count = 1;
/* TODO: add code chars with cluster mappings for text extraction */
while (code_count--)
{
if (us && un > 0)
{
int t = fz_chartorune(&char_code, us);
us += t; un -= t;
}
}
while (glyph_count--)
{
int glyph_index = -1;
float u_offset = 0;
float v_offset = 0;
float advance;
if (is && *is)
is = xps_parse_glyph_index(is, &glyph_index);
if (glyph_index == -1)
glyph_index = xps_encode_font_char(font, char_code);
xps_measure_font_glyph(doc, font, glyph_index, &mtx);
if (is_sideways)
advance = mtx.vadv * 100;
else if (bidi_level & 1)
advance = -mtx.hadv * 100;
else
advance = mtx.hadv * 100;
if (font->ft_bold)
advance *= 1.02f;
if (is && *is)
{
is = xps_parse_glyph_metrics(is, &advance, &u_offset, &v_offset);
if (*is == ';')
is ++;
}
if (bidi_level & 1)
u_offset = -mtx.hadv * 100 - u_offset;
u_offset = u_offset * 0.01f * size;
v_offset = v_offset * 0.01f * size;
if (is_sideways)
{
e = x + u_offset + (mtx.vorg * size);
f = y - v_offset + (mtx.hadv * 0.5f * size);
}
else
{
e = x + u_offset;
f = y - v_offset;
}
fz_add_text(doc->ctx, text, glyph_index, char_code, e, f);
x += advance * 0.01f * size;
}
}
return text;
}
| @@ -590,7 +590,7 @@ xps_parse_glyphs(xps_document *doc, const fz_matrix *ctm,
if (fill_att)
{
- float samples[32];
+ float samples[FZ_MAX_COLORS];
fz_colorspace *colorspace;
xps_parse_color(doc, base_uri, fill_att, &colorspace, samples); | CWE-119 | null | null |
10,540 | xps_parse_real_num(char *s, float *number)
{
char buf[64];
char *p = buf;
while (is_real_num_char(*s))
*p++ = *s++;
*p = 0;
if (buf[0])
*number = fz_atof(buf);
return s;
}
| Exec Code Overflow | 0 | xps_parse_real_num(char *s, float *number)
{
char buf[64];
char *p = buf;
while (is_real_num_char(*s))
*p++ = *s++;
*p = 0;
if (buf[0])
*number = fz_atof(buf);
return s;
}
| @@ -590,7 +590,7 @@ xps_parse_glyphs(xps_document *doc, const fz_matrix *ctm,
if (fill_att)
{
- float samples[32];
+ float samples[FZ_MAX_COLORS];
fz_colorspace *colorspace;
xps_parse_color(doc, base_uri, fill_att, &colorspace, samples); | CWE-119 | null | null |
10,541 | xps_select_best_font_encoding(xps_document *doc, fz_font *font)
{
static struct { int pid, eid; } xps_cmap_list[] =
{
{ 3, 10 }, /* Unicode with surrogates */
{ 3, 1 }, /* Unicode without surrogates */
{ 3, 5 }, /* Wansung */
{ 3, 4 }, /* Big5 */
{ 3, 3 }, /* Prc */
{ 3, 2 }, /* ShiftJis */
{ 3, 0 }, /* Symbol */
{ 1, 0 },
{ -1, -1 },
};
int i, k, n, pid, eid;
n = xps_count_font_encodings(font);
for (k = 0; xps_cmap_list[k].pid != -1; k++)
{
for (i = 0; i < n; i++)
{
xps_identify_font_encoding(font, i, &pid, &eid);
if (pid == xps_cmap_list[k].pid && eid == xps_cmap_list[k].eid)
{
xps_select_font_encoding(font, i);
return;
}
}
}
fz_warn(doc->ctx, "cannot find a suitable cmap");
}
| Exec Code Overflow | 0 | xps_select_best_font_encoding(xps_document *doc, fz_font *font)
{
static struct { int pid, eid; } xps_cmap_list[] =
{
{ 3, 10 }, /* Unicode with surrogates */
{ 3, 1 }, /* Unicode without surrogates */
{ 3, 5 }, /* Wansung */
{ 3, 4 }, /* Big5 */
{ 3, 3 }, /* Prc */
{ 3, 2 }, /* ShiftJis */
{ 3, 0 }, /* Symbol */
{ 1, 0 },
{ -1, -1 },
};
int i, k, n, pid, eid;
n = xps_count_font_encodings(font);
for (k = 0; xps_cmap_list[k].pid != -1; k++)
{
for (i = 0; i < n; i++)
{
xps_identify_font_encoding(font, i, &pid, &eid);
if (pid == xps_cmap_list[k].pid && eid == xps_cmap_list[k].eid)
{
xps_select_font_encoding(font, i);
return;
}
}
}
fz_warn(doc->ctx, "cannot find a suitable cmap");
}
| @@ -590,7 +590,7 @@ xps_parse_glyphs(xps_document *doc, const fz_matrix *ctm,
if (fill_att)
{
- float samples[32];
+ float samples[FZ_MAX_COLORS];
fz_colorspace *colorspace;
xps_parse_color(doc, base_uri, fill_att, &colorspace, samples); | CWE-119 | null | null |
10,542 | xps_select_font_encoding(fz_font *font, int idx)
{
FT_Face face = font->ft_face;
FT_Set_Charmap(face, face->charmaps[idx]);
}
| Exec Code Overflow | 0 | xps_select_font_encoding(fz_font *font, int idx)
{
FT_Face face = font->ft_face;
FT_Set_Charmap(face, face->charmaps[idx]);
}
| @@ -590,7 +590,7 @@ xps_parse_glyphs(xps_document *doc, const fz_matrix *ctm,
if (fill_att)
{
- float samples[32];
+ float samples[FZ_MAX_COLORS];
fz_colorspace *colorspace;
xps_parse_color(doc, base_uri, fill_att, &colorspace, samples); | CWE-119 | null | null |
10,543 | static int cmp_stop(const void *a, const void *b)
{
const struct stop *astop = a;
const struct stop *bstop = b;
float diff = astop->offset - bstop->offset;
if (diff < 0)
return -1;
if (diff > 0)
return 1;
return astop->index - bstop->index;
}
| Exec Code Overflow | 0 | static int cmp_stop(const void *a, const void *b)
{
const struct stop *astop = a;
const struct stop *bstop = b;
float diff = astop->offset - bstop->offset;
if (diff < 0)
return -1;
if (diff > 0)
return 1;
return astop->index - bstop->index;
}
| @@ -39,7 +39,7 @@ xps_parse_gradient_stops(xps_document *doc, char *base_uri, fz_xml *node,
struct stop *stops, int maxcount)
{
fz_colorspace *colorspace;
- float sample[8];
+ float sample[FZ_MAX_COLORS];
float rgb[3];
int before, after;
int count; | CWE-119 | null | null |
10,544 | static inline float lerp(float a, float b, float x)
{
return a + (b - a) * x;
}
| Exec Code Overflow | 0 | static inline float lerp(float a, float b, float x)
{
return a + (b - a) * x;
}
| @@ -39,7 +39,7 @@ xps_parse_gradient_stops(xps_document *doc, char *base_uri, fz_xml *node,
struct stop *stops, int maxcount)
{
fz_colorspace *colorspace;
- float sample[8];
+ float sample[FZ_MAX_COLORS];
float rgb[3];
int before, after;
int count; | CWE-119 | null | null |
10,545 | static inline float point_inside_circle(float px, float py, float x, float y, float r)
{
float dx = px - x;
float dy = py - y;
return dx * dx + dy * dy <= r * r;
}
| Exec Code Overflow | 0 | static inline float point_inside_circle(float px, float py, float x, float y, float r)
{
float dx = px - x;
float dy = py - y;
return dx * dx + dy * dy <= r * r;
}
| @@ -39,7 +39,7 @@ xps_parse_gradient_stops(xps_document *doc, char *base_uri, fz_xml *node,
struct stop *stops, int maxcount)
{
fz_colorspace *colorspace;
- float sample[8];
+ float sample[FZ_MAX_COLORS];
float rgb[3];
int before, after;
int count; | CWE-119 | null | null |
10,546 | xps_draw_linear_gradient(xps_document *doc, const fz_matrix *ctm, const fz_rect *area,
struct stop *stops, int count,
fz_xml *root, int spread)
{
float x0, y0, x1, y1;
int i, mi, ma;
float dx, dy, x, y, k;
fz_point p1, p2;
fz_matrix inv;
fz_rect local_area = *area;
char *start_point_att = fz_xml_att(root, "StartPoint");
char *end_point_att = fz_xml_att(root, "EndPoint");
x0 = y0 = 0;
x1 = y1 = 1;
if (start_point_att)
xps_parse_point(start_point_att, &x0, &y0);
if (end_point_att)
xps_parse_point(end_point_att, &x1, &y1);
p1.x = x0; p1.y = y0; p2.x = x1; p2.y = y1;
fz_transform_rect(&local_area, fz_invert_matrix(&inv, ctm));
x = p2.x - p1.x; y = p2.y - p1.y;
k = ((local_area.x0 - p1.x) * x + (local_area.y0 - p1.y) * y) / (x * x + y * y);
mi = floorf(k); ma = ceilf(k);
k = ((local_area.x1 - p1.x) * x + (local_area.y0 - p1.y) * y) / (x * x + y * y);
mi = fz_mini(mi, floorf(k)); ma = fz_maxi(ma, ceilf(k));
k = ((local_area.x0 - p1.x) * x + (local_area.y1 - p1.y) * y) / (x * x + y * y);
mi = fz_mini(mi, floorf(k)); ma = fz_maxi(ma, ceilf(k));
k = ((local_area.x1 - p1.x) * x + (local_area.y1 - p1.y) * y) / (x * x + y * y);
mi = fz_mini(mi, floorf(k)); ma = fz_maxi(ma, ceilf(k));
dx = x1 - x0; dy = y1 - y0;
if (spread == SPREAD_REPEAT)
{
for (i = mi; i < ma; i++)
xps_draw_one_linear_gradient(doc, ctm, stops, count, 0, x0 + i * dx, y0 + i * dy, x1 + i * dx, y1 + i * dy);
}
else if (spread == SPREAD_REFLECT)
{
if ((mi % 2) != 0)
mi--;
for (i = mi; i < ma; i += 2)
{
xps_draw_one_linear_gradient(doc, ctm, stops, count, 0, x0 + i * dx, y0 + i * dy, x1 + i * dx, y1 + i * dy);
xps_draw_one_linear_gradient(doc, ctm, stops, count, 0, x0 + (i + 2) * dx, y0 + (i + 2) * dy, x1 + i * dx, y1 + i * dy);
}
}
else
{
xps_draw_one_linear_gradient(doc, ctm, stops, count, 1, x0, y0, x1, y1);
}
}
| Exec Code Overflow | 0 | xps_draw_linear_gradient(xps_document *doc, const fz_matrix *ctm, const fz_rect *area,
struct stop *stops, int count,
fz_xml *root, int spread)
{
float x0, y0, x1, y1;
int i, mi, ma;
float dx, dy, x, y, k;
fz_point p1, p2;
fz_matrix inv;
fz_rect local_area = *area;
char *start_point_att = fz_xml_att(root, "StartPoint");
char *end_point_att = fz_xml_att(root, "EndPoint");
x0 = y0 = 0;
x1 = y1 = 1;
if (start_point_att)
xps_parse_point(start_point_att, &x0, &y0);
if (end_point_att)
xps_parse_point(end_point_att, &x1, &y1);
p1.x = x0; p1.y = y0; p2.x = x1; p2.y = y1;
fz_transform_rect(&local_area, fz_invert_matrix(&inv, ctm));
x = p2.x - p1.x; y = p2.y - p1.y;
k = ((local_area.x0 - p1.x) * x + (local_area.y0 - p1.y) * y) / (x * x + y * y);
mi = floorf(k); ma = ceilf(k);
k = ((local_area.x1 - p1.x) * x + (local_area.y0 - p1.y) * y) / (x * x + y * y);
mi = fz_mini(mi, floorf(k)); ma = fz_maxi(ma, ceilf(k));
k = ((local_area.x0 - p1.x) * x + (local_area.y1 - p1.y) * y) / (x * x + y * y);
mi = fz_mini(mi, floorf(k)); ma = fz_maxi(ma, ceilf(k));
k = ((local_area.x1 - p1.x) * x + (local_area.y1 - p1.y) * y) / (x * x + y * y);
mi = fz_mini(mi, floorf(k)); ma = fz_maxi(ma, ceilf(k));
dx = x1 - x0; dy = y1 - y0;
if (spread == SPREAD_REPEAT)
{
for (i = mi; i < ma; i++)
xps_draw_one_linear_gradient(doc, ctm, stops, count, 0, x0 + i * dx, y0 + i * dy, x1 + i * dx, y1 + i * dy);
}
else if (spread == SPREAD_REFLECT)
{
if ((mi % 2) != 0)
mi--;
for (i = mi; i < ma; i += 2)
{
xps_draw_one_linear_gradient(doc, ctm, stops, count, 0, x0 + i * dx, y0 + i * dy, x1 + i * dx, y1 + i * dy);
xps_draw_one_linear_gradient(doc, ctm, stops, count, 0, x0 + (i + 2) * dx, y0 + (i + 2) * dy, x1 + i * dx, y1 + i * dy);
}
}
else
{
xps_draw_one_linear_gradient(doc, ctm, stops, count, 1, x0, y0, x1, y1);
}
}
| @@ -39,7 +39,7 @@ xps_parse_gradient_stops(xps_document *doc, char *base_uri, fz_xml *node,
struct stop *stops, int maxcount)
{
fz_colorspace *colorspace;
- float sample[8];
+ float sample[FZ_MAX_COLORS];
float rgb[3];
int before, after;
int count; | CWE-119 | null | null |
10,547 | xps_draw_one_linear_gradient(xps_document *doc, const fz_matrix *ctm,
struct stop *stops, int count,
int extend,
float x0, float y0, float x1, float y1)
{
fz_shade *shade;
/* TODO: this (and the stuff in pdf_shade) should move to res_shade.c */
shade = fz_malloc_struct(doc->ctx, fz_shade);
FZ_INIT_STORABLE(shade, 1, fz_free_shade_imp);
shade->colorspace = fz_device_rgb(doc->ctx);
shade->bbox = fz_infinite_rect;
shade->matrix = fz_identity;
shade->use_background = 0;
shade->use_function = 1;
shade->type = FZ_LINEAR;
shade->u.l_or_r.extend[0] = extend;
shade->u.l_or_r.extend[1] = extend;
xps_sample_gradient_stops(shade, stops, count);
shade->u.l_or_r.coords[0][0] = x0;
shade->u.l_or_r.coords[0][1] = y0;
shade->u.l_or_r.coords[0][2] = 0;
shade->u.l_or_r.coords[1][0] = x1;
shade->u.l_or_r.coords[1][1] = y1;
shade->u.l_or_r.coords[1][2] = 0;
fz_fill_shade(doc->dev, shade, ctm, doc->opacity[doc->opacity_top]);
fz_drop_shade(doc->ctx, shade);
}
| Exec Code Overflow | 0 | xps_draw_one_linear_gradient(xps_document *doc, const fz_matrix *ctm,
struct stop *stops, int count,
int extend,
float x0, float y0, float x1, float y1)
{
fz_shade *shade;
/* TODO: this (and the stuff in pdf_shade) should move to res_shade.c */
shade = fz_malloc_struct(doc->ctx, fz_shade);
FZ_INIT_STORABLE(shade, 1, fz_free_shade_imp);
shade->colorspace = fz_device_rgb(doc->ctx);
shade->bbox = fz_infinite_rect;
shade->matrix = fz_identity;
shade->use_background = 0;
shade->use_function = 1;
shade->type = FZ_LINEAR;
shade->u.l_or_r.extend[0] = extend;
shade->u.l_or_r.extend[1] = extend;
xps_sample_gradient_stops(shade, stops, count);
shade->u.l_or_r.coords[0][0] = x0;
shade->u.l_or_r.coords[0][1] = y0;
shade->u.l_or_r.coords[0][2] = 0;
shade->u.l_or_r.coords[1][0] = x1;
shade->u.l_or_r.coords[1][1] = y1;
shade->u.l_or_r.coords[1][2] = 0;
fz_fill_shade(doc->dev, shade, ctm, doc->opacity[doc->opacity_top]);
fz_drop_shade(doc->ctx, shade);
}
| @@ -39,7 +39,7 @@ xps_parse_gradient_stops(xps_document *doc, char *base_uri, fz_xml *node,
struct stop *stops, int maxcount)
{
fz_colorspace *colorspace;
- float sample[8];
+ float sample[FZ_MAX_COLORS];
float rgb[3];
int before, after;
int count; | CWE-119 | null | null |
10,548 | xps_draw_radial_gradient(xps_document *doc, const fz_matrix *ctm, const fz_rect *area,
struct stop *stops, int count,
fz_xml *root, int spread)
{
float x0, y0, r0;
float x1, y1, r1;
float xrad = 1;
float yrad = 1;
float invscale;
int i, ma = 1;
fz_matrix local_ctm = *ctm;
fz_matrix inv;
fz_rect local_area = *area;
char *center_att = fz_xml_att(root, "Center");
char *origin_att = fz_xml_att(root, "GradientOrigin");
char *radius_x_att = fz_xml_att(root, "RadiusX");
char *radius_y_att = fz_xml_att(root, "RadiusY");
x0 = y0 = 0.0;
x1 = y1 = 1.0;
xrad = 1.0;
yrad = 1.0;
if (origin_att)
xps_parse_point(origin_att, &x0, &y0);
if (center_att)
xps_parse_point(center_att, &x1, &y1);
if (radius_x_att)
xrad = fz_atof(radius_x_att);
if (radius_y_att)
yrad = fz_atof(radius_y_att);
xrad = fz_max(0.01f, xrad);
yrad = fz_max(0.01f, yrad);
/* scale the ctm to make ellipses */
if (fz_abs(xrad) > FLT_EPSILON)
{
fz_pre_scale(&local_ctm, 1, yrad/xrad);
}
if (yrad != 0.0)
{
invscale = xrad / yrad;
y0 = y0 * invscale;
y1 = y1 * invscale;
}
r0 = 0;
r1 = xrad;
fz_transform_rect(&local_area, fz_invert_matrix(&inv, &local_ctm));
ma = fz_maxi(ma, ceilf(hypotf(local_area.x0 - x0, local_area.y0 - y0) / xrad));
ma = fz_maxi(ma, ceilf(hypotf(local_area.x1 - x0, local_area.y0 - y0) / xrad));
ma = fz_maxi(ma, ceilf(hypotf(local_area.x0 - x0, local_area.y1 - y0) / xrad));
ma = fz_maxi(ma, ceilf(hypotf(local_area.x1 - x0, local_area.y1 - y0) / xrad));
if (spread == SPREAD_REPEAT)
{
for (i = ma - 1; i >= 0; i--)
xps_draw_one_radial_gradient(doc, &local_ctm, stops, count, 0, x0, y0, r0 + i * xrad, x1, y1, r1 + i * xrad);
}
else if (spread == SPREAD_REFLECT)
{
if ((ma % 2) != 0)
ma++;
for (i = ma - 2; i >= 0; i -= 2)
{
xps_draw_one_radial_gradient(doc, &local_ctm, stops, count, 0, x0, y0, r0 + i * xrad, x1, y1, r1 + i * xrad);
xps_draw_one_radial_gradient(doc, &local_ctm, stops, count, 0, x0, y0, r0 + (i + 2) * xrad, x1, y1, r1 + i * xrad);
}
}
else
{
xps_draw_one_radial_gradient(doc, &local_ctm, stops, count, 1, x0, y0, r0, x1, y1, r1);
}
}
| Exec Code Overflow | 0 | xps_draw_radial_gradient(xps_document *doc, const fz_matrix *ctm, const fz_rect *area,
struct stop *stops, int count,
fz_xml *root, int spread)
{
float x0, y0, r0;
float x1, y1, r1;
float xrad = 1;
float yrad = 1;
float invscale;
int i, ma = 1;
fz_matrix local_ctm = *ctm;
fz_matrix inv;
fz_rect local_area = *area;
char *center_att = fz_xml_att(root, "Center");
char *origin_att = fz_xml_att(root, "GradientOrigin");
char *radius_x_att = fz_xml_att(root, "RadiusX");
char *radius_y_att = fz_xml_att(root, "RadiusY");
x0 = y0 = 0.0;
x1 = y1 = 1.0;
xrad = 1.0;
yrad = 1.0;
if (origin_att)
xps_parse_point(origin_att, &x0, &y0);
if (center_att)
xps_parse_point(center_att, &x1, &y1);
if (radius_x_att)
xrad = fz_atof(radius_x_att);
if (radius_y_att)
yrad = fz_atof(radius_y_att);
xrad = fz_max(0.01f, xrad);
yrad = fz_max(0.01f, yrad);
/* scale the ctm to make ellipses */
if (fz_abs(xrad) > FLT_EPSILON)
{
fz_pre_scale(&local_ctm, 1, yrad/xrad);
}
if (yrad != 0.0)
{
invscale = xrad / yrad;
y0 = y0 * invscale;
y1 = y1 * invscale;
}
r0 = 0;
r1 = xrad;
fz_transform_rect(&local_area, fz_invert_matrix(&inv, &local_ctm));
ma = fz_maxi(ma, ceilf(hypotf(local_area.x0 - x0, local_area.y0 - y0) / xrad));
ma = fz_maxi(ma, ceilf(hypotf(local_area.x1 - x0, local_area.y0 - y0) / xrad));
ma = fz_maxi(ma, ceilf(hypotf(local_area.x0 - x0, local_area.y1 - y0) / xrad));
ma = fz_maxi(ma, ceilf(hypotf(local_area.x1 - x0, local_area.y1 - y0) / xrad));
if (spread == SPREAD_REPEAT)
{
for (i = ma - 1; i >= 0; i--)
xps_draw_one_radial_gradient(doc, &local_ctm, stops, count, 0, x0, y0, r0 + i * xrad, x1, y1, r1 + i * xrad);
}
else if (spread == SPREAD_REFLECT)
{
if ((ma % 2) != 0)
ma++;
for (i = ma - 2; i >= 0; i -= 2)
{
xps_draw_one_radial_gradient(doc, &local_ctm, stops, count, 0, x0, y0, r0 + i * xrad, x1, y1, r1 + i * xrad);
xps_draw_one_radial_gradient(doc, &local_ctm, stops, count, 0, x0, y0, r0 + (i + 2) * xrad, x1, y1, r1 + i * xrad);
}
}
else
{
xps_draw_one_radial_gradient(doc, &local_ctm, stops, count, 1, x0, y0, r0, x1, y1, r1);
}
}
| @@ -39,7 +39,7 @@ xps_parse_gradient_stops(xps_document *doc, char *base_uri, fz_xml *node,
struct stop *stops, int maxcount)
{
fz_colorspace *colorspace;
- float sample[8];
+ float sample[FZ_MAX_COLORS];
float rgb[3];
int before, after;
int count; | CWE-119 | null | null |
10,549 | xps_parse_gradient_brush(xps_document *doc, const fz_matrix *ctm, const fz_rect *area,
char *base_uri, xps_resource *dict, fz_xml *root,
void (*draw)(xps_document *, const fz_matrix*, const fz_rect *, struct stop *, int, fz_xml *, int))
{
fz_xml *node;
char *opacity_att;
char *spread_att;
char *transform_att;
fz_xml *transform_tag = NULL;
fz_xml *stop_tag = NULL;
struct stop stop_list[MAX_STOPS];
int stop_count;
fz_matrix transform;
int spread_method;
opacity_att = fz_xml_att(root, "Opacity");
spread_att = fz_xml_att(root, "SpreadMethod");
transform_att = fz_xml_att(root, "Transform");
for (node = fz_xml_down(root); node; node = fz_xml_next(node))
{
if (!strcmp(fz_xml_tag(node), "LinearGradientBrush.Transform"))
transform_tag = fz_xml_down(node);
if (!strcmp(fz_xml_tag(node), "RadialGradientBrush.Transform"))
transform_tag = fz_xml_down(node);
if (!strcmp(fz_xml_tag(node), "LinearGradientBrush.GradientStops"))
stop_tag = fz_xml_down(node);
if (!strcmp(fz_xml_tag(node), "RadialGradientBrush.GradientStops"))
stop_tag = fz_xml_down(node);
}
xps_resolve_resource_reference(doc, dict, &transform_att, &transform_tag, NULL);
spread_method = SPREAD_PAD;
if (spread_att)
{
if (!strcmp(spread_att, "Pad"))
spread_method = SPREAD_PAD;
if (!strcmp(spread_att, "Reflect"))
spread_method = SPREAD_REFLECT;
if (!strcmp(spread_att, "Repeat"))
spread_method = SPREAD_REPEAT;
}
transform = fz_identity;
if (transform_att)
xps_parse_render_transform(doc, transform_att, &transform);
if (transform_tag)
xps_parse_matrix_transform(doc, transform_tag, &transform);
fz_concat(&transform, &transform, ctm);
if (!stop_tag) {
fz_warn(doc->ctx, "missing gradient stops tag");
return;
}
stop_count = xps_parse_gradient_stops(doc, base_uri, stop_tag, stop_list, MAX_STOPS);
if (stop_count == 0)
{
fz_warn(doc->ctx, "no gradient stops found");
return;
}
xps_begin_opacity(doc, &transform, area, base_uri, dict, opacity_att, NULL);
draw(doc, &transform, area, stop_list, stop_count, root, spread_method);
xps_end_opacity(doc, base_uri, dict, opacity_att, NULL);
}
| Exec Code Overflow | 0 | xps_parse_gradient_brush(xps_document *doc, const fz_matrix *ctm, const fz_rect *area,
char *base_uri, xps_resource *dict, fz_xml *root,
void (*draw)(xps_document *, const fz_matrix*, const fz_rect *, struct stop *, int, fz_xml *, int))
{
fz_xml *node;
char *opacity_att;
char *spread_att;
char *transform_att;
fz_xml *transform_tag = NULL;
fz_xml *stop_tag = NULL;
struct stop stop_list[MAX_STOPS];
int stop_count;
fz_matrix transform;
int spread_method;
opacity_att = fz_xml_att(root, "Opacity");
spread_att = fz_xml_att(root, "SpreadMethod");
transform_att = fz_xml_att(root, "Transform");
for (node = fz_xml_down(root); node; node = fz_xml_next(node))
{
if (!strcmp(fz_xml_tag(node), "LinearGradientBrush.Transform"))
transform_tag = fz_xml_down(node);
if (!strcmp(fz_xml_tag(node), "RadialGradientBrush.Transform"))
transform_tag = fz_xml_down(node);
if (!strcmp(fz_xml_tag(node), "LinearGradientBrush.GradientStops"))
stop_tag = fz_xml_down(node);
if (!strcmp(fz_xml_tag(node), "RadialGradientBrush.GradientStops"))
stop_tag = fz_xml_down(node);
}
xps_resolve_resource_reference(doc, dict, &transform_att, &transform_tag, NULL);
spread_method = SPREAD_PAD;
if (spread_att)
{
if (!strcmp(spread_att, "Pad"))
spread_method = SPREAD_PAD;
if (!strcmp(spread_att, "Reflect"))
spread_method = SPREAD_REFLECT;
if (!strcmp(spread_att, "Repeat"))
spread_method = SPREAD_REPEAT;
}
transform = fz_identity;
if (transform_att)
xps_parse_render_transform(doc, transform_att, &transform);
if (transform_tag)
xps_parse_matrix_transform(doc, transform_tag, &transform);
fz_concat(&transform, &transform, ctm);
if (!stop_tag) {
fz_warn(doc->ctx, "missing gradient stops tag");
return;
}
stop_count = xps_parse_gradient_stops(doc, base_uri, stop_tag, stop_list, MAX_STOPS);
if (stop_count == 0)
{
fz_warn(doc->ctx, "no gradient stops found");
return;
}
xps_begin_opacity(doc, &transform, area, base_uri, dict, opacity_att, NULL);
draw(doc, &transform, area, stop_list, stop_count, root, spread_method);
xps_end_opacity(doc, base_uri, dict, opacity_att, NULL);
}
| @@ -39,7 +39,7 @@ xps_parse_gradient_stops(xps_document *doc, char *base_uri, fz_xml *node,
struct stop *stops, int maxcount)
{
fz_colorspace *colorspace;
- float sample[8];
+ float sample[FZ_MAX_COLORS];
float rgb[3];
int before, after;
int count; | CWE-119 | null | null |
10,550 | xps_parse_linear_gradient_brush(xps_document *doc, const fz_matrix *ctm, const fz_rect *area,
char *base_uri, xps_resource *dict, fz_xml *root)
{
xps_parse_gradient_brush(doc, ctm, area, base_uri, dict, root, xps_draw_linear_gradient);
}
| Exec Code Overflow | 0 | xps_parse_linear_gradient_brush(xps_document *doc, const fz_matrix *ctm, const fz_rect *area,
char *base_uri, xps_resource *dict, fz_xml *root)
{
xps_parse_gradient_brush(doc, ctm, area, base_uri, dict, root, xps_draw_linear_gradient);
}
| @@ -39,7 +39,7 @@ xps_parse_gradient_stops(xps_document *doc, char *base_uri, fz_xml *node,
struct stop *stops, int maxcount)
{
fz_colorspace *colorspace;
- float sample[8];
+ float sample[FZ_MAX_COLORS];
float rgb[3];
int before, after;
int count; | CWE-119 | null | null |
10,551 | xps_parse_radial_gradient_brush(xps_document *doc, const fz_matrix *ctm, const fz_rect *area,
char *base_uri, xps_resource *dict, fz_xml *root)
{
xps_parse_gradient_brush(doc, ctm, area, base_uri, dict, root, xps_draw_radial_gradient);
}
| Exec Code Overflow | 0 | xps_parse_radial_gradient_brush(xps_document *doc, const fz_matrix *ctm, const fz_rect *area,
char *base_uri, xps_resource *dict, fz_xml *root)
{
xps_parse_gradient_brush(doc, ctm, area, base_uri, dict, root, xps_draw_radial_gradient);
}
| @@ -39,7 +39,7 @@ xps_parse_gradient_stops(xps_document *doc, char *base_uri, fz_xml *node,
struct stop *stops, int maxcount)
{
fz_colorspace *colorspace;
- float sample[8];
+ float sample[FZ_MAX_COLORS];
float rgb[3];
int before, after;
int count; | CWE-119 | null | null |
10,552 | xps_sample_gradient_stops(fz_shade *shade, struct stop *stops, int count)
{
float offset, d;
int i, k;
k = 0;
for (i = 0; i < 256; i++)
{
offset = i / 255.0f;
while (k + 1 < count && offset > stops[k+1].offset)
k++;
d = (offset - stops[k].offset) / (stops[k+1].offset - stops[k].offset);
shade->function[i][0] = lerp(stops[k].r, stops[k+1].r, d);
shade->function[i][1] = lerp(stops[k].g, stops[k+1].g, d);
shade->function[i][2] = lerp(stops[k].b, stops[k+1].b, d);
shade->function[i][3] = lerp(stops[k].a, stops[k+1].a, d);
}
}
| Exec Code Overflow | 0 | xps_sample_gradient_stops(fz_shade *shade, struct stop *stops, int count)
{
float offset, d;
int i, k;
k = 0;
for (i = 0; i < 256; i++)
{
offset = i / 255.0f;
while (k + 1 < count && offset > stops[k+1].offset)
k++;
d = (offset - stops[k].offset) / (stops[k+1].offset - stops[k].offset);
shade->function[i][0] = lerp(stops[k].r, stops[k+1].r, d);
shade->function[i][1] = lerp(stops[k].g, stops[k+1].g, d);
shade->function[i][2] = lerp(stops[k].b, stops[k+1].b, d);
shade->function[i][3] = lerp(stops[k].a, stops[k+1].a, d);
}
}
| @@ -39,7 +39,7 @@ xps_parse_gradient_stops(xps_document *doc, char *base_uri, fz_xml *node,
struct stop *stops, int maxcount)
{
fz_colorspace *colorspace;
- float sample[8];
+ float sample[FZ_MAX_COLORS];
float rgb[3];
int before, after;
int count; | CWE-119 | null | null |
10,553 | xps_clip(xps_document *doc, const fz_matrix *ctm, xps_resource *dict, char *clip_att, fz_xml *clip_tag)
{
fz_path *path;
int fill_rule = 0;
if (clip_att)
path = xps_parse_abbreviated_geometry(doc, clip_att, &fill_rule);
else if (clip_tag)
path = xps_parse_path_geometry(doc, dict, clip_tag, 0, &fill_rule);
else
path = fz_new_path(doc->ctx);
fz_clip_path(doc->dev, path, NULL, fill_rule == 0, ctm);
fz_free_path(doc->ctx, path);
}
| Exec Code Overflow | 0 | xps_clip(xps_document *doc, const fz_matrix *ctm, xps_resource *dict, char *clip_att, fz_xml *clip_tag)
{
fz_path *path;
int fill_rule = 0;
if (clip_att)
path = xps_parse_abbreviated_geometry(doc, clip_att, &fill_rule);
else if (clip_tag)
path = xps_parse_path_geometry(doc, dict, clip_tag, 0, &fill_rule);
else
path = fz_new_path(doc->ctx);
fz_clip_path(doc->dev, path, NULL, fill_rule == 0, ctm);
fz_free_path(doc->ctx, path);
}
| @@ -826,7 +826,7 @@ xps_parse_path(xps_document *doc, const fz_matrix *ctm, char *base_uri, xps_reso
fz_stroke_state *stroke = NULL;
fz_matrix transform;
- float samples[32];
+ float samples[FZ_MAX_COLORS];
fz_colorspace *colorspace;
fz_path *path = NULL;
fz_path *stroke_path = NULL; | CWE-119 | null | null |
10,554 | xps_draw_arc(fz_context *doc, fz_path *path,
float size_x, float size_y, float rotation_angle,
int is_large_arc, int is_clockwise,
float point_x, float point_y)
{
fz_matrix rotmat, revmat;
fz_matrix mtx;
fz_point pt;
float rx, ry;
float x1, y1, x2, y2;
float x1t, y1t;
float cxt, cyt, cx, cy;
float t1, t2, t3;
float sign;
float th1, dth;
pt = fz_currentpoint(doc, path);
x1 = pt.x;
y1 = pt.y;
x2 = point_x;
y2 = point_y;
rx = size_x;
ry = size_y;
if (is_clockwise != is_large_arc)
sign = 1;
else
sign = -1;
fz_rotate(&rotmat, rotation_angle);
fz_rotate(&revmat, -rotation_angle);
/* http://www.w3.org/TR/SVG11/implnote.html#ArcImplementationNotes */
/* Conversion from endpoint to center parameterization */
/* F.6.6.1 -- ensure radii are positive and non-zero */
rx = fabsf(rx);
ry = fabsf(ry);
if (rx < 0.001f || ry < 0.001f || (x1 == x2 && y1 == y2))
{
fz_lineto(doc, path, x2, y2);
return;
}
/* F.6.5.1 */
pt.x = (x1 - x2) / 2;
pt.y = (y1 - y2) / 2;
fz_transform_vector(&pt, &revmat);
x1t = pt.x;
y1t = pt.y;
/* F.6.6.2 -- ensure radii are large enough */
t1 = (x1t * x1t) / (rx * rx) + (y1t * y1t) / (ry * ry);
if (t1 > 1)
{
rx = rx * sqrtf(t1);
ry = ry * sqrtf(t1);
}
/* F.6.5.2 */
t1 = (rx * rx * ry * ry) - (rx * rx * y1t * y1t) - (ry * ry * x1t * x1t);
t2 = (rx * rx * y1t * y1t) + (ry * ry * x1t * x1t);
t3 = t1 / t2;
/* guard against rounding errors; sqrt of negative numbers is bad for your health */
if (t3 < 0) t3 = 0;
t3 = sqrtf(t3);
cxt = sign * t3 * (rx * y1t) / ry;
cyt = sign * t3 * -(ry * x1t) / rx;
/* F.6.5.3 */
pt.x = cxt;
pt.y = cyt;
fz_transform_vector(&pt, &rotmat);
cx = pt.x + (x1 + x2) / 2;
cy = pt.y + (y1 + y2) / 2;
/* F.6.5.4 */
{
fz_point coord1, coord2, coord3, coord4;
coord1.x = 1;
coord1.y = 0;
coord2.x = (x1t - cxt) / rx;
coord2.y = (y1t - cyt) / ry;
coord3.x = (x1t - cxt) / rx;
coord3.y = (y1t - cyt) / ry;
coord4.x = (-x1t - cxt) / rx;
coord4.y = (-y1t - cyt) / ry;
th1 = angle_between(coord1, coord2);
dth = angle_between(coord3, coord4);
if (dth < 0 && !is_clockwise)
dth += (((float)M_PI / 180) * 360);
if (dth > 0 && is_clockwise)
dth -= (((float)M_PI / 180) * 360);
}
fz_pre_scale(fz_pre_rotate(fz_translate(&mtx, cx, cy), rotation_angle), rx, ry);
xps_draw_arc_segment(doc, path, &mtx, th1, th1 + dth, is_clockwise);
fz_lineto(doc, path, point_x, point_y);
}
| Exec Code Overflow | 0 | xps_draw_arc(fz_context *doc, fz_path *path,
float size_x, float size_y, float rotation_angle,
int is_large_arc, int is_clockwise,
float point_x, float point_y)
{
fz_matrix rotmat, revmat;
fz_matrix mtx;
fz_point pt;
float rx, ry;
float x1, y1, x2, y2;
float x1t, y1t;
float cxt, cyt, cx, cy;
float t1, t2, t3;
float sign;
float th1, dth;
pt = fz_currentpoint(doc, path);
x1 = pt.x;
y1 = pt.y;
x2 = point_x;
y2 = point_y;
rx = size_x;
ry = size_y;
if (is_clockwise != is_large_arc)
sign = 1;
else
sign = -1;
fz_rotate(&rotmat, rotation_angle);
fz_rotate(&revmat, -rotation_angle);
/* http://www.w3.org/TR/SVG11/implnote.html#ArcImplementationNotes */
/* Conversion from endpoint to center parameterization */
/* F.6.6.1 -- ensure radii are positive and non-zero */
rx = fabsf(rx);
ry = fabsf(ry);
if (rx < 0.001f || ry < 0.001f || (x1 == x2 && y1 == y2))
{
fz_lineto(doc, path, x2, y2);
return;
}
/* F.6.5.1 */
pt.x = (x1 - x2) / 2;
pt.y = (y1 - y2) / 2;
fz_transform_vector(&pt, &revmat);
x1t = pt.x;
y1t = pt.y;
/* F.6.6.2 -- ensure radii are large enough */
t1 = (x1t * x1t) / (rx * rx) + (y1t * y1t) / (ry * ry);
if (t1 > 1)
{
rx = rx * sqrtf(t1);
ry = ry * sqrtf(t1);
}
/* F.6.5.2 */
t1 = (rx * rx * ry * ry) - (rx * rx * y1t * y1t) - (ry * ry * x1t * x1t);
t2 = (rx * rx * y1t * y1t) + (ry * ry * x1t * x1t);
t3 = t1 / t2;
/* guard against rounding errors; sqrt of negative numbers is bad for your health */
if (t3 < 0) t3 = 0;
t3 = sqrtf(t3);
cxt = sign * t3 * (rx * y1t) / ry;
cyt = sign * t3 * -(ry * x1t) / rx;
/* F.6.5.3 */
pt.x = cxt;
pt.y = cyt;
fz_transform_vector(&pt, &rotmat);
cx = pt.x + (x1 + x2) / 2;
cy = pt.y + (y1 + y2) / 2;
/* F.6.5.4 */
{
fz_point coord1, coord2, coord3, coord4;
coord1.x = 1;
coord1.y = 0;
coord2.x = (x1t - cxt) / rx;
coord2.y = (y1t - cyt) / ry;
coord3.x = (x1t - cxt) / rx;
coord3.y = (y1t - cyt) / ry;
coord4.x = (-x1t - cxt) / rx;
coord4.y = (-y1t - cyt) / ry;
th1 = angle_between(coord1, coord2);
dth = angle_between(coord3, coord4);
if (dth < 0 && !is_clockwise)
dth += (((float)M_PI / 180) * 360);
if (dth > 0 && is_clockwise)
dth -= (((float)M_PI / 180) * 360);
}
fz_pre_scale(fz_pre_rotate(fz_translate(&mtx, cx, cy), rotation_angle), rx, ry);
xps_draw_arc_segment(doc, path, &mtx, th1, th1 + dth, is_clockwise);
fz_lineto(doc, path, point_x, point_y);
}
| @@ -826,7 +826,7 @@ xps_parse_path(xps_document *doc, const fz_matrix *ctm, char *base_uri, xps_reso
fz_stroke_state *stroke = NULL;
fz_matrix transform;
- float samples[32];
+ float samples[FZ_MAX_COLORS];
fz_colorspace *colorspace;
fz_path *path = NULL;
fz_path *stroke_path = NULL; | CWE-119 | null | null |
10,555 | xps_draw_arc_segment(fz_context *doc, fz_path *path, const fz_matrix *mtx, float th0, float th1, int iscw)
{
float t, d;
fz_point p;
while (th1 < th0)
th1 += (float)M_PI * 2;
d = (float)M_PI / 180; /* 1-degree precision */
if (iscw)
{
for (t = th0 + d; t < th1 - d/2; t += d)
{
p.x = cosf(t);
p.y = sinf(t);
fz_transform_point(&p, mtx);
fz_lineto(doc, path, p.x, p.y);
}
}
else
{
th0 += (float)M_PI * 2;
for (t = th0 - d; t > th1 + d/2; t -= d)
{
p.x = cosf(t);
p.y = sinf(t);
fz_transform_point(&p, mtx);
fz_lineto(doc, path, p.x, p.y);
}
}
}
| Exec Code Overflow | 0 | xps_draw_arc_segment(fz_context *doc, fz_path *path, const fz_matrix *mtx, float th0, float th1, int iscw)
{
float t, d;
fz_point p;
while (th1 < th0)
th1 += (float)M_PI * 2;
d = (float)M_PI / 180; /* 1-degree precision */
if (iscw)
{
for (t = th0 + d; t < th1 - d/2; t += d)
{
p.x = cosf(t);
p.y = sinf(t);
fz_transform_point(&p, mtx);
fz_lineto(doc, path, p.x, p.y);
}
}
else
{
th0 += (float)M_PI * 2;
for (t = th0 - d; t > th1 + d/2; t -= d)
{
p.x = cosf(t);
p.y = sinf(t);
fz_transform_point(&p, mtx);
fz_lineto(doc, path, p.x, p.y);
}
}
}
| @@ -826,7 +826,7 @@ xps_parse_path(xps_document *doc, const fz_matrix *ctm, char *base_uri, xps_reso
fz_stroke_state *stroke = NULL;
fz_matrix transform;
- float samples[32];
+ float samples[FZ_MAX_COLORS];
fz_colorspace *colorspace;
fz_path *path = NULL;
fz_path *stroke_path = NULL; | CWE-119 | null | null |
10,556 | xps_parse_abbreviated_geometry(xps_document *doc, char *geom, int *fill_rule)
{
fz_path *path;
char **args;
char **pargs;
char *s = geom;
fz_point pt;
int i, n;
int cmd, old;
float x1, y1, x2, y2, x3, y3;
float smooth_x, smooth_y; /* saved cubic bezier control point for smooth curves */
int reset_smooth;
path = fz_new_path(doc->ctx);
args = fz_malloc_array(doc->ctx, strlen(geom) + 1, sizeof(char*));
pargs = args;
while (*s)
{
if ((*s >= 'A' && *s <= 'Z') || (*s >= 'a' && *s <= 'z'))
{
*pargs++ = s++;
}
else if ((*s >= '0' && *s <= '9') || *s == '.' || *s == '+' || *s == '-' || *s == 'e' || *s == 'E')
{
*pargs++ = s;
while ((*s >= '0' && *s <= '9') || *s == '.' || *s == '+' || *s == '-' || *s == 'e' || *s == 'E')
s ++;
}
else
{
s++;
}
}
*pargs = s;
n = pargs - args;
i = 0;
old = 0;
reset_smooth = 1;
smooth_x = 0;
smooth_y = 0;
while (i < n)
{
cmd = args[i][0];
if (cmd == '+' || cmd == '.' || cmd == '-' || (cmd >= '0' && cmd <= '9'))
cmd = old; /* it's a number, repeat old command */
else
i ++;
if (reset_smooth)
{
smooth_x = 0;
smooth_y = 0;
}
reset_smooth = 1;
switch (cmd)
{
case 'F':
if (i >= n) break;
*fill_rule = atoi(args[i]);
i ++;
break;
case 'M':
if (i + 1 >= n) break;
fz_moveto(doc->ctx, path, fz_atof(args[i]), fz_atof(args[i+1]));
i += 2;
break;
case 'm':
if (i + 1 >= n) break;
pt = fz_currentpoint(doc->ctx, path);
fz_moveto(doc->ctx, path, pt.x + fz_atof(args[i]), pt.y + fz_atof(args[i+1]));
i += 2;
break;
case 'L':
if (i + 1 >= n) break;
fz_lineto(doc->ctx, path, fz_atof(args[i]), fz_atof(args[i+1]));
i += 2;
break;
case 'l':
if (i + 1 >= n) break;
pt = fz_currentpoint(doc->ctx, path);
fz_lineto(doc->ctx, path, pt.x + fz_atof(args[i]), pt.y + fz_atof(args[i+1]));
i += 2;
break;
case 'H':
if (i >= n) break;
pt = fz_currentpoint(doc->ctx, path);
fz_lineto(doc->ctx, path, fz_atof(args[i]), pt.y);
i += 1;
break;
case 'h':
if (i >= n) break;
pt = fz_currentpoint(doc->ctx, path);
fz_lineto(doc->ctx, path, pt.x + fz_atof(args[i]), pt.y);
i += 1;
break;
case 'V':
if (i >= n) break;
pt = fz_currentpoint(doc->ctx, path);
fz_lineto(doc->ctx, path, pt.x, fz_atof(args[i]));
i += 1;
break;
case 'v':
if (i >= n) break;
pt = fz_currentpoint(doc->ctx, path);
fz_lineto(doc->ctx, path, pt.x, pt.y + fz_atof(args[i]));
i += 1;
break;
case 'C':
if (i + 5 >= n) break;
x1 = fz_atof(args[i+0]);
y1 = fz_atof(args[i+1]);
x2 = fz_atof(args[i+2]);
y2 = fz_atof(args[i+3]);
x3 = fz_atof(args[i+4]);
y3 = fz_atof(args[i+5]);
fz_curveto(doc->ctx, path, x1, y1, x2, y2, x3, y3);
i += 6;
reset_smooth = 0;
smooth_x = x3 - x2;
smooth_y = y3 - y2;
break;
case 'c':
if (i + 5 >= n) break;
pt = fz_currentpoint(doc->ctx, path);
x1 = fz_atof(args[i+0]) + pt.x;
y1 = fz_atof(args[i+1]) + pt.y;
x2 = fz_atof(args[i+2]) + pt.x;
y2 = fz_atof(args[i+3]) + pt.y;
x3 = fz_atof(args[i+4]) + pt.x;
y3 = fz_atof(args[i+5]) + pt.y;
fz_curveto(doc->ctx, path, x1, y1, x2, y2, x3, y3);
i += 6;
reset_smooth = 0;
smooth_x = x3 - x2;
smooth_y = y3 - y2;
break;
case 'S':
if (i + 3 >= n) break;
pt = fz_currentpoint(doc->ctx, path);
x1 = fz_atof(args[i+0]);
y1 = fz_atof(args[i+1]);
x2 = fz_atof(args[i+2]);
y2 = fz_atof(args[i+3]);
fz_curveto(doc->ctx, path, pt.x + smooth_x, pt.y + smooth_y, x1, y1, x2, y2);
i += 4;
reset_smooth = 0;
smooth_x = x2 - x1;
smooth_y = y2 - y1;
break;
case 's':
if (i + 3 >= n) break;
pt = fz_currentpoint(doc->ctx, path);
x1 = fz_atof(args[i+0]) + pt.x;
y1 = fz_atof(args[i+1]) + pt.y;
x2 = fz_atof(args[i+2]) + pt.x;
y2 = fz_atof(args[i+3]) + pt.y;
fz_curveto(doc->ctx, path, pt.x + smooth_x, pt.y + smooth_y, x1, y1, x2, y2);
i += 4;
reset_smooth = 0;
smooth_x = x2 - x1;
smooth_y = y2 - y1;
break;
case 'Q':
if (i + 3 >= n) break;
pt = fz_currentpoint(doc->ctx, path);
x1 = fz_atof(args[i+0]);
y1 = fz_atof(args[i+1]);
x2 = fz_atof(args[i+2]);
y2 = fz_atof(args[i+3]);
fz_curveto(doc->ctx, path,
(pt.x + 2 * x1) / 3, (pt.y + 2 * y1) / 3,
(x2 + 2 * x1) / 3, (y2 + 2 * y1) / 3,
x2, y2);
i += 4;
break;
case 'q':
if (i + 3 >= n) break;
pt = fz_currentpoint(doc->ctx, path);
x1 = fz_atof(args[i+0]) + pt.x;
y1 = fz_atof(args[i+1]) + pt.y;
x2 = fz_atof(args[i+2]) + pt.x;
y2 = fz_atof(args[i+3]) + pt.y;
fz_curveto(doc->ctx, path,
(pt.x + 2 * x1) / 3, (pt.y + 2 * y1) / 3,
(x2 + 2 * x1) / 3, (y2 + 2 * y1) / 3,
x2, y2);
i += 4;
break;
case 'A':
if (i + 6 >= n) break;
xps_draw_arc(doc->ctx, path,
fz_atof(args[i+0]), fz_atof(args[i+1]), fz_atof(args[i+2]),
atoi(args[i+3]), atoi(args[i+4]),
fz_atof(args[i+5]), fz_atof(args[i+6]));
i += 7;
break;
case 'a':
if (i + 6 >= n) break;
pt = fz_currentpoint(doc->ctx, path);
xps_draw_arc(doc->ctx, path,
fz_atof(args[i+0]), fz_atof(args[i+1]), fz_atof(args[i+2]),
atoi(args[i+3]), atoi(args[i+4]),
fz_atof(args[i+5]) + pt.x, fz_atof(args[i+6]) + pt.y);
i += 7;
break;
case 'Z':
case 'z':
fz_closepath(doc->ctx, path);
break;
default:
/* eek */
fz_warn(doc->ctx, "ignoring invalid command '%c'", cmd);
/* Skip any trailing numbers to avoid an infinite loop */
while (i < n && (args[i][0] == '+' || args[i][0] == '.' || args[i][0] == '-' || (args[i][0] >= '0' && args[i][0] <= '9')))
i ++;
break;
}
old = cmd;
}
fz_free(doc->ctx, args);
return path;
}
| Exec Code Overflow | 0 | xps_parse_abbreviated_geometry(xps_document *doc, char *geom, int *fill_rule)
{
fz_path *path;
char **args;
char **pargs;
char *s = geom;
fz_point pt;
int i, n;
int cmd, old;
float x1, y1, x2, y2, x3, y3;
float smooth_x, smooth_y; /* saved cubic bezier control point for smooth curves */
int reset_smooth;
path = fz_new_path(doc->ctx);
args = fz_malloc_array(doc->ctx, strlen(geom) + 1, sizeof(char*));
pargs = args;
while (*s)
{
if ((*s >= 'A' && *s <= 'Z') || (*s >= 'a' && *s <= 'z'))
{
*pargs++ = s++;
}
else if ((*s >= '0' && *s <= '9') || *s == '.' || *s == '+' || *s == '-' || *s == 'e' || *s == 'E')
{
*pargs++ = s;
while ((*s >= '0' && *s <= '9') || *s == '.' || *s == '+' || *s == '-' || *s == 'e' || *s == 'E')
s ++;
}
else
{
s++;
}
}
*pargs = s;
n = pargs - args;
i = 0;
old = 0;
reset_smooth = 1;
smooth_x = 0;
smooth_y = 0;
while (i < n)
{
cmd = args[i][0];
if (cmd == '+' || cmd == '.' || cmd == '-' || (cmd >= '0' && cmd <= '9'))
cmd = old; /* it's a number, repeat old command */
else
i ++;
if (reset_smooth)
{
smooth_x = 0;
smooth_y = 0;
}
reset_smooth = 1;
switch (cmd)
{
case 'F':
if (i >= n) break;
*fill_rule = atoi(args[i]);
i ++;
break;
case 'M':
if (i + 1 >= n) break;
fz_moveto(doc->ctx, path, fz_atof(args[i]), fz_atof(args[i+1]));
i += 2;
break;
case 'm':
if (i + 1 >= n) break;
pt = fz_currentpoint(doc->ctx, path);
fz_moveto(doc->ctx, path, pt.x + fz_atof(args[i]), pt.y + fz_atof(args[i+1]));
i += 2;
break;
case 'L':
if (i + 1 >= n) break;
fz_lineto(doc->ctx, path, fz_atof(args[i]), fz_atof(args[i+1]));
i += 2;
break;
case 'l':
if (i + 1 >= n) break;
pt = fz_currentpoint(doc->ctx, path);
fz_lineto(doc->ctx, path, pt.x + fz_atof(args[i]), pt.y + fz_atof(args[i+1]));
i += 2;
break;
case 'H':
if (i >= n) break;
pt = fz_currentpoint(doc->ctx, path);
fz_lineto(doc->ctx, path, fz_atof(args[i]), pt.y);
i += 1;
break;
case 'h':
if (i >= n) break;
pt = fz_currentpoint(doc->ctx, path);
fz_lineto(doc->ctx, path, pt.x + fz_atof(args[i]), pt.y);
i += 1;
break;
case 'V':
if (i >= n) break;
pt = fz_currentpoint(doc->ctx, path);
fz_lineto(doc->ctx, path, pt.x, fz_atof(args[i]));
i += 1;
break;
case 'v':
if (i >= n) break;
pt = fz_currentpoint(doc->ctx, path);
fz_lineto(doc->ctx, path, pt.x, pt.y + fz_atof(args[i]));
i += 1;
break;
case 'C':
if (i + 5 >= n) break;
x1 = fz_atof(args[i+0]);
y1 = fz_atof(args[i+1]);
x2 = fz_atof(args[i+2]);
y2 = fz_atof(args[i+3]);
x3 = fz_atof(args[i+4]);
y3 = fz_atof(args[i+5]);
fz_curveto(doc->ctx, path, x1, y1, x2, y2, x3, y3);
i += 6;
reset_smooth = 0;
smooth_x = x3 - x2;
smooth_y = y3 - y2;
break;
case 'c':
if (i + 5 >= n) break;
pt = fz_currentpoint(doc->ctx, path);
x1 = fz_atof(args[i+0]) + pt.x;
y1 = fz_atof(args[i+1]) + pt.y;
x2 = fz_atof(args[i+2]) + pt.x;
y2 = fz_atof(args[i+3]) + pt.y;
x3 = fz_atof(args[i+4]) + pt.x;
y3 = fz_atof(args[i+5]) + pt.y;
fz_curveto(doc->ctx, path, x1, y1, x2, y2, x3, y3);
i += 6;
reset_smooth = 0;
smooth_x = x3 - x2;
smooth_y = y3 - y2;
break;
case 'S':
if (i + 3 >= n) break;
pt = fz_currentpoint(doc->ctx, path);
x1 = fz_atof(args[i+0]);
y1 = fz_atof(args[i+1]);
x2 = fz_atof(args[i+2]);
y2 = fz_atof(args[i+3]);
fz_curveto(doc->ctx, path, pt.x + smooth_x, pt.y + smooth_y, x1, y1, x2, y2);
i += 4;
reset_smooth = 0;
smooth_x = x2 - x1;
smooth_y = y2 - y1;
break;
case 's':
if (i + 3 >= n) break;
pt = fz_currentpoint(doc->ctx, path);
x1 = fz_atof(args[i+0]) + pt.x;
y1 = fz_atof(args[i+1]) + pt.y;
x2 = fz_atof(args[i+2]) + pt.x;
y2 = fz_atof(args[i+3]) + pt.y;
fz_curveto(doc->ctx, path, pt.x + smooth_x, pt.y + smooth_y, x1, y1, x2, y2);
i += 4;
reset_smooth = 0;
smooth_x = x2 - x1;
smooth_y = y2 - y1;
break;
case 'Q':
if (i + 3 >= n) break;
pt = fz_currentpoint(doc->ctx, path);
x1 = fz_atof(args[i+0]);
y1 = fz_atof(args[i+1]);
x2 = fz_atof(args[i+2]);
y2 = fz_atof(args[i+3]);
fz_curveto(doc->ctx, path,
(pt.x + 2 * x1) / 3, (pt.y + 2 * y1) / 3,
(x2 + 2 * x1) / 3, (y2 + 2 * y1) / 3,
x2, y2);
i += 4;
break;
case 'q':
if (i + 3 >= n) break;
pt = fz_currentpoint(doc->ctx, path);
x1 = fz_atof(args[i+0]) + pt.x;
y1 = fz_atof(args[i+1]) + pt.y;
x2 = fz_atof(args[i+2]) + pt.x;
y2 = fz_atof(args[i+3]) + pt.y;
fz_curveto(doc->ctx, path,
(pt.x + 2 * x1) / 3, (pt.y + 2 * y1) / 3,
(x2 + 2 * x1) / 3, (y2 + 2 * y1) / 3,
x2, y2);
i += 4;
break;
case 'A':
if (i + 6 >= n) break;
xps_draw_arc(doc->ctx, path,
fz_atof(args[i+0]), fz_atof(args[i+1]), fz_atof(args[i+2]),
atoi(args[i+3]), atoi(args[i+4]),
fz_atof(args[i+5]), fz_atof(args[i+6]));
i += 7;
break;
case 'a':
if (i + 6 >= n) break;
pt = fz_currentpoint(doc->ctx, path);
xps_draw_arc(doc->ctx, path,
fz_atof(args[i+0]), fz_atof(args[i+1]), fz_atof(args[i+2]),
atoi(args[i+3]), atoi(args[i+4]),
fz_atof(args[i+5]) + pt.x, fz_atof(args[i+6]) + pt.y);
i += 7;
break;
case 'Z':
case 'z':
fz_closepath(doc->ctx, path);
break;
default:
/* eek */
fz_warn(doc->ctx, "ignoring invalid command '%c'", cmd);
/* Skip any trailing numbers to avoid an infinite loop */
while (i < n && (args[i][0] == '+' || args[i][0] == '.' || args[i][0] == '-' || (args[i][0] >= '0' && args[i][0] <= '9')))
i ++;
break;
}
old = cmd;
}
fz_free(doc->ctx, args);
return path;
}
| @@ -826,7 +826,7 @@ xps_parse_path(xps_document *doc, const fz_matrix *ctm, char *base_uri, xps_reso
fz_stroke_state *stroke = NULL;
fz_matrix transform;
- float samples[32];
+ float samples[FZ_MAX_COLORS];
fz_colorspace *colorspace;
fz_path *path = NULL;
fz_path *stroke_path = NULL; | CWE-119 | null | null |
10,557 | xps_parse_arc_segment(fz_context *doc, fz_path *path, fz_xml *root, int stroking, int *skipped_stroke)
{
/* ArcSegment pretty much follows the SVG algorithm for converting an
* arc in endpoint representation to an arc in centerpoint
* representation. Once in centerpoint it can be given to the
* graphics library in the form of a postscript arc. */
float rotation_angle;
int is_large_arc, is_clockwise;
float point_x, point_y;
float size_x, size_y;
int is_stroked;
char *point_att = fz_xml_att(root, "Point");
char *size_att = fz_xml_att(root, "Size");
char *rotation_angle_att = fz_xml_att(root, "RotationAngle");
char *is_large_arc_att = fz_xml_att(root, "IsLargeArc");
char *sweep_direction_att = fz_xml_att(root, "SweepDirection");
char *is_stroked_att = fz_xml_att(root, "IsStroked");
if (!point_att || !size_att || !rotation_angle_att || !is_large_arc_att || !sweep_direction_att)
{
fz_warn(doc, "ArcSegment element is missing attributes");
return;
}
is_stroked = 1;
if (is_stroked_att && !strcmp(is_stroked_att, "false"))
is_stroked = 0;
if (!is_stroked)
*skipped_stroke = 1;
point_x = point_y = 0;
size_x = size_y = 0;
xps_parse_point(point_att, &point_x, &point_y);
xps_parse_point(size_att, &size_x, &size_y);
rotation_angle = fz_atof(rotation_angle_att);
is_large_arc = !strcmp(is_large_arc_att, "true");
is_clockwise = !strcmp(sweep_direction_att, "Clockwise");
if (stroking && !is_stroked)
{
fz_moveto(doc, path, point_x, point_y);
return;
}
xps_draw_arc(doc, path, size_x, size_y, rotation_angle, is_large_arc, is_clockwise, point_x, point_y);
}
| Exec Code Overflow | 0 | xps_parse_arc_segment(fz_context *doc, fz_path *path, fz_xml *root, int stroking, int *skipped_stroke)
{
/* ArcSegment pretty much follows the SVG algorithm for converting an
* arc in endpoint representation to an arc in centerpoint
* representation. Once in centerpoint it can be given to the
* graphics library in the form of a postscript arc. */
float rotation_angle;
int is_large_arc, is_clockwise;
float point_x, point_y;
float size_x, size_y;
int is_stroked;
char *point_att = fz_xml_att(root, "Point");
char *size_att = fz_xml_att(root, "Size");
char *rotation_angle_att = fz_xml_att(root, "RotationAngle");
char *is_large_arc_att = fz_xml_att(root, "IsLargeArc");
char *sweep_direction_att = fz_xml_att(root, "SweepDirection");
char *is_stroked_att = fz_xml_att(root, "IsStroked");
if (!point_att || !size_att || !rotation_angle_att || !is_large_arc_att || !sweep_direction_att)
{
fz_warn(doc, "ArcSegment element is missing attributes");
return;
}
is_stroked = 1;
if (is_stroked_att && !strcmp(is_stroked_att, "false"))
is_stroked = 0;
if (!is_stroked)
*skipped_stroke = 1;
point_x = point_y = 0;
size_x = size_y = 0;
xps_parse_point(point_att, &point_x, &point_y);
xps_parse_point(size_att, &size_x, &size_y);
rotation_angle = fz_atof(rotation_angle_att);
is_large_arc = !strcmp(is_large_arc_att, "true");
is_clockwise = !strcmp(sweep_direction_att, "Clockwise");
if (stroking && !is_stroked)
{
fz_moveto(doc, path, point_x, point_y);
return;
}
xps_draw_arc(doc, path, size_x, size_y, rotation_angle, is_large_arc, is_clockwise, point_x, point_y);
}
| @@ -826,7 +826,7 @@ xps_parse_path(xps_document *doc, const fz_matrix *ctm, char *base_uri, xps_reso
fz_stroke_state *stroke = NULL;
fz_matrix transform;
- float samples[32];
+ float samples[FZ_MAX_COLORS];
fz_colorspace *colorspace;
fz_path *path = NULL;
fz_path *stroke_path = NULL; | CWE-119 | null | null |
10,558 | xps_parse_float_array(char *s, int num, float *x)
{
int k = 0;
if (s == NULL || *s == 0)
return NULL;
while (*s)
{
while (*s == 0x0d || *s == '\t' || *s == ' ' || *s == 0x0a)
s++;
x[k] = (float)strtod(s, &s);
while (*s == 0x0d || *s == '\t' || *s == ' ' || *s == 0x0a)
s++;
if (*s == ',')
s++;
if (++k == num)
break;
}
return s;
}
| Exec Code Overflow | 0 | xps_parse_float_array(char *s, int num, float *x)
{
int k = 0;
if (s == NULL || *s == 0)
return NULL;
while (*s)
{
while (*s == 0x0d || *s == '\t' || *s == ' ' || *s == 0x0a)
s++;
x[k] = (float)strtod(s, &s);
while (*s == 0x0d || *s == '\t' || *s == ' ' || *s == 0x0a)
s++;
if (*s == ',')
s++;
if (++k == num)
break;
}
return s;
}
| @@ -826,7 +826,7 @@ xps_parse_path(xps_document *doc, const fz_matrix *ctm, char *base_uri, xps_reso
fz_stroke_state *stroke = NULL;
fz_matrix transform;
- float samples[32];
+ float samples[FZ_MAX_COLORS];
fz_colorspace *colorspace;
fz_path *path = NULL;
fz_path *stroke_path = NULL; | CWE-119 | null | null |
10,559 | xps_parse_line_cap(char *attr)
{
if (attr)
{
if (!strcmp(attr, "Flat")) return 0;
if (!strcmp(attr, "Round")) return 1;
if (!strcmp(attr, "Square")) return 2;
if (!strcmp(attr, "Triangle")) return 3;
}
return 0;
}
| Exec Code Overflow | 0 | xps_parse_line_cap(char *attr)
{
if (attr)
{
if (!strcmp(attr, "Flat")) return 0;
if (!strcmp(attr, "Round")) return 1;
if (!strcmp(attr, "Square")) return 2;
if (!strcmp(attr, "Triangle")) return 3;
}
return 0;
}
| @@ -826,7 +826,7 @@ xps_parse_path(xps_document *doc, const fz_matrix *ctm, char *base_uri, xps_reso
fz_stroke_state *stroke = NULL;
fz_matrix transform;
- float samples[32];
+ float samples[FZ_MAX_COLORS];
fz_colorspace *colorspace;
fz_path *path = NULL;
fz_path *stroke_path = NULL; | CWE-119 | null | null |
10,560 | xps_parse_path_geometry(xps_document *doc, xps_resource *dict, fz_xml *root, int stroking, int *fill_rule)
{
fz_xml *node;
char *figures_att;
char *fill_rule_att;
char *transform_att;
fz_xml *transform_tag = NULL;
fz_xml *figures_tag = NULL; /* only used by resource */
fz_matrix transform;
fz_path *path;
figures_att = fz_xml_att(root, "Figures");
fill_rule_att = fz_xml_att(root, "FillRule");
transform_att = fz_xml_att(root, "Transform");
for (node = fz_xml_down(root); node; node = fz_xml_next(node))
{
if (!strcmp(fz_xml_tag(node), "PathGeometry.Transform"))
transform_tag = fz_xml_down(node);
}
xps_resolve_resource_reference(doc, dict, &transform_att, &transform_tag, NULL);
xps_resolve_resource_reference(doc, dict, &figures_att, &figures_tag, NULL);
if (fill_rule_att)
{
if (!strcmp(fill_rule_att, "NonZero"))
*fill_rule = 1;
if (!strcmp(fill_rule_att, "EvenOdd"))
*fill_rule = 0;
}
transform = fz_identity;
if (transform_att)
xps_parse_render_transform(doc, transform_att, &transform);
if (transform_tag)
xps_parse_matrix_transform(doc, transform_tag, &transform);
if (figures_att)
path = xps_parse_abbreviated_geometry(doc, figures_att, fill_rule);
else
path = fz_new_path(doc->ctx);
if (figures_tag)
xps_parse_path_figure(doc->ctx, path, figures_tag, stroking);
for (node = fz_xml_down(root); node; node = fz_xml_next(node))
{
if (!strcmp(fz_xml_tag(node), "PathFigure"))
xps_parse_path_figure(doc->ctx, path, node, stroking);
}
if (transform_att || transform_tag)
fz_transform_path(doc->ctx, path, &transform);
return path;
}
| Exec Code Overflow | 0 | xps_parse_path_geometry(xps_document *doc, xps_resource *dict, fz_xml *root, int stroking, int *fill_rule)
{
fz_xml *node;
char *figures_att;
char *fill_rule_att;
char *transform_att;
fz_xml *transform_tag = NULL;
fz_xml *figures_tag = NULL; /* only used by resource */
fz_matrix transform;
fz_path *path;
figures_att = fz_xml_att(root, "Figures");
fill_rule_att = fz_xml_att(root, "FillRule");
transform_att = fz_xml_att(root, "Transform");
for (node = fz_xml_down(root); node; node = fz_xml_next(node))
{
if (!strcmp(fz_xml_tag(node), "PathGeometry.Transform"))
transform_tag = fz_xml_down(node);
}
xps_resolve_resource_reference(doc, dict, &transform_att, &transform_tag, NULL);
xps_resolve_resource_reference(doc, dict, &figures_att, &figures_tag, NULL);
if (fill_rule_att)
{
if (!strcmp(fill_rule_att, "NonZero"))
*fill_rule = 1;
if (!strcmp(fill_rule_att, "EvenOdd"))
*fill_rule = 0;
}
transform = fz_identity;
if (transform_att)
xps_parse_render_transform(doc, transform_att, &transform);
if (transform_tag)
xps_parse_matrix_transform(doc, transform_tag, &transform);
if (figures_att)
path = xps_parse_abbreviated_geometry(doc, figures_att, fill_rule);
else
path = fz_new_path(doc->ctx);
if (figures_tag)
xps_parse_path_figure(doc->ctx, path, figures_tag, stroking);
for (node = fz_xml_down(root); node; node = fz_xml_next(node))
{
if (!strcmp(fz_xml_tag(node), "PathFigure"))
xps_parse_path_figure(doc->ctx, path, node, stroking);
}
if (transform_att || transform_tag)
fz_transform_path(doc->ctx, path, &transform);
return path;
}
| @@ -826,7 +826,7 @@ xps_parse_path(xps_document *doc, const fz_matrix *ctm, char *base_uri, xps_reso
fz_stroke_state *stroke = NULL;
fz_matrix transform;
- float samples[32];
+ float samples[FZ_MAX_COLORS];
fz_colorspace *colorspace;
fz_path *path = NULL;
fz_path *stroke_path = NULL; | CWE-119 | null | null |
10,561 | xps_parse_point(char *s_in, float *x, float *y)
{
char *s_out = s_in;
float xy[2];
s_out = xps_parse_float_array(s_out, 2, &xy[0]);
*x = xy[0];
*y = xy[1];
return s_out;
}
| Exec Code Overflow | 0 | xps_parse_point(char *s_in, float *x, float *y)
{
char *s_out = s_in;
float xy[2];
s_out = xps_parse_float_array(s_out, 2, &xy[0]);
*x = xy[0];
*y = xy[1];
return s_out;
}
| @@ -826,7 +826,7 @@ xps_parse_path(xps_document *doc, const fz_matrix *ctm, char *base_uri, xps_reso
fz_stroke_state *stroke = NULL;
fz_matrix transform;
- float samples[32];
+ float samples[FZ_MAX_COLORS];
fz_colorspace *colorspace;
fz_path *path = NULL;
fz_path *stroke_path = NULL; | CWE-119 | null | null |
10,562 | xps_parse_poly_bezier_segment(fz_context *doc, fz_path *path, fz_xml *root, int stroking, int *skipped_stroke)
{
char *points_att = fz_xml_att(root, "Points");
char *is_stroked_att = fz_xml_att(root, "IsStroked");
float x[3], y[3];
int is_stroked;
char *s;
int n;
if (!points_att)
{
fz_warn(doc, "PolyBezierSegment element has no points");
return;
}
is_stroked = 1;
if (is_stroked_att && !strcmp(is_stroked_att, "false"))
is_stroked = 0;
if (!is_stroked)
*skipped_stroke = 1;
s = points_att;
n = 0;
while (*s != 0)
{
while (*s == ' ') s++;
s = xps_parse_point(s, &x[n], &y[n]);
n ++;
if (n == 3)
{
if (stroking && !is_stroked)
fz_moveto(doc, path, x[2], y[2]);
else
fz_curveto(doc, path, x[0], y[0], x[1], y[1], x[2], y[2]);
n = 0;
}
}
}
| Exec Code Overflow | 0 | xps_parse_poly_bezier_segment(fz_context *doc, fz_path *path, fz_xml *root, int stroking, int *skipped_stroke)
{
char *points_att = fz_xml_att(root, "Points");
char *is_stroked_att = fz_xml_att(root, "IsStroked");
float x[3], y[3];
int is_stroked;
char *s;
int n;
if (!points_att)
{
fz_warn(doc, "PolyBezierSegment element has no points");
return;
}
is_stroked = 1;
if (is_stroked_att && !strcmp(is_stroked_att, "false"))
is_stroked = 0;
if (!is_stroked)
*skipped_stroke = 1;
s = points_att;
n = 0;
while (*s != 0)
{
while (*s == ' ') s++;
s = xps_parse_point(s, &x[n], &y[n]);
n ++;
if (n == 3)
{
if (stroking && !is_stroked)
fz_moveto(doc, path, x[2], y[2]);
else
fz_curveto(doc, path, x[0], y[0], x[1], y[1], x[2], y[2]);
n = 0;
}
}
}
| @@ -826,7 +826,7 @@ xps_parse_path(xps_document *doc, const fz_matrix *ctm, char *base_uri, xps_reso
fz_stroke_state *stroke = NULL;
fz_matrix transform;
- float samples[32];
+ float samples[FZ_MAX_COLORS];
fz_colorspace *colorspace;
fz_path *path = NULL;
fz_path *stroke_path = NULL; | CWE-119 | null | null |
10,563 | xps_parse_poly_quadratic_bezier_segment(fz_context *doc, fz_path *path, fz_xml *root, int stroking, int *skipped_stroke)
{
char *points_att = fz_xml_att(root, "Points");
char *is_stroked_att = fz_xml_att(root, "IsStroked");
float x[2], y[2];
int is_stroked;
fz_point pt;
char *s;
int n;
if (!points_att)
{
fz_warn(doc, "PolyQuadraticBezierSegment element has no points");
return;
}
is_stroked = 1;
if (is_stroked_att && !strcmp(is_stroked_att, "false"))
is_stroked = 0;
if (!is_stroked)
*skipped_stroke = 1;
s = points_att;
n = 0;
while (*s != 0)
{
while (*s == ' ') s++;
s = xps_parse_point(s, &x[n], &y[n]);
n ++;
if (n == 2)
{
if (stroking && !is_stroked)
{
fz_moveto(doc, path, x[1], y[1]);
}
else
{
pt = fz_currentpoint(doc, path);
fz_curveto(doc, path,
(pt.x + 2 * x[0]) / 3, (pt.y + 2 * y[0]) / 3,
(x[1] + 2 * x[0]) / 3, (y[1] + 2 * y[0]) / 3,
x[1], y[1]);
}
n = 0;
}
}
}
| Exec Code Overflow | 0 | xps_parse_poly_quadratic_bezier_segment(fz_context *doc, fz_path *path, fz_xml *root, int stroking, int *skipped_stroke)
{
char *points_att = fz_xml_att(root, "Points");
char *is_stroked_att = fz_xml_att(root, "IsStroked");
float x[2], y[2];
int is_stroked;
fz_point pt;
char *s;
int n;
if (!points_att)
{
fz_warn(doc, "PolyQuadraticBezierSegment element has no points");
return;
}
is_stroked = 1;
if (is_stroked_att && !strcmp(is_stroked_att, "false"))
is_stroked = 0;
if (!is_stroked)
*skipped_stroke = 1;
s = points_att;
n = 0;
while (*s != 0)
{
while (*s == ' ') s++;
s = xps_parse_point(s, &x[n], &y[n]);
n ++;
if (n == 2)
{
if (stroking && !is_stroked)
{
fz_moveto(doc, path, x[1], y[1]);
}
else
{
pt = fz_currentpoint(doc, path);
fz_curveto(doc, path,
(pt.x + 2 * x[0]) / 3, (pt.y + 2 * y[0]) / 3,
(x[1] + 2 * x[0]) / 3, (y[1] + 2 * y[0]) / 3,
x[1], y[1]);
}
n = 0;
}
}
}
| @@ -826,7 +826,7 @@ xps_parse_path(xps_document *doc, const fz_matrix *ctm, char *base_uri, xps_reso
fz_stroke_state *stroke = NULL;
fz_matrix transform;
- float samples[32];
+ float samples[FZ_MAX_COLORS];
fz_colorspace *colorspace;
fz_path *path = NULL;
fz_path *stroke_path = NULL; | CWE-119 | null | null |
10,564 | PHP_FUNCTION(parse_url)
{
char *str;
int str_len;
php_url *resource;
long key = -1;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &str, &str_len, &key) == FAILURE) {
return;
}
resource = php_url_parse_ex(str, str_len);
if (resource == NULL) {
/* @todo Find a method to determine why php_url_parse_ex() failed */
RETURN_FALSE;
}
if (key > -1) {
switch (key) {
case PHP_URL_SCHEME:
if (resource->scheme != NULL) RETVAL_STRING(resource->scheme, 1);
break;
case PHP_URL_HOST:
if (resource->host != NULL) RETVAL_STRING(resource->host, 1);
break;
case PHP_URL_PORT:
if (resource->port != 0) RETVAL_LONG(resource->port);
break;
case PHP_URL_USER:
if (resource->user != NULL) RETVAL_STRING(resource->user, 1);
break;
case PHP_URL_PASS:
if (resource->pass != NULL) RETVAL_STRING(resource->pass, 1);
break;
case PHP_URL_PATH:
if (resource->path != NULL) RETVAL_STRING(resource->path, 1);
break;
case PHP_URL_QUERY:
if (resource->query != NULL) RETVAL_STRING(resource->query, 1);
break;
case PHP_URL_FRAGMENT:
if (resource->fragment != NULL) RETVAL_STRING(resource->fragment, 1);
break;
default:
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid URL component identifier %ld", key);
RETVAL_FALSE;
}
goto done;
}
/* allocate an array for return */
array_init(return_value);
/* add the various elements to the array */
if (resource->scheme != NULL)
add_assoc_string(return_value, "scheme", resource->scheme, 1);
if (resource->host != NULL)
add_assoc_string(return_value, "host", resource->host, 1);
if (resource->port != 0)
add_assoc_long(return_value, "port", resource->port);
if (resource->user != NULL)
add_assoc_string(return_value, "user", resource->user, 1);
if (resource->pass != NULL)
add_assoc_string(return_value, "pass", resource->pass, 1);
if (resource->path != NULL)
add_assoc_string(return_value, "path", resource->path, 1);
if (resource->query != NULL)
add_assoc_string(return_value, "query", resource->query, 1);
if (resource->fragment != NULL)
add_assoc_string(return_value, "fragment", resource->fragment, 1);
done:
php_url_free(resource);
}
| Bypass | 0 | PHP_FUNCTION(parse_url)
{
char *str;
int str_len;
php_url *resource;
long key = -1;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &str, &str_len, &key) == FAILURE) {
return;
}
resource = php_url_parse_ex(str, str_len);
if (resource == NULL) {
/* @todo Find a method to determine why php_url_parse_ex() failed */
RETURN_FALSE;
}
if (key > -1) {
switch (key) {
case PHP_URL_SCHEME:
if (resource->scheme != NULL) RETVAL_STRING(resource->scheme, 1);
break;
case PHP_URL_HOST:
if (resource->host != NULL) RETVAL_STRING(resource->host, 1);
break;
case PHP_URL_PORT:
if (resource->port != 0) RETVAL_LONG(resource->port);
break;
case PHP_URL_USER:
if (resource->user != NULL) RETVAL_STRING(resource->user, 1);
break;
case PHP_URL_PASS:
if (resource->pass != NULL) RETVAL_STRING(resource->pass, 1);
break;
case PHP_URL_PATH:
if (resource->path != NULL) RETVAL_STRING(resource->path, 1);
break;
case PHP_URL_QUERY:
if (resource->query != NULL) RETVAL_STRING(resource->query, 1);
break;
case PHP_URL_FRAGMENT:
if (resource->fragment != NULL) RETVAL_STRING(resource->fragment, 1);
break;
default:
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid URL component identifier %ld", key);
RETVAL_FALSE;
}
goto done;
}
/* allocate an array for return */
array_init(return_value);
/* add the various elements to the array */
if (resource->scheme != NULL)
add_assoc_string(return_value, "scheme", resource->scheme, 1);
if (resource->host != NULL)
add_assoc_string(return_value, "host", resource->host, 1);
if (resource->port != 0)
add_assoc_long(return_value, "port", resource->port);
if (resource->user != NULL)
add_assoc_string(return_value, "user", resource->user, 1);
if (resource->pass != NULL)
add_assoc_string(return_value, "pass", resource->pass, 1);
if (resource->path != NULL)
add_assoc_string(return_value, "path", resource->path, 1);
if (resource->query != NULL)
add_assoc_string(return_value, "query", resource->query, 1);
if (resource->fragment != NULL)
add_assoc_string(return_value, "fragment", resource->fragment, 1);
done:
php_url_free(resource);
}
| @@ -217,28 +217,7 @@ PHPAPI php_url *php_url_parse_ex(char const *str, int length)
goto nohost;
}
- e = ue;
-
- if (!(p = memchr(s, '/', (ue - s)))) {
- char *query, *fragment;
-
- query = memchr(s, '?', (ue - s));
- fragment = memchr(s, '#', (ue - s));
-
- if (query && fragment) {
- if (query > fragment) {
- e = fragment;
- } else {
- e = query;
- }
- } else if (query) {
- e = query;
- } else if (fragment) {
- e = fragment;
- }
- } else {
- e = p;
- }
+ e = s + strcspn(s, "/?#");
/* check for login and password */
if ((p = zend_memrchr(s, '@', (e-s)))) { | CWE-20 | null | null |
10,565 | PHP_FUNCTION(get_headers)
{
char *url;
int url_len;
php_stream_context *context;
php_stream *stream;
zval **prev_val, **hdr = NULL, **h;
HashPosition pos;
HashTable *hashT;
long format = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &url, &url_len, &format) == FAILURE) {
return;
}
context = FG(default_context) ? FG(default_context) : (FG(default_context) = php_stream_context_alloc(TSRMLS_C));
if (!(stream = php_stream_open_wrapper_ex(url, "r", REPORT_ERRORS | STREAM_USE_URL | STREAM_ONLY_GET_HEADERS, NULL, context))) {
RETURN_FALSE;
}
if (!stream->wrapperdata || Z_TYPE_P(stream->wrapperdata) != IS_ARRAY) {
php_stream_close(stream);
RETURN_FALSE;
}
array_init(return_value);
/* check for curl-wrappers that provide headers via a special "headers" element */
if (zend_hash_find(HASH_OF(stream->wrapperdata), "headers", sizeof("headers"), (void **)&h) != FAILURE && Z_TYPE_PP(h) == IS_ARRAY) {
/* curl-wrappers don't load data until the 1st read */
if (!Z_ARRVAL_PP(h)->nNumOfElements) {
php_stream_getc(stream);
}
zend_hash_find(HASH_OF(stream->wrapperdata), "headers", sizeof("headers"), (void **)&h);
hashT = Z_ARRVAL_PP(h);
} else {
hashT = HASH_OF(stream->wrapperdata);
}
zend_hash_internal_pointer_reset_ex(hashT, &pos);
while (zend_hash_get_current_data_ex(hashT, (void**)&hdr, &pos) != FAILURE) {
if (!hdr || Z_TYPE_PP(hdr) != IS_STRING) {
zend_hash_move_forward_ex(hashT, &pos);
continue;
}
if (!format) {
no_name_header:
add_next_index_stringl(return_value, Z_STRVAL_PP(hdr), Z_STRLEN_PP(hdr), 1);
} else {
char c;
char *s, *p;
if ((p = strchr(Z_STRVAL_PP(hdr), ':'))) {
c = *p;
*p = '\0';
s = p + 1;
while (isspace((int)*(unsigned char *)s)) {
s++;
}
if (zend_hash_find(HASH_OF(return_value), Z_STRVAL_PP(hdr), (p - Z_STRVAL_PP(hdr) + 1), (void **) &prev_val) == FAILURE) {
add_assoc_stringl_ex(return_value, Z_STRVAL_PP(hdr), (p - Z_STRVAL_PP(hdr) + 1), s, (Z_STRLEN_PP(hdr) - (s - Z_STRVAL_PP(hdr))), 1);
} else { /* some headers may occur more then once, therefor we need to remake the string into an array */
convert_to_array(*prev_val);
add_next_index_stringl(*prev_val, s, (Z_STRLEN_PP(hdr) - (s - Z_STRVAL_PP(hdr))), 1);
}
*p = c;
} else {
goto no_name_header;
}
}
zend_hash_move_forward_ex(hashT, &pos);
}
php_stream_close(stream);
}
| Bypass | 0 | PHP_FUNCTION(get_headers)
{
char *url;
int url_len;
php_stream_context *context;
php_stream *stream;
zval **prev_val, **hdr = NULL, **h;
HashPosition pos;
HashTable *hashT;
long format = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &url, &url_len, &format) == FAILURE) {
return;
}
context = FG(default_context) ? FG(default_context) : (FG(default_context) = php_stream_context_alloc(TSRMLS_C));
if (!(stream = php_stream_open_wrapper_ex(url, "r", REPORT_ERRORS | STREAM_USE_URL | STREAM_ONLY_GET_HEADERS, NULL, context))) {
RETURN_FALSE;
}
if (!stream->wrapperdata || Z_TYPE_P(stream->wrapperdata) != IS_ARRAY) {
php_stream_close(stream);
RETURN_FALSE;
}
array_init(return_value);
/* check for curl-wrappers that provide headers via a special "headers" element */
if (zend_hash_find(HASH_OF(stream->wrapperdata), "headers", sizeof("headers"), (void **)&h) != FAILURE && Z_TYPE_PP(h) == IS_ARRAY) {
/* curl-wrappers don't load data until the 1st read */
if (!Z_ARRVAL_PP(h)->nNumOfElements) {
php_stream_getc(stream);
}
zend_hash_find(HASH_OF(stream->wrapperdata), "headers", sizeof("headers"), (void **)&h);
hashT = Z_ARRVAL_PP(h);
} else {
hashT = HASH_OF(stream->wrapperdata);
}
zend_hash_internal_pointer_reset_ex(hashT, &pos);
while (zend_hash_get_current_data_ex(hashT, (void**)&hdr, &pos) != FAILURE) {
if (!hdr || Z_TYPE_PP(hdr) != IS_STRING) {
zend_hash_move_forward_ex(hashT, &pos);
continue;
}
if (!format) {
no_name_header:
add_next_index_stringl(return_value, Z_STRVAL_PP(hdr), Z_STRLEN_PP(hdr), 1);
} else {
char c;
char *s, *p;
if ((p = strchr(Z_STRVAL_PP(hdr), ':'))) {
c = *p;
*p = '\0';
s = p + 1;
while (isspace((int)*(unsigned char *)s)) {
s++;
}
if (zend_hash_find(HASH_OF(return_value), Z_STRVAL_PP(hdr), (p - Z_STRVAL_PP(hdr) + 1), (void **) &prev_val) == FAILURE) {
add_assoc_stringl_ex(return_value, Z_STRVAL_PP(hdr), (p - Z_STRVAL_PP(hdr) + 1), s, (Z_STRLEN_PP(hdr) - (s - Z_STRVAL_PP(hdr))), 1);
} else { /* some headers may occur more then once, therefor we need to remake the string into an array */
convert_to_array(*prev_val);
add_next_index_stringl(*prev_val, s, (Z_STRLEN_PP(hdr) - (s - Z_STRVAL_PP(hdr))), 1);
}
*p = c;
} else {
goto no_name_header;
}
}
zend_hash_move_forward_ex(hashT, &pos);
}
php_stream_close(stream);
}
| @@ -217,28 +217,7 @@ PHPAPI php_url *php_url_parse_ex(char const *str, int length)
goto nohost;
}
- e = ue;
-
- if (!(p = memchr(s, '/', (ue - s)))) {
- char *query, *fragment;
-
- query = memchr(s, '?', (ue - s));
- fragment = memchr(s, '#', (ue - s));
-
- if (query && fragment) {
- if (query > fragment) {
- e = fragment;
- } else {
- e = query;
- }
- } else if (query) {
- e = query;
- } else if (fragment) {
- e = fragment;
- }
- } else {
- e = p;
- }
+ e = s + strcspn(s, "/?#");
/* check for login and password */
if ((p = zend_memrchr(s, '@', (e-s)))) { | CWE-20 | null | null |
10,566 | PHPAPI int php_raw_url_decode(char *str, int len)
{
char *dest = str;
char *data = str;
while (len--) {
if (*data == '%' && len >= 2 && isxdigit((int) *(data + 1))
&& isxdigit((int) *(data + 2))) {
#ifndef CHARSET_EBCDIC
*dest = (char) php_htoi(data + 1);
#else
*dest = os_toebcdic[(char) php_htoi(data + 1)];
#endif
data += 2;
len -= 2;
} else {
*dest = *data;
}
data++;
dest++;
}
*dest = '\0';
return dest - str;
}
| Bypass | 0 | PHPAPI int php_raw_url_decode(char *str, int len)
{
char *dest = str;
char *data = str;
while (len--) {
if (*data == '%' && len >= 2 && isxdigit((int) *(data + 1))
&& isxdigit((int) *(data + 2))) {
#ifndef CHARSET_EBCDIC
*dest = (char) php_htoi(data + 1);
#else
*dest = os_toebcdic[(char) php_htoi(data + 1)];
#endif
data += 2;
len -= 2;
} else {
*dest = *data;
}
data++;
dest++;
}
*dest = '\0';
return dest - str;
}
| @@ -217,28 +217,7 @@ PHPAPI php_url *php_url_parse_ex(char const *str, int length)
goto nohost;
}
- e = ue;
-
- if (!(p = memchr(s, '/', (ue - s)))) {
- char *query, *fragment;
-
- query = memchr(s, '?', (ue - s));
- fragment = memchr(s, '#', (ue - s));
-
- if (query && fragment) {
- if (query > fragment) {
- e = fragment;
- } else {
- e = query;
- }
- } else if (query) {
- e = query;
- } else if (fragment) {
- e = fragment;
- }
- } else {
- e = p;
- }
+ e = s + strcspn(s, "/?#");
/* check for login and password */
if ((p = zend_memrchr(s, '@', (e-s)))) { | CWE-20 | null | null |
10,567 | static gboolean lxterminal_socket_accept_client(GIOChannel * source, GIOCondition condition, LXTermWindow * lxtermwin)
{
if (condition & G_IO_IN)
{
/* Accept the new connection. */
int fd = accept(g_io_channel_unix_get_fd(source), NULL, NULL);
if (fd < 0)
g_warning("Accept failed: %s\n", g_strerror(errno));
/* Add O_NONBLOCK to the flags. */
fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_NONBLOCK);
/* Create a glib I/O channel. */
GIOChannel * gio = g_io_channel_unix_new(fd);
if (gio == NULL)
g_warning("Cannot create new GIOChannel\n");
else
{
/* Set up the glib I/O channel and add it to the event loop. */
g_io_channel_set_encoding(gio, NULL, NULL);
g_io_add_watch(gio, G_IO_IN | G_IO_HUP, (GIOFunc) lxterminal_socket_read_channel, lxtermwin);
g_io_channel_unref(gio);
}
}
/* Our listening socket hung up - we are dead. */
if (condition & G_IO_HUP)
g_error("Server listening socket closed unexpectedly\n");
return TRUE;
}
| DoS Bypass | 0 | static gboolean lxterminal_socket_accept_client(GIOChannel * source, GIOCondition condition, LXTermWindow * lxtermwin)
{
if (condition & G_IO_IN)
{
/* Accept the new connection. */
int fd = accept(g_io_channel_unix_get_fd(source), NULL, NULL);
if (fd < 0)
g_warning("Accept failed: %s\n", g_strerror(errno));
/* Add O_NONBLOCK to the flags. */
fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_NONBLOCK);
/* Create a glib I/O channel. */
GIOChannel * gio = g_io_channel_unix_new(fd);
if (gio == NULL)
g_warning("Cannot create new GIOChannel\n");
else
{
/* Set up the glib I/O channel and add it to the event loop. */
g_io_channel_set_encoding(gio, NULL, NULL);
g_io_add_watch(gio, G_IO_IN | G_IO_HUP, (GIOFunc) lxterminal_socket_read_channel, lxtermwin);
g_io_channel_unref(gio);
}
}
/* Our listening socket hung up - we are dead. */
if (condition & G_IO_HUP)
g_error("Server listening socket closed unexpectedly\n");
return TRUE;
}
| @@ -140,7 +140,8 @@ gboolean lxterminal_socket_initialize(LXTermWindow * lxtermwin, gint argc, gchar
* This function returns TRUE if this process should keep running and FALSE if it should exit. */
/* Formulate the path for the Unix domain socket. */
- gchar * socket_path = g_strdup_printf("/tmp/.lxterminal-socket%s-%s", gdk_display_get_name(gdk_display_get_default()), g_get_user_name());
+ gchar * socket_path = g_strdup_printf("%s/.lxterminal-socket-%s", g_get_user_runtime_dir(), gdk_display_get_name(gdk_display_get_default()));
+ printf("%s\n", socket_path);
/* Create socket. */
int fd = socket(PF_UNIX, SOCK_STREAM, 0); | CWE-284 | null | null |
10,568 | static gboolean lxterminal_socket_read_channel(GIOChannel * gio, GIOCondition condition, LXTermWindow * lxtermwin)
{
/* Read message. */
gchar * msg = NULL;
gsize len = 0;
GError * err = NULL;
GIOStatus ret = g_io_channel_read_to_end(gio, &msg, &len, &err);
if (ret == G_IO_STATUS_ERROR)
{
g_warning("Error reading socket: %s\n", err->message);
}
/* Process message. */
if (len > 0)
{
/* Skip the the first (cur_dir) and last '\0' for argument count */
gint argc = -1;
gsize i;
for (i = 0; i < len; i ++)
{
if (msg[i] == '\0')
{
argc ++;
}
}
gchar * cur_dir = msg;
gchar * * argv = g_malloc(argc * sizeof(char *));
gint nul_count = 0;
for (i = 0; i < len; i ++)
{
if (msg[i] == '\0' && nul_count < argc)
{
argv[nul_count] = &msg[i + 1];
nul_count ++;
}
}
/* Parse arguments.
* Initialize a new LXTerminal and create a new window. */
CommandArguments arguments;
lxterminal_process_arguments(argc, argv, &arguments);
g_free(argv);
/* Make sure working directory matches that of the client process */
if (arguments.working_directory == NULL)
{
arguments.working_directory = g_strdup(cur_dir);
}
lxterminal_initialize(lxtermwin, &arguments);
}
g_free(msg);
/* If there was a disconnect, discontinue read. Otherwise, continue. */
if (condition & G_IO_HUP)
{
return FALSE;
}
return TRUE;
}
| DoS Bypass | 0 | static gboolean lxterminal_socket_read_channel(GIOChannel * gio, GIOCondition condition, LXTermWindow * lxtermwin)
{
/* Read message. */
gchar * msg = NULL;
gsize len = 0;
GError * err = NULL;
GIOStatus ret = g_io_channel_read_to_end(gio, &msg, &len, &err);
if (ret == G_IO_STATUS_ERROR)
{
g_warning("Error reading socket: %s\n", err->message);
}
/* Process message. */
if (len > 0)
{
/* Skip the the first (cur_dir) and last '\0' for argument count */
gint argc = -1;
gsize i;
for (i = 0; i < len; i ++)
{
if (msg[i] == '\0')
{
argc ++;
}
}
gchar * cur_dir = msg;
gchar * * argv = g_malloc(argc * sizeof(char *));
gint nul_count = 0;
for (i = 0; i < len; i ++)
{
if (msg[i] == '\0' && nul_count < argc)
{
argv[nul_count] = &msg[i + 1];
nul_count ++;
}
}
/* Parse arguments.
* Initialize a new LXTerminal and create a new window. */
CommandArguments arguments;
lxterminal_process_arguments(argc, argv, &arguments);
g_free(argv);
/* Make sure working directory matches that of the client process */
if (arguments.working_directory == NULL)
{
arguments.working_directory = g_strdup(cur_dir);
}
lxterminal_initialize(lxtermwin, &arguments);
}
g_free(msg);
/* If there was a disconnect, discontinue read. Otherwise, continue. */
if (condition & G_IO_HUP)
{
return FALSE;
}
return TRUE;
}
| @@ -140,7 +140,8 @@ gboolean lxterminal_socket_initialize(LXTermWindow * lxtermwin, gint argc, gchar
* This function returns TRUE if this process should keep running and FALSE if it should exit. */
/* Formulate the path for the Unix domain socket. */
- gchar * socket_path = g_strdup_printf("/tmp/.lxterminal-socket%s-%s", gdk_display_get_name(gdk_display_get_default()), g_get_user_name());
+ gchar * socket_path = g_strdup_printf("%s/.lxterminal-socket-%s", g_get_user_runtime_dir(), gdk_display_get_name(gdk_display_get_default()));
+ printf("%s\n", socket_path);
/* Create socket. */
int fd = socket(PF_UNIX, SOCK_STREAM, 0); | CWE-284 | null | null |
10,569 | inline bool HasScripting()
{
return (NPNFuncs.version >= NPVERS_HAS_NPRUNTIME_SCRIPTING);
}
| +Info | 0 | inline bool HasScripting()
{
return (NPNFuncs.version >= NPVERS_HAS_NPRUNTIME_SCRIPTING);
}
| @@ -1108,6 +1108,7 @@ nsPluginInstance::setupCookies(const std::string& pageurl)
ss << "/tmp/gnash-cookies." << getpid();
cookiefile.open(ss.str().c_str(), std::ios::out | std::ios::trunc);
+ chmod (ss.str().c_str(), 0600);
// Firefox provides cookies in the following format:
// | CWE-264 | null | null |
10,570 | NPP_GetMIMEDescription(void)
{
return const_cast<char *>(MIME_TYPES_DESCRIPTION);
}
| +Info | 0 | NPP_GetMIMEDescription(void)
{
return const_cast<char *>(MIME_TYPES_DESCRIPTION);
}
| @@ -1108,6 +1108,7 @@ nsPluginInstance::setupCookies(const std::string& pageurl)
ss << "/tmp/gnash-cookies." << getpid();
cookiefile.open(ss.str().c_str(), std::ios::out | std::ios::trunc);
+ chmod (ss.str().c_str(), 0600);
// Firefox provides cookies in the following format:
// | CWE-264 | null | null |
10,571 | NS_DestroyPluginInstance(nsPluginInstanceBase* aPlugin)
{
delete static_cast<gnash::nsPluginInstance *> (aPlugin);
}
| +Info | 0 | NS_DestroyPluginInstance(nsPluginInstanceBase* aPlugin)
{
delete static_cast<gnash::nsPluginInstance *> (aPlugin);
}
| @@ -1108,6 +1108,7 @@ nsPluginInstance::setupCookies(const std::string& pageurl)
ss << "/tmp/gnash-cookies." << getpid();
cookiefile.open(ss.str().c_str(), std::ios::out | std::ios::trunc);
+ chmod (ss.str().c_str(), 0600);
// Firefox provides cookies in the following format:
// | CWE-264 | null | null |
10,572 | NS_NewPluginInstance(nsPluginCreateData * aCreateDataStruct)
{
if(!aCreateDataStruct) {
return NULL;
}
return new gnash::nsPluginInstance(aCreateDataStruct);
}
| +Info | 0 | NS_NewPluginInstance(nsPluginCreateData * aCreateDataStruct)
{
if(!aCreateDataStruct) {
return NULL;
}
return new gnash::nsPluginInstance(aCreateDataStruct);
}
| @@ -1108,6 +1108,7 @@ nsPluginInstance::setupCookies(const std::string& pageurl)
ss << "/tmp/gnash-cookies." << getpid();
cookiefile.open(ss.str().c_str(), std::ios::out | std::ios::trunc);
+ chmod (ss.str().c_str(), 0600);
// Firefox provides cookies in the following format:
// | CWE-264 | null | null |
10,573 | NS_PluginInitialize()
{
if ( gnash::plugInitialized ) {
gnash::log_debug("NS_PluginInitialize called, but ignored (we already initialized)");
return NPERR_NO_ERROR;
}
gnash::log_debug("NS_PluginInitialize call ---------------------------");
NPError err = NPERR_NO_ERROR;
NPBool supportsXEmbed = TRUE;
err = NPN_GetValue(NULL,NPNVSupportsXEmbedBool,
(void *)&supportsXEmbed);
if (err != NPERR_NO_ERROR || !supportsXEmbed) {
gnash::log_error("NPAPI ERROR: No xEmbed support in this browser!");
return NPERR_INCOMPATIBLE_VERSION_ERROR;
} else {
gnash::log_debug("xEmbed supported in this browser");
}
NPNToolkitType toolkit;
err = NPN_GetValue(NULL, NPNVToolkit, &toolkit);
if (err != NPERR_NO_ERROR || toolkit != NPNVGtk2) {
gnash::log_error("NPAPI ERROR: No GTK2 support in this browser! Have version %d", (int)toolkit);
} else {
gnash::log_debug("GTK2 supported in this browser");
}
/*
Check for environment variables.
*/
char* opts = std::getenv("GNASH_OPTIONS");
if (opts != NULL) {
gnash::log_debug("GNASH_OPTIONS: %s", opts);
if ( strstr(opts, "waitforgdb") ) {
waitforgdb = true;
}
if ( strstr(opts, "writelauncher") ) {
createSaLauncher = true;
}
}
std::string newGnashRc;
#if !defined(__OS2__ ) && ! defined(__amigaos4__)
newGnashRc.append(SYSCONFDIR);
newGnashRc.append("/gnashpluginrc");
#endif
const char *home = NULL;
#if defined(__amigaos4__)
home = "/gnash";
#elif defined(__HAIKU__)
BPath bp;
if (B_OK != find_directory(B_USER_SETTINGS_DIRECTORY, &bp))
{
std::cerr << "Failed to find user settings directory" << std::endl;
} else {
bp.Append("Gnash");
home = bp.Path();
}
#else
home = std::getenv("HOME");
#endif
if ( home ) {
newGnashRc.append(":");
newGnashRc.append(home);
#ifdef __HAIKU__
newGnashRc.append("/gnashpluginrc");
#else
newGnashRc.append("/.gnashpluginrc");
#endif
} else {
gnash::log_error("WARNING: NPAPI plugin could not find user home dir");
}
char *gnashrc = std::getenv("GNASHRC");
if ( gnashrc ) {
newGnashRc.append(":");
newGnashRc.append(gnashrc);
}
if ( setenv("GNASHRC", newGnashRc.c_str(), 1) ) {
gnash::log_debug("WARNING: NPAPI plugin could not append to the GNASHRC env variable");
} else {
gnash::log_debug("NOTE: NPAPI plugin set GNASHRC to %d", newGnashRc);
}
/* Success */
gnash::plugInitialized = TRUE;
return NPERR_NO_ERROR;
}
| +Info | 0 | NS_PluginInitialize()
{
if ( gnash::plugInitialized ) {
gnash::log_debug("NS_PluginInitialize called, but ignored (we already initialized)");
return NPERR_NO_ERROR;
}
gnash::log_debug("NS_PluginInitialize call ---------------------------");
NPError err = NPERR_NO_ERROR;
NPBool supportsXEmbed = TRUE;
err = NPN_GetValue(NULL,NPNVSupportsXEmbedBool,
(void *)&supportsXEmbed);
if (err != NPERR_NO_ERROR || !supportsXEmbed) {
gnash::log_error("NPAPI ERROR: No xEmbed support in this browser!");
return NPERR_INCOMPATIBLE_VERSION_ERROR;
} else {
gnash::log_debug("xEmbed supported in this browser");
}
NPNToolkitType toolkit;
err = NPN_GetValue(NULL, NPNVToolkit, &toolkit);
if (err != NPERR_NO_ERROR || toolkit != NPNVGtk2) {
gnash::log_error("NPAPI ERROR: No GTK2 support in this browser! Have version %d", (int)toolkit);
} else {
gnash::log_debug("GTK2 supported in this browser");
}
/*
Check for environment variables.
*/
char* opts = std::getenv("GNASH_OPTIONS");
if (opts != NULL) {
gnash::log_debug("GNASH_OPTIONS: %s", opts);
if ( strstr(opts, "waitforgdb") ) {
waitforgdb = true;
}
if ( strstr(opts, "writelauncher") ) {
createSaLauncher = true;
}
}
std::string newGnashRc;
#if !defined(__OS2__ ) && ! defined(__amigaos4__)
newGnashRc.append(SYSCONFDIR);
newGnashRc.append("/gnashpluginrc");
#endif
const char *home = NULL;
#if defined(__amigaos4__)
home = "/gnash";
#elif defined(__HAIKU__)
BPath bp;
if (B_OK != find_directory(B_USER_SETTINGS_DIRECTORY, &bp))
{
std::cerr << "Failed to find user settings directory" << std::endl;
} else {
bp.Append("Gnash");
home = bp.Path();
}
#else
home = std::getenv("HOME");
#endif
if ( home ) {
newGnashRc.append(":");
newGnashRc.append(home);
#ifdef __HAIKU__
newGnashRc.append("/gnashpluginrc");
#else
newGnashRc.append("/.gnashpluginrc");
#endif
} else {
gnash::log_error("WARNING: NPAPI plugin could not find user home dir");
}
char *gnashrc = std::getenv("GNASHRC");
if ( gnashrc ) {
newGnashRc.append(":");
newGnashRc.append(gnashrc);
}
if ( setenv("GNASHRC", newGnashRc.c_str(), 1) ) {
gnash::log_debug("WARNING: NPAPI plugin could not append to the GNASHRC env variable");
} else {
gnash::log_debug("NOTE: NPAPI plugin set GNASHRC to %d", newGnashRc);
}
/* Success */
gnash::plugInitialized = TRUE;
return NPERR_NO_ERROR;
}
| @@ -1108,6 +1108,7 @@ nsPluginInstance::setupCookies(const std::string& pageurl)
ss << "/tmp/gnash-cookies." << getpid();
cookiefile.open(ss.str().c_str(), std::ios::out | std::ios::trunc);
+ chmod (ss.str().c_str(), 0600);
// Firefox provides cookies in the following format:
// | CWE-264 | null | null |
10,574 | NS_PluginShutdown()
{
#if 0
if (!plugInitialized) {
gnash::log_debug("Plugin already shut down");
return;
}
plugInitialized = FALSE;
#endif
}
| +Info | 0 | NS_PluginShutdown()
{
#if 0
if (!plugInitialized) {
gnash::log_debug("Plugin already shut down");
return;
}
plugInitialized = FALSE;
#endif
}
| @@ -1108,6 +1108,7 @@ nsPluginInstance::setupCookies(const std::string& pageurl)
ss << "/tmp/gnash-cookies." << getpid();
cookiefile.open(ss.str().c_str(), std::ios::out | std::ios::trunc);
+ chmod (ss.str().c_str(), 0600);
// Firefox provides cookies in the following format:
// | CWE-264 | null | null |
10,575 | nsPluginInstance::NewStream(NPMIMEType /*type*/, NPStream* stream,
NPBool /*seekable*/, uint16_t* /*stype*/)
{
if (_childpid) {
return NPERR_GENERIC_ERROR;
}
_swf_url = stream->url;
if (!_swf_url.empty() && _window) {
return startProc();
}
return NPERR_NO_ERROR;
}
| +Info | 0 | nsPluginInstance::NewStream(NPMIMEType /*type*/, NPStream* stream,
NPBool /*seekable*/, uint16_t* /*stype*/)
{
if (_childpid) {
return NPERR_GENERIC_ERROR;
}
_swf_url = stream->url;
if (!_swf_url.empty() && _window) {
return startProc();
}
return NPERR_NO_ERROR;
}
| @@ -1108,6 +1108,7 @@ nsPluginInstance::setupCookies(const std::string& pageurl)
ss << "/tmp/gnash-cookies." << getpid();
cookiefile.open(ss.str().c_str(), std::ios::out | std::ios::trunc);
+ chmod (ss.str().c_str(), 0600);
// Firefox provides cookies in the following format:
// | CWE-264 | null | null |
10,576 | nsPluginInstance::SetWindow(NPWindow* aWindow)
{
if(!aWindow) {
gnash::log_error(std::string(__FUNCTION__) + ": ERROR: Window handle was bogus!");
return NPERR_INVALID_PARAM;
#if 0
} else {
gnash::log_debug("%s: X origin = %d, Y Origin = %d, Width = %d,"
" Height = %d, WindowID = %p, this = %p",
__FUNCTION__,
aWindow->x, aWindow->y, aWindow->width, aWindow->height,
aWindow->window, this);
#endif
}
if (_window) {
return NPERR_GENERIC_ERROR;
}
_width = aWindow->width;
_height = aWindow->height;
_window = reinterpret_cast<Window> (aWindow->window);
if (!_childpid && !_swf_url.empty()) {
return startProc();
}
return NPERR_NO_ERROR;
}
| +Info | 0 | nsPluginInstance::SetWindow(NPWindow* aWindow)
{
if(!aWindow) {
gnash::log_error(std::string(__FUNCTION__) + ": ERROR: Window handle was bogus!");
return NPERR_INVALID_PARAM;
#if 0
} else {
gnash::log_debug("%s: X origin = %d, Y Origin = %d, Width = %d,"
" Height = %d, WindowID = %p, this = %p",
__FUNCTION__,
aWindow->x, aWindow->y, aWindow->width, aWindow->height,
aWindow->window, this);
#endif
}
if (_window) {
return NPERR_GENERIC_ERROR;
}
_width = aWindow->width;
_height = aWindow->height;
_window = reinterpret_cast<Window> (aWindow->window);
if (!_childpid && !_swf_url.empty()) {
return startProc();
}
return NPERR_NO_ERROR;
}
| @@ -1108,6 +1108,7 @@ nsPluginInstance::setupCookies(const std::string& pageurl)
ss << "/tmp/gnash-cookies." << getpid();
cookiefile.open(ss.str().c_str(), std::ios::out | std::ios::trunc);
+ chmod (ss.str().c_str(), 0600);
// Firefox provides cookies in the following format:
// | CWE-264 | null | null |
10,577 | nsPluginInstance::WriteReady(NPStream* /* stream */ )
{
if ( _streamfd != -1 ) {
return 1024;
} else {
return 0;
}
}
| +Info | 0 | nsPluginInstance::WriteReady(NPStream* /* stream */ )
{
if ( _streamfd != -1 ) {
return 1024;
} else {
return 0;
}
}
| @@ -1108,6 +1108,7 @@ nsPluginInstance::setupCookies(const std::string& pageurl)
ss << "/tmp/gnash-cookies." << getpid();
cookiefile.open(ss.str().c_str(), std::ios::out | std::ios::trunc);
+ chmod (ss.str().c_str(), 0600);
// Firefox provides cookies in the following format:
// | CWE-264 | null | null |
10,578 | cleanup_childpid(gpointer data)
{
int* pid = static_cast<int*>(data);
int status;
int rv = waitpid(*pid, &status, WNOHANG);
if (rv <= 0) {
kill(*pid, SIGKILL);
waitpid(*pid, &status, 0);
}
gnash::log_debug("Child process exited with status %s", status);
delete pid;
return FALSE;
}
| +Info | 0 | cleanup_childpid(gpointer data)
{
int* pid = static_cast<int*>(data);
int status;
int rv = waitpid(*pid, &status, WNOHANG);
if (rv <= 0) {
kill(*pid, SIGKILL);
waitpid(*pid, &status, 0);
}
gnash::log_debug("Child process exited with status %s", status);
delete pid;
return FALSE;
}
| @@ -1108,6 +1108,7 @@ nsPluginInstance::setupCookies(const std::string& pageurl)
ss << "/tmp/gnash-cookies." << getpid();
cookiefile.open(ss.str().c_str(), std::ios::out | std::ios::trunc);
+ chmod (ss.str().c_str(), 0600);
// Firefox provides cookies in the following format:
// | CWE-264 | null | null |
10,579 | close_fds(const int (& except)[N])
{
int numfailed = 0, closed = 0;
for (int anfd = fileno(stderr)+1; numfailed < 10; anfd++) {
if (std::find(except, except+N, anfd) != except+N) {
continue;
}
if (close(anfd) < 0) {
numfailed++;
} else {
numfailed = 0;
closed++;
}
}
gnash::log_debug("Closed %d files.", closed);
}
| +Info | 0 | close_fds(const int (& except)[N])
{
int numfailed = 0, closed = 0;
for (int anfd = fileno(stderr)+1; numfailed < 10; anfd++) {
if (std::find(except, except+N, anfd) != except+N) {
continue;
}
if (close(anfd) < 0) {
numfailed++;
} else {
numfailed = 0;
closed++;
}
}
gnash::log_debug("Closed %d files.", closed);
}
| @@ -1108,6 +1108,7 @@ nsPluginInstance::setupCookies(const std::string& pageurl)
ss << "/tmp/gnash-cookies." << getpid();
cookiefile.open(ss.str().c_str(), std::ios::out | std::ios::trunc);
+ chmod (ss.str().c_str(), 0600);
// Firefox provides cookies in the following format:
// | CWE-264 | null | null |
10,580 | create_standalone_launcher(const std::string& page_url, const std::string& swf_url,
const std::map<std::string, std::string>& params)
{
#ifdef CREATE_STANDALONE_GNASH_LAUNCHER
if (!createSaLauncher) {
return;
}
std::ofstream saLauncher;
std::stringstream ss;
static int debugno = 0;
debugno = (debugno + 1) % 10;
ss << "/tmp/gnash-debug-" << debugno << ".sh";
saLauncher.open(ss.str().c_str(), std::ios::out | std::ios::trunc);
if (!saLauncher) {
gnash::log_error("Failed to open new file for standalone launcher: " + ss.str());
return;
}
saLauncher << "#!/bin/sh" << std::endl
<< "export GNASH_COOKIES_IN="
<< "/tmp/gnash-cookies." << getpid() << std::endl
<< getGnashExecutable() << " ";
if (!page_url.empty()) {
saLauncher << "-U '" << page_url << "' ";
}
for (std::map<std::string,std::string>::const_iterator it = params.begin(),
itEnd = params.end(); it != itEnd; ++it) {
const std::string& nam = it->first;
const std::string& val = it->second;
saLauncher << "-P '"
<< boost::algorithm::replace_all_copy(nam, "'", "'\\''")
<< "="
<< boost::algorithm::replace_all_copy(val, "'", "'\\''")
<< "' ";
}
saLauncher << "'" << swf_url << "' "
<< "$@" // allow caller to pass any additional argument
<< std::endl;
saLauncher.close();
#endif
}
| +Info | 0 | create_standalone_launcher(const std::string& page_url, const std::string& swf_url,
const std::map<std::string, std::string>& params)
{
#ifdef CREATE_STANDALONE_GNASH_LAUNCHER
if (!createSaLauncher) {
return;
}
std::ofstream saLauncher;
std::stringstream ss;
static int debugno = 0;
debugno = (debugno + 1) % 10;
ss << "/tmp/gnash-debug-" << debugno << ".sh";
saLauncher.open(ss.str().c_str(), std::ios::out | std::ios::trunc);
if (!saLauncher) {
gnash::log_error("Failed to open new file for standalone launcher: " + ss.str());
return;
}
saLauncher << "#!/bin/sh" << std::endl
<< "export GNASH_COOKIES_IN="
<< "/tmp/gnash-cookies." << getpid() << std::endl
<< getGnashExecutable() << " ";
if (!page_url.empty()) {
saLauncher << "-U '" << page_url << "' ";
}
for (std::map<std::string,std::string>::const_iterator it = params.begin(),
itEnd = params.end(); it != itEnd; ++it) {
const std::string& nam = it->first;
const std::string& val = it->second;
saLauncher << "-P '"
<< boost::algorithm::replace_all_copy(nam, "'", "'\\''")
<< "="
<< boost::algorithm::replace_all_copy(val, "'", "'\\''")
<< "' ";
}
saLauncher << "'" << swf_url << "' "
<< "$@" // allow caller to pass any additional argument
<< std::endl;
saLauncher.close();
#endif
}
| @@ -1108,6 +1108,7 @@ nsPluginInstance::setupCookies(const std::string& pageurl)
ss << "/tmp/gnash-cookies." << getpid();
cookiefile.open(ss.str().c_str(), std::ios::out | std::ios::trunc);
+ chmod (ss.str().c_str(), 0600);
// Firefox provides cookies in the following format:
// | CWE-264 | null | null |
10,581 | nsPluginInstance::getCmdLine(int hostfd, int controlfd)
{
std::vector<std::string> arg_vec;
std::string cmd = getGnashExecutable();
if (cmd.empty()) {
gnash::log_error("Failed to locate the Gnash executable!");
return arg_vec;
}
arg_vec.push_back(cmd);
arg_vec.push_back("-u");
arg_vec.push_back(_swf_url);
std::string pageurl = getCurrentPageURL();
if (pageurl.empty()) {
gnash::log_error("Could not get current page URL!");
} else {
arg_vec.push_back("-U");
arg_vec.push_back(pageurl);
}
setupCookies(pageurl);
setupProxy(pageurl);
std::stringstream pars;
pars << "-x " << _window // X window ID to render into
<< " -j " << _width // Width of window
<< " -k " << _height; // Height of window
#if GNASH_PLUGIN_DEBUG > 1
pars << " -vv ";
#endif
if ((hostfd > 0) && (controlfd)) {
pars << " -F " << hostfd // Socket to send commands to
<< ":" << controlfd; // Socket determining lifespan
}
std::string pars_str = pars.str();
typedef boost::char_separator<char> char_sep;
boost::tokenizer<char_sep> tok(pars_str, char_sep(" "));
arg_vec.insert(arg_vec.end(), tok.begin(), tok.end());
for (std::map<std::string,std::string>::const_iterator it = _params.begin(),
itEnd = _params.end(); it != itEnd; ++it) {
const std::string& nam = it->first;
const std::string& val = it->second;
arg_vec.push_back("-P");
arg_vec.push_back(nam + "=" + val);
}
arg_vec.push_back("-");
create_standalone_launcher(pageurl, _swf_url, _params);
return arg_vec;
}
| +Info | 0 | nsPluginInstance::getCmdLine(int hostfd, int controlfd)
{
std::vector<std::string> arg_vec;
std::string cmd = getGnashExecutable();
if (cmd.empty()) {
gnash::log_error("Failed to locate the Gnash executable!");
return arg_vec;
}
arg_vec.push_back(cmd);
arg_vec.push_back("-u");
arg_vec.push_back(_swf_url);
std::string pageurl = getCurrentPageURL();
if (pageurl.empty()) {
gnash::log_error("Could not get current page URL!");
} else {
arg_vec.push_back("-U");
arg_vec.push_back(pageurl);
}
setupCookies(pageurl);
setupProxy(pageurl);
std::stringstream pars;
pars << "-x " << _window // X window ID to render into
<< " -j " << _width // Width of window
<< " -k " << _height; // Height of window
#if GNASH_PLUGIN_DEBUG > 1
pars << " -vv ";
#endif
if ((hostfd > 0) && (controlfd)) {
pars << " -F " << hostfd // Socket to send commands to
<< ":" << controlfd; // Socket determining lifespan
}
std::string pars_str = pars.str();
typedef boost::char_separator<char> char_sep;
boost::tokenizer<char_sep> tok(pars_str, char_sep(" "));
arg_vec.insert(arg_vec.end(), tok.begin(), tok.end());
for (std::map<std::string,std::string>::const_iterator it = _params.begin(),
itEnd = _params.end(); it != itEnd; ++it) {
const std::string& nam = it->first;
const std::string& val = it->second;
arg_vec.push_back("-P");
arg_vec.push_back(nam + "=" + val);
}
arg_vec.push_back("-");
create_standalone_launcher(pageurl, _swf_url, _params);
return arg_vec;
}
| @@ -1108,6 +1108,7 @@ nsPluginInstance::setupCookies(const std::string& pageurl)
ss << "/tmp/gnash-cookies." << getpid();
cookiefile.open(ss.str().c_str(), std::ios::out | std::ios::trunc);
+ chmod (ss.str().c_str(), 0600);
// Firefox provides cookies in the following format:
// | CWE-264 | null | null |
10,582 | nsPluginInstance::getCurrentPageURL() const
{
return getDocumentProp("baseURI");
}
| +Info | 0 | nsPluginInstance::getCurrentPageURL() const
{
return getDocumentProp("baseURI");
}
| @@ -1108,6 +1108,7 @@ nsPluginInstance::setupCookies(const std::string& pageurl)
ss << "/tmp/gnash-cookies." << getpid();
cookiefile.open(ss.str().c_str(), std::ios::out | std::ios::trunc);
+ chmod (ss.str().c_str(), 0600);
// Firefox provides cookies in the following format:
// | CWE-264 | null | null |
10,583 | nsPluginInstance::getDocumentProp(const std::string& propname) const
{
std::string rv;
if (!HasScripting()) {
LOG_ONCE( gnash::log_debug("Browser doesn't support scripting") );
return rv;
}
NPObject* windowobj;
NPError err = NPN_GetValue(_instance, NPNVWindowNPObject, &windowobj);
if (err != NPERR_NO_ERROR || !windowobj) {
return rv;
}
boost::shared_ptr<NPObject> window_obj(windowobj, NPN_ReleaseObject);
NPIdentifier doc_id = NPN_GetStringIdentifier("document");
NPVariant docvar;
if(! NPN_GetProperty(_instance, windowobj, doc_id, &docvar) ) {
return rv;
}
boost::shared_ptr<NPVariant> doc_var(&docvar, NPN_ReleaseVariantValue);
if (!NPVARIANT_IS_OBJECT(docvar)) {
return rv;
}
NPObject* doc_obj = NPVARIANT_TO_OBJECT(docvar);
NPIdentifier prop_id = NPN_GetStringIdentifier(propname.c_str());
NPVariant propvar;
if (!NPN_GetProperty(_instance, doc_obj, prop_id, &propvar)) {
return rv;
}
boost::shared_ptr<NPVariant> prop_var(&propvar, NPN_ReleaseVariantValue);
if (!NPVARIANT_IS_STRING(propvar)) {
return rv;
}
const NPString& prop_str = NPVARIANT_TO_STRING(propvar);
rv = NPStringToString(prop_str);
return rv;
}
| +Info | 0 | nsPluginInstance::getDocumentProp(const std::string& propname) const
{
std::string rv;
if (!HasScripting()) {
LOG_ONCE( gnash::log_debug("Browser doesn't support scripting") );
return rv;
}
NPObject* windowobj;
NPError err = NPN_GetValue(_instance, NPNVWindowNPObject, &windowobj);
if (err != NPERR_NO_ERROR || !windowobj) {
return rv;
}
boost::shared_ptr<NPObject> window_obj(windowobj, NPN_ReleaseObject);
NPIdentifier doc_id = NPN_GetStringIdentifier("document");
NPVariant docvar;
if(! NPN_GetProperty(_instance, windowobj, doc_id, &docvar) ) {
return rv;
}
boost::shared_ptr<NPVariant> doc_var(&docvar, NPN_ReleaseVariantValue);
if (!NPVARIANT_IS_OBJECT(docvar)) {
return rv;
}
NPObject* doc_obj = NPVARIANT_TO_OBJECT(docvar);
NPIdentifier prop_id = NPN_GetStringIdentifier(propname.c_str());
NPVariant propvar;
if (!NPN_GetProperty(_instance, doc_obj, prop_id, &propvar)) {
return rv;
}
boost::shared_ptr<NPVariant> prop_var(&propvar, NPN_ReleaseVariantValue);
if (!NPVARIANT_IS_STRING(propvar)) {
return rv;
}
const NPString& prop_str = NPVARIANT_TO_STRING(propvar);
rv = NPStringToString(prop_str);
return rv;
}
| @@ -1108,6 +1108,7 @@ nsPluginInstance::setupCookies(const std::string& pageurl)
ss << "/tmp/gnash-cookies." << getpid();
cookiefile.open(ss.str().c_str(), std::ios::out | std::ios::trunc);
+ chmod (ss.str().c_str(), 0600);
// Firefox provides cookies in the following format:
// | CWE-264 | null | null |
10,584 | getGnashExecutable()
{
std::string procname;
bool process_found = false;
struct stat procstats;
char *gnash_env = std::getenv("GNASH_PLAYER");
if (gnash_env) {
procname = gnash_env;
process_found = (0 == stat(procname.c_str(), &procstats));
if (!process_found) {
gnash::log_error("Invalid path to gnash executable: ");
return "";
}
}
if (!process_found) {
procname = GNASHBINDIR "/gtk-gnash";
process_found = (0 == stat(procname.c_str(), &procstats));
}
if (!process_found) {
procname = GNASHBINDIR "/qt4-gnash";
process_found = (0 == stat(procname.c_str(), &procstats));
}
if (!process_found) {
gnash::log_error(std::string("Unable to find Gnash in ") + GNASHBINDIR);
return "";
}
return procname;
}
| +Info | 0 | getGnashExecutable()
{
std::string procname;
bool process_found = false;
struct stat procstats;
char *gnash_env = std::getenv("GNASH_PLAYER");
if (gnash_env) {
procname = gnash_env;
process_found = (0 == stat(procname.c_str(), &procstats));
if (!process_found) {
gnash::log_error("Invalid path to gnash executable: ");
return "";
}
}
if (!process_found) {
procname = GNASHBINDIR "/gtk-gnash";
process_found = (0 == stat(procname.c_str(), &procstats));
}
if (!process_found) {
procname = GNASHBINDIR "/qt4-gnash";
process_found = (0 == stat(procname.c_str(), &procstats));
}
if (!process_found) {
gnash::log_error(std::string("Unable to find Gnash in ") + GNASHBINDIR);
return "";
}
return procname;
}
| @@ -1108,6 +1108,7 @@ nsPluginInstance::setupCookies(const std::string& pageurl)
ss << "/tmp/gnash-cookies." << getpid();
cookiefile.open(ss.str().c_str(), std::ios::out | std::ios::trunc);
+ chmod (ss.str().c_str(), 0600);
// Firefox provides cookies in the following format:
// | CWE-264 | null | null |
10,585 | nsPluginInstance::handlePlayerRequests(GIOChannel* iochan, GIOCondition cond)
{
if ( cond & G_IO_HUP ) {
gnash::log_debug("Player control socket hang up");
return false;
}
assert(cond & G_IO_IN);
gnash::log_debug("Checking player requests on FD #%d",
g_io_channel_unix_get_fd(iochan));
const size_t buf_size = 1;
gchar buffer[buf_size];
do {
GError* error = 0;
gsize bytes_read = 0;
GIOStatus status = g_io_channel_read_chars(iochan, buffer, buf_size,
&bytes_read, &error);
switch (status) {
case G_IO_STATUS_ERROR:
gnash::log_error("error reading request line: %s",
error ? error->message : "unspecified error");
g_error_free(error);
return false;
case G_IO_STATUS_EOF:
gnash::log_error("EOF (error: %s)",
error ? error->message : "unspecified error");
g_error_free(error);
return false;
case G_IO_STATUS_AGAIN:
gnash::log_debug("read again");
continue;
case G_IO_STATUS_NORMAL:
_requestbuf.append(buffer, buffer+bytes_read);
#if 0
gnash::log_debug("Normal read: %s", std::string(buffer, buffer+bytes_read));
#endif
break;
default:
gnash::log_error("Abnormal status!");
return false;
}
} while (g_io_channel_get_buffer_condition(iochan) & G_IO_IN);
processPlayerRequest();
return true;
}
| +Info | 0 | nsPluginInstance::handlePlayerRequests(GIOChannel* iochan, GIOCondition cond)
{
if ( cond & G_IO_HUP ) {
gnash::log_debug("Player control socket hang up");
return false;
}
assert(cond & G_IO_IN);
gnash::log_debug("Checking player requests on FD #%d",
g_io_channel_unix_get_fd(iochan));
const size_t buf_size = 1;
gchar buffer[buf_size];
do {
GError* error = 0;
gsize bytes_read = 0;
GIOStatus status = g_io_channel_read_chars(iochan, buffer, buf_size,
&bytes_read, &error);
switch (status) {
case G_IO_STATUS_ERROR:
gnash::log_error("error reading request line: %s",
error ? error->message : "unspecified error");
g_error_free(error);
return false;
case G_IO_STATUS_EOF:
gnash::log_error("EOF (error: %s)",
error ? error->message : "unspecified error");
g_error_free(error);
return false;
case G_IO_STATUS_AGAIN:
gnash::log_debug("read again");
continue;
case G_IO_STATUS_NORMAL:
_requestbuf.append(buffer, buffer+bytes_read);
#if 0
gnash::log_debug("Normal read: %s", std::string(buffer, buffer+bytes_read));
#endif
break;
default:
gnash::log_error("Abnormal status!");
return false;
}
} while (g_io_channel_get_buffer_condition(iochan) & G_IO_IN);
processPlayerRequest();
return true;
}
| @@ -1108,6 +1108,7 @@ nsPluginInstance::setupCookies(const std::string& pageurl)
ss << "/tmp/gnash-cookies." << getpid();
cookiefile.open(ss.str().c_str(), std::ios::out | std::ios::trunc);
+ chmod (ss.str().c_str(), 0600);
// Firefox provides cookies in the following format:
// | CWE-264 | null | null |
10,586 | nsPluginInstance::nsPluginInstance(nsPluginCreateData* data)
:
nsPluginInstanceBase(),
_instance(data->instance),
_window(0),
_width(0),
_height(0),
_streamfd(-1),
_childpid(0),
_filefd(-1),
_name(),
_scriptObject(0)
{
for (size_t i=0, n=data->argc; i<n; ++i) {
std::string name, val;
gnash::StringNoCaseEqual noCaseCompare;
if (data->argn[i]) {
name = data->argn[i];
}
if (data->argv[i]) {
val = data->argv[i];
}
if (noCaseCompare(name, "name")) {
_name = val;
}
_params[name] = val;
}
if (HasScripting()) {
_scriptObject = (GnashPluginScriptObject*) NPN_CreateObject( _instance,
GnashPluginScriptObject::marshalGetNPClass());
}
return;
}
| +Info | 0 | nsPluginInstance::nsPluginInstance(nsPluginCreateData* data)
:
nsPluginInstanceBase(),
_instance(data->instance),
_window(0),
_width(0),
_height(0),
_streamfd(-1),
_childpid(0),
_filefd(-1),
_name(),
_scriptObject(0)
{
for (size_t i=0, n=data->argc; i<n; ++i) {
std::string name, val;
gnash::StringNoCaseEqual noCaseCompare;
if (data->argn[i]) {
name = data->argn[i];
}
if (data->argv[i]) {
val = data->argv[i];
}
if (noCaseCompare(name, "name")) {
_name = val;
}
_params[name] = val;
}
if (HasScripting()) {
_scriptObject = (GnashPluginScriptObject*) NPN_CreateObject( _instance,
GnashPluginScriptObject::marshalGetNPClass());
}
return;
}
| @@ -1108,6 +1108,7 @@ nsPluginInstance::setupCookies(const std::string& pageurl)
ss << "/tmp/gnash-cookies." << getpid();
cookiefile.open(ss.str().c_str(), std::ios::out | std::ios::trunc);
+ chmod (ss.str().c_str(), 0600);
// Firefox provides cookies in the following format:
// | CWE-264 | null | null |
10,587 | processLog_debug(const boost::format& fmt)
{
std::cout << "DEBUG: " << fmt.str() << std::endl;
}
| +Info | 0 | processLog_debug(const boost::format& fmt)
{
std::cout << "DEBUG: " << fmt.str() << std::endl;
}
| @@ -1108,6 +1108,7 @@ nsPluginInstance::setupCookies(const std::string& pageurl)
ss << "/tmp/gnash-cookies." << getpid();
cookiefile.open(ss.str().c_str(), std::ios::out | std::ios::trunc);
+ chmod (ss.str().c_str(), 0600);
// Firefox provides cookies in the following format:
// | CWE-264 | null | null |
10,588 | processLog_debug(const boost::format& /* fmt */)
{ /* do nothing */ }
| +Info | 0 | processLog_debug(const boost::format& /* fmt */)
{ /* do nothing */ }
| @@ -1108,6 +1108,7 @@ nsPluginInstance::setupCookies(const std::string& pageurl)
ss << "/tmp/gnash-cookies." << getpid();
cookiefile.open(ss.str().c_str(), std::ios::out | std::ios::trunc);
+ chmod (ss.str().c_str(), 0600);
// Firefox provides cookies in the following format:
// | CWE-264 | null | null |
10,589 | processLog_trace(const boost::format& fmt)
{
std::cout << "TRACE: " << fmt.str() << std::endl;
}
| +Info | 0 | processLog_trace(const boost::format& fmt)
{
std::cout << "TRACE: " << fmt.str() << std::endl;
}
| @@ -1108,6 +1108,7 @@ nsPluginInstance::setupCookies(const std::string& pageurl)
ss << "/tmp/gnash-cookies." << getpid();
cookiefile.open(ss.str().c_str(), std::ios::out | std::ios::trunc);
+ chmod (ss.str().c_str(), 0600);
// Firefox provides cookies in the following format:
// | CWE-264 | null | null |
10,590 | processLog_trace(const boost::format& /* fmt */)
{ /* do nothing */ }
| +Info | 0 | processLog_trace(const boost::format& /* fmt */)
{ /* do nothing */ }
| @@ -1108,6 +1108,7 @@ nsPluginInstance::setupCookies(const std::string& pageurl)
ss << "/tmp/gnash-cookies." << getpid();
cookiefile.open(ss.str().c_str(), std::ios::out | std::ios::trunc);
+ chmod (ss.str().c_str(), 0600);
// Firefox provides cookies in the following format:
// | CWE-264 | null | null |
10,591 | remove_handler(GIOChannel*, GIOCondition, gpointer)
{
return FALSE;
}
| +Info | 0 | remove_handler(GIOChannel*, GIOCondition, gpointer)
{
return FALSE;
}
| @@ -1108,6 +1108,7 @@ nsPluginInstance::setupCookies(const std::string& pageurl)
ss << "/tmp/gnash-cookies." << getpid();
cookiefile.open(ss.str().c_str(), std::ios::out | std::ios::trunc);
+ chmod (ss.str().c_str(), 0600);
// Firefox provides cookies in the following format:
// | CWE-264 | null | null |
10,592 | nsPluginInstance::setupProxy(const std::string& url)
{
#if NPAPI_VERSION != 190
if (!NPNFuncs.getvalueforurl) return;
#endif
char *proxy = 0;
uint32_t length = 0;
#if NPAPI_VERSION != 190
NPN_GetValueForURL(_instance, NPNURLVProxy, url.c_str(),
&proxy, &length);
#endif
if (!proxy) {
gnash::log_debug("No proxy setting for %s", url);
return;
}
std::string nproxy (proxy, length);
NPN_MemFree(proxy);
gnash::log_debug("Proxy setting for %s is %s", url, nproxy);
std::vector<std::string> parts;
boost::split(parts, nproxy,
boost::is_any_of(" "), boost::token_compress_on);
if ( parts[0] == "DIRECT" ) {
}
else if ( parts[0] == "PROXY" ) {
if (setenv("http_proxy", parts[1].c_str(), 1) < 0) {
gnash::log_error(
"Couldn't set environment variable http_proxy to %s",
nproxy);
}
}
else {
gnash::log_error("Unknown proxy type: %s", nproxy);
}
}
| +Info | 0 | nsPluginInstance::setupProxy(const std::string& url)
{
#if NPAPI_VERSION != 190
if (!NPNFuncs.getvalueforurl) return;
#endif
char *proxy = 0;
uint32_t length = 0;
#if NPAPI_VERSION != 190
NPN_GetValueForURL(_instance, NPNURLVProxy, url.c_str(),
&proxy, &length);
#endif
if (!proxy) {
gnash::log_debug("No proxy setting for %s", url);
return;
}
std::string nproxy (proxy, length);
NPN_MemFree(proxy);
gnash::log_debug("Proxy setting for %s is %s", url, nproxy);
std::vector<std::string> parts;
boost::split(parts, nproxy,
boost::is_any_of(" "), boost::token_compress_on);
if ( parts[0] == "DIRECT" ) {
}
else if ( parts[0] == "PROXY" ) {
if (setenv("http_proxy", parts[1].c_str(), 1) < 0) {
gnash::log_error(
"Couldn't set environment variable http_proxy to %s",
nproxy);
}
}
else {
gnash::log_error("Unknown proxy type: %s", nproxy);
}
}
| @@ -1108,6 +1108,7 @@ nsPluginInstance::setupCookies(const std::string& pageurl)
ss << "/tmp/gnash-cookies." << getpid();
cookiefile.open(ss.str().c_str(), std::ios::out | std::ios::trunc);
+ chmod (ss.str().c_str(), 0600);
// Firefox provides cookies in the following format:
// | CWE-264 | null | null |
10,593 | nsPluginInstance::startProc()
{
int p2c_pipe[2];
int c2p_pipe[2];
int p2c_controlpipe[2];
int ret = socketpair(AF_UNIX, SOCK_STREAM, 0, p2c_pipe);
if (ret == -1) {
gnash::log_error("socketpair(p2c) failed: %s", strerror(errno));
return NPERR_GENERIC_ERROR;
}
_streamfd = p2c_pipe[1];
ret = socketpair(AF_UNIX, SOCK_STREAM, 0, c2p_pipe);
if (ret == -1) {
gnash::log_error("socketpair(c2p) failed: %s", strerror(errno));
return NPERR_GENERIC_ERROR;
}
ret = socketpair(AF_UNIX, SOCK_STREAM, 0, p2c_controlpipe);
if (ret == -1) {
gnash::log_error("socketpair(control) failed: %s", strerror(errno));
return NPERR_GENERIC_ERROR;
}
if (HasScripting() && _scriptObject) {
_scriptObject->setControlFD(p2c_controlpipe[1]);
_scriptObject->setHostFD(c2p_pipe[0]);
}
std::vector<std::string> arg_vec = getCmdLine(c2p_pipe[1],
p2c_controlpipe[0]);
if (arg_vec.empty()) {
gnash::log_error("Failed to obtain command line parameters.");
return NPERR_GENERIC_ERROR;
}
std::vector<const char*> args;
std::transform(arg_vec.begin(), arg_vec.end(), std::back_inserter(args),
std::mem_fun_ref(&std::string::c_str));
args.push_back(0);
_childpid = fork();
if (_childpid == -1) {
gnash::log_error("fork() failed: %s", strerror(errno));
return NPERR_OUT_OF_MEMORY_ERROR;
}
if (_childpid > 0) {
ret = close (p2c_pipe[0]);
if (ret == -1) {
gnash::log_error("p2c_pipe[0] close() failed: %s",
strerror(errno));
}
ret = close (c2p_pipe[1]);
if (ret == -1) {
gnash::log_error("c2p_pipe[1] close() failed: %s",
strerror(errno));
gnash::log_debug("Forked successfully but with ignorable errors.");
} else {
gnash::log_debug("Forked successfully, child process PID is %d",
_childpid);
}
setupIOChannel(c2p_pipe[0], (GIOFunc)handlePlayerRequestsWrapper,
(GIOCondition)(G_IO_IN|G_IO_HUP));
setupIOChannel(p2c_controlpipe[1], remove_handler, G_IO_HUP);
return NPERR_NO_ERROR;
}
ret = close (p2c_pipe[1]);
ret = dup2 (p2c_pipe[0], fileno(stdin));
if (ret == -1) {
gnash::log_error("dup2() failed: %s", strerror(errno));
}
int dontclose[] = {c2p_pipe[1], c2p_pipe[0], p2c_controlpipe[0]};
close_fds(dontclose);
gnash::log_debug("Starting process: %s", boost::algorithm::join(arg_vec, " "));
wait_for_gdb();
execv(args[0], const_cast<char**>(&args.front()));
perror("executing standalone gnash");
exit (-1);
}
| +Info | 0 | nsPluginInstance::startProc()
{
int p2c_pipe[2];
int c2p_pipe[2];
int p2c_controlpipe[2];
int ret = socketpair(AF_UNIX, SOCK_STREAM, 0, p2c_pipe);
if (ret == -1) {
gnash::log_error("socketpair(p2c) failed: %s", strerror(errno));
return NPERR_GENERIC_ERROR;
}
_streamfd = p2c_pipe[1];
ret = socketpair(AF_UNIX, SOCK_STREAM, 0, c2p_pipe);
if (ret == -1) {
gnash::log_error("socketpair(c2p) failed: %s", strerror(errno));
return NPERR_GENERIC_ERROR;
}
ret = socketpair(AF_UNIX, SOCK_STREAM, 0, p2c_controlpipe);
if (ret == -1) {
gnash::log_error("socketpair(control) failed: %s", strerror(errno));
return NPERR_GENERIC_ERROR;
}
if (HasScripting() && _scriptObject) {
_scriptObject->setControlFD(p2c_controlpipe[1]);
_scriptObject->setHostFD(c2p_pipe[0]);
}
std::vector<std::string> arg_vec = getCmdLine(c2p_pipe[1],
p2c_controlpipe[0]);
if (arg_vec.empty()) {
gnash::log_error("Failed to obtain command line parameters.");
return NPERR_GENERIC_ERROR;
}
std::vector<const char*> args;
std::transform(arg_vec.begin(), arg_vec.end(), std::back_inserter(args),
std::mem_fun_ref(&std::string::c_str));
args.push_back(0);
_childpid = fork();
if (_childpid == -1) {
gnash::log_error("fork() failed: %s", strerror(errno));
return NPERR_OUT_OF_MEMORY_ERROR;
}
if (_childpid > 0) {
ret = close (p2c_pipe[0]);
if (ret == -1) {
gnash::log_error("p2c_pipe[0] close() failed: %s",
strerror(errno));
}
ret = close (c2p_pipe[1]);
if (ret == -1) {
gnash::log_error("c2p_pipe[1] close() failed: %s",
strerror(errno));
gnash::log_debug("Forked successfully but with ignorable errors.");
} else {
gnash::log_debug("Forked successfully, child process PID is %d",
_childpid);
}
setupIOChannel(c2p_pipe[0], (GIOFunc)handlePlayerRequestsWrapper,
(GIOCondition)(G_IO_IN|G_IO_HUP));
setupIOChannel(p2c_controlpipe[1], remove_handler, G_IO_HUP);
return NPERR_NO_ERROR;
}
ret = close (p2c_pipe[1]);
ret = dup2 (p2c_pipe[0], fileno(stdin));
if (ret == -1) {
gnash::log_error("dup2() failed: %s", strerror(errno));
}
int dontclose[] = {c2p_pipe[1], c2p_pipe[0], p2c_controlpipe[0]};
close_fds(dontclose);
gnash::log_debug("Starting process: %s", boost::algorithm::join(arg_vec, " "));
wait_for_gdb();
execv(args[0], const_cast<char**>(&args.front()));
perror("executing standalone gnash");
exit (-1);
}
| @@ -1108,6 +1108,7 @@ nsPluginInstance::setupCookies(const std::string& pageurl)
ss << "/tmp/gnash-cookies." << getpid();
cookiefile.open(ss.str().c_str(), std::ios::out | std::ios::trunc);
+ chmod (ss.str().c_str(), 0600);
// Firefox provides cookies in the following format:
// | CWE-264 | null | null |
10,594 | FT_Create_Class_cff_field_handlers( FT_Library library,
CFF_Field_Handler** output_class )
{
CFF_Field_Handler* clazz = NULL;
FT_Error error;
FT_Memory memory = library->memory;
int i = 0;
#undef CFF_FIELD
#define CFF_FIELD( code, name, id, kind ) i++;
#undef CFF_FIELD_DELTA
#define CFF_FIELD_DELTA( code, name, max, id ) i++;
#undef CFF_FIELD_CALLBACK
#define CFF_FIELD_CALLBACK( code, name, id ) i++;
#include "cfftoken.h"
i++; /* { 0, 0, 0, 0, 0, 0, 0 } */
if ( FT_ALLOC( clazz, sizeof ( CFF_Field_Handler ) * i ) )
return error;
i = 0;
#ifndef FT_DEBUG_LEVEL_TRACE
#undef CFF_FIELD_CALLBACK
#define CFF_FIELD_CALLBACK( code_, name_, id_ ) \
clazz[i].kind = cff_kind_callback; \
clazz[i].code = code_ | CFFCODE; \
clazz[i].offset = 0; \
clazz[i].size = 0; \
clazz[i].reader = cff_parse_ ## name_; \
clazz[i].array_max = 0; \
clazz[i].count_offset = 0; \
i++;
#undef CFF_FIELD
#define CFF_FIELD( code_, name_, id_, kind_ ) \
clazz[i].kind = kind_; \
clazz[i].code = code_ | CFFCODE; \
clazz[i].offset = FT_FIELD_OFFSET( name_ ); \
clazz[i].size = FT_FIELD_SIZE( name_ ); \
clazz[i].reader = 0; \
clazz[i].array_max = 0; \
clazz[i].count_offset = 0; \
i++; \
#undef CFF_FIELD_DELTA
#define CFF_FIELD_DELTA( code_, name_, max_, id_ ) \
clazz[i].kind = cff_kind_delta; \
clazz[i].code = code_ | CFFCODE; \
clazz[i].offset = FT_FIELD_OFFSET( name_ ); \
clazz[i].size = FT_FIELD_SIZE_DELTA( name_ ); \
clazz[i].reader = 0; \
clazz[i].array_max = max_; \
clazz[i].count_offset = FT_FIELD_OFFSET( num_ ## name_ ); \
i++;
#include "cfftoken.h"
clazz[i].kind = 0;
clazz[i].code = 0;
clazz[i].offset = 0;
clazz[i].size = 0;
clazz[i].reader = 0;
clazz[i].array_max = 0;
clazz[i].count_offset = 0;
#else /* FT_DEBUG_LEVEL_TRACE */
#undef CFF_FIELD_CALLBACK
#define CFF_FIELD_CALLBACK( code_, name_, id_ ) \
clazz[i].kind = cff_kind_callback; \
clazz[i].code = code_ | CFFCODE; \
clazz[i].offset = 0; \
clazz[i].size = 0; \
clazz[i].reader = cff_parse_ ## name_; \
clazz[i].array_max = 0; \
clazz[i].count_offset = 0; \
clazz[i].id = id_; \
i++;
#undef CFF_FIELD
#define CFF_FIELD( code_, name_, id_, kind_ ) \
clazz[i].kind = kind_; \
clazz[i].code = code_ | CFFCODE; \
clazz[i].offset = FT_FIELD_OFFSET( name_ ); \
clazz[i].size = FT_FIELD_SIZE( name_ ); \
clazz[i].reader = 0; \
clazz[i].array_max = 0; \
clazz[i].count_offset = 0; \
clazz[i].id = id_; \
i++; \
#undef CFF_FIELD_DELTA
#define CFF_FIELD_DELTA( code_, name_, max_, id_ ) \
clazz[i].kind = cff_kind_delta; \
clazz[i].code = code_ | CFFCODE; \
clazz[i].offset = FT_FIELD_OFFSET( name_ ); \
clazz[i].size = FT_FIELD_SIZE_DELTA( name_ ); \
clazz[i].reader = 0; \
clazz[i].array_max = max_; \
clazz[i].count_offset = FT_FIELD_OFFSET( num_ ## name_ ); \
clazz[i].id = id_; \
i++;
#include "cfftoken.h"
clazz[i].kind = 0;
clazz[i].code = 0;
clazz[i].offset = 0;
clazz[i].size = 0;
clazz[i].reader = 0;
clazz[i].array_max = 0;
clazz[i].count_offset = 0;
clazz[i].id = 0;
#endif /* FT_DEBUG_LEVEL_TRACE */
*output_class = clazz;
return FT_Err_Ok;
}
| Overflow | 0 | FT_Create_Class_cff_field_handlers( FT_Library library,
CFF_Field_Handler** output_class )
{
CFF_Field_Handler* clazz = NULL;
FT_Error error;
FT_Memory memory = library->memory;
int i = 0;
#undef CFF_FIELD
#define CFF_FIELD( code, name, id, kind ) i++;
#undef CFF_FIELD_DELTA
#define CFF_FIELD_DELTA( code, name, max, id ) i++;
#undef CFF_FIELD_CALLBACK
#define CFF_FIELD_CALLBACK( code, name, id ) i++;
#include "cfftoken.h"
i++; /* { 0, 0, 0, 0, 0, 0, 0 } */
if ( FT_ALLOC( clazz, sizeof ( CFF_Field_Handler ) * i ) )
return error;
i = 0;
#ifndef FT_DEBUG_LEVEL_TRACE
#undef CFF_FIELD_CALLBACK
#define CFF_FIELD_CALLBACK( code_, name_, id_ ) \
clazz[i].kind = cff_kind_callback; \
clazz[i].code = code_ | CFFCODE; \
clazz[i].offset = 0; \
clazz[i].size = 0; \
clazz[i].reader = cff_parse_ ## name_; \
clazz[i].array_max = 0; \
clazz[i].count_offset = 0; \
i++;
#undef CFF_FIELD
#define CFF_FIELD( code_, name_, id_, kind_ ) \
clazz[i].kind = kind_; \
clazz[i].code = code_ | CFFCODE; \
clazz[i].offset = FT_FIELD_OFFSET( name_ ); \
clazz[i].size = FT_FIELD_SIZE( name_ ); \
clazz[i].reader = 0; \
clazz[i].array_max = 0; \
clazz[i].count_offset = 0; \
i++; \
#undef CFF_FIELD_DELTA
#define CFF_FIELD_DELTA( code_, name_, max_, id_ ) \
clazz[i].kind = cff_kind_delta; \
clazz[i].code = code_ | CFFCODE; \
clazz[i].offset = FT_FIELD_OFFSET( name_ ); \
clazz[i].size = FT_FIELD_SIZE_DELTA( name_ ); \
clazz[i].reader = 0; \
clazz[i].array_max = max_; \
clazz[i].count_offset = FT_FIELD_OFFSET( num_ ## name_ ); \
i++;
#include "cfftoken.h"
clazz[i].kind = 0;
clazz[i].code = 0;
clazz[i].offset = 0;
clazz[i].size = 0;
clazz[i].reader = 0;
clazz[i].array_max = 0;
clazz[i].count_offset = 0;
#else /* FT_DEBUG_LEVEL_TRACE */
#undef CFF_FIELD_CALLBACK
#define CFF_FIELD_CALLBACK( code_, name_, id_ ) \
clazz[i].kind = cff_kind_callback; \
clazz[i].code = code_ | CFFCODE; \
clazz[i].offset = 0; \
clazz[i].size = 0; \
clazz[i].reader = cff_parse_ ## name_; \
clazz[i].array_max = 0; \
clazz[i].count_offset = 0; \
clazz[i].id = id_; \
i++;
#undef CFF_FIELD
#define CFF_FIELD( code_, name_, id_, kind_ ) \
clazz[i].kind = kind_; \
clazz[i].code = code_ | CFFCODE; \
clazz[i].offset = FT_FIELD_OFFSET( name_ ); \
clazz[i].size = FT_FIELD_SIZE( name_ ); \
clazz[i].reader = 0; \
clazz[i].array_max = 0; \
clazz[i].count_offset = 0; \
clazz[i].id = id_; \
i++; \
#undef CFF_FIELD_DELTA
#define CFF_FIELD_DELTA( code_, name_, max_, id_ ) \
clazz[i].kind = cff_kind_delta; \
clazz[i].code = code_ | CFFCODE; \
clazz[i].offset = FT_FIELD_OFFSET( name_ ); \
clazz[i].size = FT_FIELD_SIZE_DELTA( name_ ); \
clazz[i].reader = 0; \
clazz[i].array_max = max_; \
clazz[i].count_offset = FT_FIELD_OFFSET( num_ ## name_ ); \
clazz[i].id = id_; \
i++;
#include "cfftoken.h"
clazz[i].kind = 0;
clazz[i].code = 0;
clazz[i].offset = 0;
clazz[i].size = 0;
clazz[i].reader = 0;
clazz[i].array_max = 0;
clazz[i].count_offset = 0;
clazz[i].id = 0;
#endif /* FT_DEBUG_LEVEL_TRACE */
*output_class = clazz;
return FT_Err_Ok;
}
| @@ -1422,13 +1422,17 @@
/* and look for it in our current list. */
FT_UInt code;
- FT_UInt num_args = (FT_UInt)
- ( parser->top - parser->stack );
+ FT_UInt num_args;
const CFF_Field_Handler* field;
+ if ( (FT_UInt)( parser->top - parser->stack ) >= parser->stackSize )
+ goto Stack_Overflow;
+
+ num_args = (FT_UInt)( parser->top - parser->stack );
*parser->top = p;
- code = v;
+ code = v;
+
if ( v == 12 )
{
/* two byte operator */ | CWE-787 | null | null |
10,595 | FT_Destroy_Class_cff_field_handlers( FT_Library library,
CFF_Field_Handler* clazz )
{
FT_Memory memory = library->memory;
if ( clazz )
FT_FREE( clazz );
}
| Overflow | 0 | FT_Destroy_Class_cff_field_handlers( FT_Library library,
CFF_Field_Handler* clazz )
{
FT_Memory memory = library->memory;
if ( clazz )
FT_FREE( clazz );
}
| @@ -1422,13 +1422,17 @@
/* and look for it in our current list. */
FT_UInt code;
- FT_UInt num_args = (FT_UInt)
- ( parser->top - parser->stack );
+ FT_UInt num_args;
const CFF_Field_Handler* field;
+ if ( (FT_UInt)( parser->top - parser->stack ) >= parser->stackSize )
+ goto Stack_Overflow;
+
+ num_args = (FT_UInt)( parser->top - parser->stack );
*parser->top = p;
- code = v;
+ code = v;
+
if ( v == 12 )
{
/* two byte operator */ | CWE-787 | null | null |
10,596 | cff_parse_cid_ros( CFF_Parser parser )
{
CFF_FontRecDict dict = (CFF_FontRecDict)parser->object;
FT_Byte** data = parser->stack;
FT_Error error;
error = FT_ERR( Stack_Underflow );
if ( parser->top >= parser->stack + 3 )
{
dict->cid_registry = (FT_UInt)cff_parse_num( parser, data++ );
dict->cid_ordering = (FT_UInt)cff_parse_num( parser, data++ );
if ( **data == 30 )
FT_TRACE1(( "cff_parse_cid_ros: real supplement is rounded\n" ));
dict->cid_supplement = cff_parse_num( parser, data );
if ( dict->cid_supplement < 0 )
FT_TRACE1(( "cff_parse_cid_ros: negative supplement %d is found\n",
dict->cid_supplement ));
error = FT_Err_Ok;
FT_TRACE4(( " %d %d %d\n",
dict->cid_registry,
dict->cid_ordering,
dict->cid_supplement ));
}
return error;
}
| Overflow | 0 | cff_parse_cid_ros( CFF_Parser parser )
{
CFF_FontRecDict dict = (CFF_FontRecDict)parser->object;
FT_Byte** data = parser->stack;
FT_Error error;
error = FT_ERR( Stack_Underflow );
if ( parser->top >= parser->stack + 3 )
{
dict->cid_registry = (FT_UInt)cff_parse_num( parser, data++ );
dict->cid_ordering = (FT_UInt)cff_parse_num( parser, data++ );
if ( **data == 30 )
FT_TRACE1(( "cff_parse_cid_ros: real supplement is rounded\n" ));
dict->cid_supplement = cff_parse_num( parser, data );
if ( dict->cid_supplement < 0 )
FT_TRACE1(( "cff_parse_cid_ros: negative supplement %d is found\n",
dict->cid_supplement ));
error = FT_Err_Ok;
FT_TRACE4(( " %d %d %d\n",
dict->cid_registry,
dict->cid_ordering,
dict->cid_supplement ));
}
return error;
}
| @@ -1422,13 +1422,17 @@
/* and look for it in our current list. */
FT_UInt code;
- FT_UInt num_args = (FT_UInt)
- ( parser->top - parser->stack );
+ FT_UInt num_args;
const CFF_Field_Handler* field;
+ if ( (FT_UInt)( parser->top - parser->stack ) >= parser->stackSize )
+ goto Stack_Overflow;
+
+ num_args = (FT_UInt)( parser->top - parser->stack );
*parser->top = p;
- code = v;
+ code = v;
+
if ( v == 12 )
{
/* two byte operator */ | CWE-787 | null | null |
10,597 | cff_parse_fixed( CFF_Parser parser,
FT_Byte** d )
{
return do_fixed( parser, d, 0 );
}
| Overflow | 0 | cff_parse_fixed( CFF_Parser parser,
FT_Byte** d )
{
return do_fixed( parser, d, 0 );
}
| @@ -1422,13 +1422,17 @@
/* and look for it in our current list. */
FT_UInt code;
- FT_UInt num_args = (FT_UInt)
- ( parser->top - parser->stack );
+ FT_UInt num_args;
const CFF_Field_Handler* field;
+ if ( (FT_UInt)( parser->top - parser->stack ) >= parser->stackSize )
+ goto Stack_Overflow;
+
+ num_args = (FT_UInt)( parser->top - parser->stack );
*parser->top = p;
- code = v;
+ code = v;
+
if ( v == 12 )
{
/* two byte operator */ | CWE-787 | null | null |
10,598 | cff_parse_fixed_scaled( CFF_Parser parser,
FT_Byte** d,
FT_Long scaling )
{
return do_fixed( parser, d, scaling );
}
| Overflow | 0 | cff_parse_fixed_scaled( CFF_Parser parser,
FT_Byte** d,
FT_Long scaling )
{
return do_fixed( parser, d, scaling );
}
| @@ -1422,13 +1422,17 @@
/* and look for it in our current list. */
FT_UInt code;
- FT_UInt num_args = (FT_UInt)
- ( parser->top - parser->stack );
+ FT_UInt num_args;
const CFF_Field_Handler* field;
+ if ( (FT_UInt)( parser->top - parser->stack ) >= parser->stackSize )
+ goto Stack_Overflow;
+
+ num_args = (FT_UInt)( parser->top - parser->stack );
*parser->top = p;
- code = v;
+ code = v;
+
if ( v == 12 )
{
/* two byte operator */ | CWE-787 | null | null |
10,599 | cff_parse_font_bbox( CFF_Parser parser )
{
CFF_FontRecDict dict = (CFF_FontRecDict)parser->object;
FT_BBox* bbox = &dict->font_bbox;
FT_Byte** data = parser->stack;
FT_Error error;
error = FT_ERR( Stack_Underflow );
if ( parser->top >= parser->stack + 4 )
{
bbox->xMin = FT_RoundFix( cff_parse_fixed( parser, data++ ) );
bbox->yMin = FT_RoundFix( cff_parse_fixed( parser, data++ ) );
bbox->xMax = FT_RoundFix( cff_parse_fixed( parser, data++ ) );
bbox->yMax = FT_RoundFix( cff_parse_fixed( parser, data ) );
error = FT_Err_Ok;
FT_TRACE4(( " [%d %d %d %d]\n",
bbox->xMin / 65536,
bbox->yMin / 65536,
bbox->xMax / 65536,
bbox->yMax / 65536 ));
}
return error;
}
| Overflow | 0 | cff_parse_font_bbox( CFF_Parser parser )
{
CFF_FontRecDict dict = (CFF_FontRecDict)parser->object;
FT_BBox* bbox = &dict->font_bbox;
FT_Byte** data = parser->stack;
FT_Error error;
error = FT_ERR( Stack_Underflow );
if ( parser->top >= parser->stack + 4 )
{
bbox->xMin = FT_RoundFix( cff_parse_fixed( parser, data++ ) );
bbox->yMin = FT_RoundFix( cff_parse_fixed( parser, data++ ) );
bbox->xMax = FT_RoundFix( cff_parse_fixed( parser, data++ ) );
bbox->yMax = FT_RoundFix( cff_parse_fixed( parser, data ) );
error = FT_Err_Ok;
FT_TRACE4(( " [%d %d %d %d]\n",
bbox->xMin / 65536,
bbox->yMin / 65536,
bbox->xMax / 65536,
bbox->yMax / 65536 ));
}
return error;
}
| @@ -1422,13 +1422,17 @@
/* and look for it in our current list. */
FT_UInt code;
- FT_UInt num_args = (FT_UInt)
- ( parser->top - parser->stack );
+ FT_UInt num_args;
const CFF_Field_Handler* field;
+ if ( (FT_UInt)( parser->top - parser->stack ) >= parser->stackSize )
+ goto Stack_Overflow;
+
+ num_args = (FT_UInt)( parser->top - parser->stack );
*parser->top = p;
- code = v;
+ code = v;
+
if ( v == 12 )
{
/* two byte operator */ | CWE-787 | null | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.