2
0
mirror of https://gitlab.isc.org/isc-projects/dhcp synced 2025-08-28 12:57:42 +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 #23138] [ISC-Bugs #27945] [ISC-Bugs #25586]
[ISC-Bugs #27684] [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 Changes since 4.2.2
- Fix the code that checks for an existing DDNS transaction to cancel - Fix the code that checks for an existing DDNS transaction to cancel

View File

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

View File

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

View File

@ -2731,13 +2731,13 @@ void parse_group_declaration (cfile, group)
int dynamicp = 0; int dynamicp = 0;
int staticp = 0; int staticp = 0;
g = (struct group *)0; g = NULL;
if (!clone_group(&g, group, MDL)) if (!clone_group(&g, group, MDL))
log_fatal("no memory for explicit group."); 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) { if (is_identifier (token) || token == STRING) {
next_token (&val, (unsigned *)0, cfile); next_token(&val, NULL, cfile);
name = dmalloc(strlen(val) + 1, MDL); name = dmalloc(strlen(val) + 1, MDL);
if (!name) if (!name)
@ -2751,36 +2751,35 @@ void parse_group_declaration (cfile, group)
} }
do { do {
token = peek_token (&val, (unsigned *)0, cfile); token = peek_token(&val, NULL, cfile);
if (token == RBRACE) { if (token == RBRACE) {
token = next_token (&val, (unsigned *)0, cfile); token = next_token(&val, NULL, cfile);
break; break;
} else if (token == END_OF_FILE) { } 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"); parse_warn(cfile, "unexpected end of file");
break; break;
} else if (token == TOKEN_DELETED) { } else if (token == TOKEN_DELETED) {
token = next_token (&val, (unsigned *)0, cfile); token = next_token(&val, NULL, cfile);
parse_semi(cfile); parse_semi(cfile);
deletedp = 1; deletedp = 1;
} else if (token == DYNAMIC) { } else if (token == DYNAMIC) {
token = next_token (&val, (unsigned *)0, cfile); token = next_token(&val, NULL, cfile);
parse_semi(cfile); parse_semi(cfile);
dynamicp = 1; dynamicp = 1;
} else if (token == STATIC) { } else if (token == STATIC) {
token = next_token (&val, (unsigned *)0, cfile); token = next_token(&val, NULL, cfile);
parse_semi(cfile); parse_semi(cfile);
staticp = 1; staticp = 1;
} }
declaration = parse_statement(cfile, g, GROUP_DECL, declaration = parse_statement(cfile, g, GROUP_DECL,
(struct host_decl *)0, NULL, declaration);
declaration);
} while (1); } while (1);
if (name) { if (name) {
if (deletedp) { if (deletedp) {
if (group_name_hash) { if (group_name_hash) {
t = (struct group_object *)0; t = NULL;
if (group_hash_lookup(&t, group_name_hash, if (group_hash_lookup(&t, group_name_hash,
name, name,
strlen(name), MDL)) { strlen(name), MDL)) {
@ -2788,7 +2787,7 @@ void parse_group_declaration (cfile, group)
} }
} }
} else { } else {
t = (struct group_object *)0; t = NULL;
status = group_object_allocate(&t, MDL); status = group_object_allocate(&t, MDL);
if (status != ISC_R_SUCCESS) if (status != ISC_R_SUCCESS)
log_fatal("no memory for group decl %s: %s", log_fatal("no memory for group decl %s: %s",
@ -2800,7 +2799,7 @@ void parse_group_declaration (cfile, group)
(deletedp ? GROUP_OBJECT_DELETED : 0)); (deletedp ? GROUP_OBJECT_DELETED : 0));
supersede_group(t, 0); supersede_group(t, 0);
} }
if (t) if (t != NULL)
group_object_dereference(&t, MDL); 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") * Copyright (C) 2006-2007,2009 by Internet Systems Consortium, Inc. ("ISC")
* *
* Permission to use, copy, modify, and distribute this software for any * 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); (lease_duration / 8);
if (time_renewal > cur_time) { if (time_renewal > cur_time) {
if (time_renewal < cur_time)
time_renewal = 0;
else
time_renewal = htonl(time_renewal - cur_time); time_renewal = htonl(time_renewal - cur_time);
if (!add_option(options, if (!add_option(options,
@ -487,15 +485,8 @@ dhcpleasequery(struct packet *packet, int ms_nulltp) {
} }
if (lease->ends > cur_time) { 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); time_expiry = htonl(lease->ends - cur_time);
if (!add_option(options, if (!add_option(options,
DHO_DHCP_LEASE_TIME, DHO_DHCP_LEASE_TIME,
&time_expiry, &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")) { if (!omapi_ds_strcmp (name, "hardware-type")) {
int type; int type;
if (value && (value -> type == omapi_datatype_data && if ((value != NULL) &&
value -> u.buffer.len == sizeof type)) { ((value->type == omapi_datatype_data) &&
if (value -> u.buffer.len > sizeof type) (value->u.buffer.len == sizeof(type)))) {
return DHCP_R_INVALIDARG; if (value->u.buffer.len > sizeof(type))
memcpy (&type, return (DHCP_R_INVALIDARG);
value -> u.buffer.value, memcpy(&type, value->u.buffer.value,
value->u.buffer.len); value->u.buffer.len);
type = ntohl(type); type = ntohl(type);
} else if (value -> type == omapi_datatype_int) } else if ((value != NULL) &&
(value->type == omapi_datatype_int))
type = value->u.integer; type = value->u.integer;
else else
return DHCP_R_INVALIDARG; return (DHCP_R_INVALIDARG);
host->interface.hbuf[0] = type; host->interface.hbuf[0] = type;
return ISC_R_SUCCESS; return (ISC_R_SUCCESS);
} }
if (!omapi_ds_strcmp (name, "dhcp-client-identifier")) { if (!omapi_ds_strcmp (name, "dhcp-client-identifier")) {