2
0
mirror of https://gitlab.isc.org/isc-projects/dhcp synced 2025-08-28 21:07:43 +00:00

Remove unnecessary checks in the lease query code and clean up

several compiler issues (some dereferences of NULL and treating
an int as a boolean).
[ISC-Bugs #26203]
This commit is contained in:
Shawn Routhier 2012-04-10 21:26:44 +00:00
parent bc7f8b8e39
commit d289ee683e
6 changed files with 117 additions and 118 deletions

View File

@ -124,6 +124,11 @@ work on other platforms. Please report any problems and suggested fixes to
[ISC-Bugs #23138] [ISC-Bugs #27945] [ISC-Bugs #25586]
[ISC-Bugs #27684]
- Remove unnecessary checks in the lease query code and clean up
several compiler issues (some dereferences of NULL and treating
an int as a boolean).
[ISC-Bugs #26203]
Changes since 4.2.2
- Fix the code that checks for an existing DDNS transaction to cancel

View File

@ -3,7 +3,8 @@
Support for executable statements. */
/*
* Copyright (c) 2004-2007,2009 by Internet Systems Consortium, Inc. ("ISC")
* Copyright (c) 2009,2012 by Internet Systems Consortium, Inc. ("ISC")
* Copyright (c) 2004-2007 by Internet Systems Consortium, Inc. ("ISC")
* Copyright (c) 1998-2003 by Internet Software Consortium
*
* Permission to use, copy, modify, and distribute this software for any
@ -344,27 +345,26 @@ int execute_statements (result, packet, lease, client_state,
#if defined (DEBUG_EXPRESSIONS)
log_debug("exec: set %s", r->data.set.name);
#endif
if (!binding) {
binding = dmalloc (sizeof *binding, MDL);
if (binding) {
memset (binding, 0, sizeof *binding);
if (binding == NULL) {
binding = dmalloc(sizeof(*binding), MDL);
if (binding != NULL) {
memset(binding, 0, sizeof(*binding));
binding->name =
dmalloc(strlen
(r->data.set.name) + 1,
MDL);
if (binding -> name) {
strcpy (binding -> name,
r -> data.set.name);
if (binding->name != NULL) {
strcpy(binding->name, r->data.set.name);
binding->next = (*scope)->bindings;
(*scope)->bindings = binding;
} else {
dfree(binding, MDL);
binding = (struct binding *)0;
binding = NULL;
}
}
}
if (binding) {
if (binding -> value)
if (binding != NULL) {
if (binding->value != NULL)
binding_value_dereference
(&binding->value, MDL);
if (r->op == set_statement) {
@ -378,9 +378,10 @@ int execute_statements (result, packet, lease, client_state,
if (!(binding_value_allocate
(&binding->value, MDL))) {
dfree(binding, MDL);
binding = (struct binding *)0;
binding = NULL;
}
if (binding -> value) {
if ((binding != NULL) &&
(binding->value != NULL)) {
binding->value->type =
binding_function;
(fundef_reference

View File

@ -177,11 +177,12 @@ void bootp (packet)
}
/* Execute the host statements. */
execute_statements_in_scope ((struct binding_value **)0,
packet, lease, (struct client_state *)0,
if (hp != NULL) {
execute_statements_in_scope (NULL, packet, lease, NULL,
packet->options, options,
&lease->scope,
hp->group, lease->subnet->group);
}
/* Drop the request if it's not allowed for this client. */
if ((oc = lookup_option (&server_universe, options, SV_ALLOW_BOOTP)) &&
@ -364,7 +365,8 @@ void bootp (packet)
/* Report what we're doing... */
log_info("%s", msgbuf);
log_info("BOOTREPLY for %s to %s (%s) via %s",
piaddr (lease->ip_addr), hp -> name,
piaddr(lease->ip_addr),
((hp != NULL) && (hp->name != NULL)) ? hp -> name : "unknown",
print_hw_addr (packet->raw->htype,
packet->raw->hlen,
packet->raw->chaddr),

View File

@ -2731,13 +2731,13 @@ void parse_group_declaration (cfile, group)
int dynamicp = 0;
int staticp = 0;
g = (struct group *)0;
g = NULL;
if (!clone_group(&g, group, MDL))
log_fatal("no memory for explicit group.");
token = peek_token (&val, (unsigned *)0, cfile);
token = peek_token(&val, NULL, cfile);
if (is_identifier (token) || token == STRING) {
next_token (&val, (unsigned *)0, cfile);
next_token(&val, NULL, cfile);
name = dmalloc(strlen(val) + 1, MDL);
if (!name)
@ -2751,36 +2751,35 @@ void parse_group_declaration (cfile, group)
}
do {
token = peek_token (&val, (unsigned *)0, cfile);
token = peek_token(&val, NULL, cfile);
if (token == RBRACE) {
token = next_token (&val, (unsigned *)0, cfile);
token = next_token(&val, NULL, cfile);
break;
} else if (token == END_OF_FILE) {
token = next_token (&val, (unsigned *)0, cfile);
token = next_token(&val, NULL, cfile);
parse_warn(cfile, "unexpected end of file");
break;
} else if (token == TOKEN_DELETED) {
token = next_token (&val, (unsigned *)0, cfile);
token = next_token(&val, NULL, cfile);
parse_semi(cfile);
deletedp = 1;
} else if (token == DYNAMIC) {
token = next_token (&val, (unsigned *)0, cfile);
token = next_token(&val, NULL, cfile);
parse_semi(cfile);
dynamicp = 1;
} else if (token == STATIC) {
token = next_token (&val, (unsigned *)0, cfile);
token = next_token(&val, NULL, cfile);
parse_semi(cfile);
staticp = 1;
}
declaration = parse_statement(cfile, g, GROUP_DECL,
(struct host_decl *)0,
declaration);
NULL, declaration);
} while (1);
if (name) {
if (deletedp) {
if (group_name_hash) {
t = (struct group_object *)0;
t = NULL;
if (group_hash_lookup(&t, group_name_hash,
name,
strlen(name), MDL)) {
@ -2788,7 +2787,7 @@ void parse_group_declaration (cfile, group)
}
}
} else {
t = (struct group_object *)0;
t = NULL;
status = group_object_allocate(&t, MDL);
if (status != ISC_R_SUCCESS)
log_fatal("no memory for group decl %s: %s",
@ -2800,7 +2799,7 @@ void parse_group_declaration (cfile, group)
(deletedp ? GROUP_OBJECT_DELETED : 0));
supersede_group(t, 0);
}
if (t)
if (t != NULL)
group_object_dereference(&t, MDL);
}
}

View File

@ -1,4 +1,5 @@
/*
* Copyright (C) 2011-2012 by Internet Systems Consortium, Inc. ("ISC")
* Copyright (C) 2006-2007,2009 by Internet Systems Consortium, Inc. ("ISC")
*
* Permission to use, copy, modify, and distribute this software for any
@ -454,9 +455,6 @@ dhcpleasequery(struct packet *packet, int ms_nulltp) {
(lease_duration / 8);
if (time_renewal > cur_time) {
if (time_renewal < cur_time)
time_renewal = 0;
else
time_renewal = htonl(time_renewal - cur_time);
if (!add_option(options,
@ -487,15 +485,8 @@ dhcpleasequery(struct packet *packet, int ms_nulltp) {
}
if (lease->ends > cur_time) {
if (time_expiry < cur_time) {
log_error("Impossible condition at %s:%d.",
MDL);
option_state_dereference(&options, MDL);
lease_dereference(&lease, MDL);
return;
}
time_expiry = htonl(lease->ends - cur_time);
if (!add_option(options,
DHO_DHCP_LEASE_TIME,
&time_expiry,

View File

@ -984,20 +984,21 @@ isc_result_t dhcp_host_set_value (omapi_object_t *h,
if (!omapi_ds_strcmp (name, "hardware-type")) {
int type;
if (value && (value -> type == omapi_datatype_data &&
value -> u.buffer.len == sizeof type)) {
if (value -> u.buffer.len > sizeof type)
return DHCP_R_INVALIDARG;
memcpy (&type,
value -> u.buffer.value,
if ((value != NULL) &&
((value->type == omapi_datatype_data) &&
(value->u.buffer.len == sizeof(type)))) {
if (value->u.buffer.len > sizeof(type))
return (DHCP_R_INVALIDARG);
memcpy(&type, value->u.buffer.value,
value->u.buffer.len);
type = ntohl(type);
} else if (value -> type == omapi_datatype_int)
} else if ((value != NULL) &&
(value->type == omapi_datatype_int))
type = value->u.integer;
else
return DHCP_R_INVALIDARG;
return (DHCP_R_INVALIDARG);
host->interface.hbuf[0] = type;
return ISC_R_SUCCESS;
return (ISC_R_SUCCESS);
}
if (!omapi_ds_strcmp (name, "dhcp-client-identifier")) {