mirror of
https://gitlab.isc.org/isc-projects/dhcp
synced 2025-08-22 18:07:25 +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:
parent
bc7f8b8e39
commit
d289ee683e
5
RELNOTES
5
RELNOTES
@ -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
|
||||||
|
@ -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
|
||||||
@ -327,66 +328,66 @@ int execute_statements (result, packet, lease, client_state,
|
|||||||
case set_statement:
|
case set_statement:
|
||||||
case define_statement:
|
case define_statement:
|
||||||
if (!scope) {
|
if (!scope) {
|
||||||
log_error ("set %s: no scope",
|
log_error("set %s: no scope",
|
||||||
r -> data.set.name);
|
r->data.set.name);
|
||||||
status = 0;
|
status = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (!*scope) {
|
if (!*scope) {
|
||||||
if (!binding_scope_allocate (scope, MDL)) {
|
if (!binding_scope_allocate(scope, MDL)) {
|
||||||
log_error ("set %s: can't allocate scope",
|
log_error("set %s: can't allocate scope",
|
||||||
r -> data.set.name);
|
r->data.set.name);
|
||||||
status = 0;
|
status = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
binding = find_binding (*scope, r -> data.set.name);
|
binding = find_binding(*scope, r->data.set.name);
|
||||||
#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) {
|
||||||
status = (evaluate_expression
|
status = (evaluate_expression
|
||||||
(&binding -> value, packet,
|
(&binding->value, packet,
|
||||||
lease, client_state,
|
lease, client_state,
|
||||||
in_options, out_options,
|
in_options, out_options,
|
||||||
scope, r -> data.set.expr,
|
scope, r->data.set.expr,
|
||||||
MDL));
|
MDL));
|
||||||
} else {
|
} else {
|
||||||
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 -> type =
|
(binding->value != NULL)) {
|
||||||
binding_function;
|
binding->value->type =
|
||||||
(fundef_reference
|
binding_function;
|
||||||
(&binding -> value -> value.fundef,
|
(fundef_reference
|
||||||
r -> data.set.expr -> data.func,
|
(&binding->value->value.fundef,
|
||||||
MDL));
|
r->data.set.expr->data.func,
|
||||||
|
MDL));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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)) &&
|
||||||
@ -362,15 +363,16 @@ 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),
|
||||||
print_hw_addr (packet -> raw -> htype,
|
((hp != NULL) && (hp->name != NULL)) ? hp -> name : "unknown",
|
||||||
packet -> raw -> hlen,
|
print_hw_addr (packet->raw->htype,
|
||||||
packet -> raw -> chaddr),
|
packet->raw->hlen,
|
||||||
packet -> raw -> giaddr.s_addr
|
packet->raw->chaddr),
|
||||||
? inet_ntoa (packet -> raw -> giaddr)
|
packet->raw->giaddr.s_addr
|
||||||
: packet -> interface -> name);
|
? inet_ntoa (packet->raw->giaddr)
|
||||||
|
: packet->interface->name);
|
||||||
|
|
||||||
/* Set up the parts of the address that are in common. */
|
/* Set up the parts of the address that are in common. */
|
||||||
to.sin_family = AF_INET;
|
to.sin_family = AF_INET;
|
||||||
|
@ -2731,77 +2731,76 @@ 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)
|
||||||
log_fatal ("no memory for group decl name %s", val);
|
log_fatal("no memory for group decl name %s", val);
|
||||||
strcpy (name, val);
|
strcpy(name, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!parse_lbrace (cfile)) {
|
if (!parse_lbrace(cfile)) {
|
||||||
group_dereference (&g, MDL);
|
group_dereference(&g, MDL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
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)) {
|
||||||
delete_group (t, 0);
|
delete_group(t, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} 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",
|
||||||
val, isc_result_totext (status));
|
val, isc_result_totext(status));
|
||||||
group_reference (&t -> group, g, MDL);
|
group_reference(&t->group, g, MDL);
|
||||||
t -> name = name;
|
t->name = name;
|
||||||
t -> flags = ((staticp ? GROUP_OBJECT_STATIC : 0) |
|
t->flags = ((staticp ? GROUP_OBJECT_STATIC : 0) |
|
||||||
(dynamicp ? GROUP_OBJECT_DYNAMIC : 0) |
|
(dynamicp ? GROUP_OBJECT_DYNAMIC : 0) |
|
||||||
(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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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,10 +455,7 @@ 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 = htonl(time_renewal - cur_time);
|
||||||
time_renewal = 0;
|
|
||||||
else
|
|
||||||
time_renewal = htonl(time_renewal - cur_time);
|
|
||||||
|
|
||||||
if (!add_option(options,
|
if (!add_option(options,
|
||||||
DHO_DHCP_RENEWAL_TIME,
|
DHO_DHCP_RENEWAL_TIME,
|
||||||
@ -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,
|
||||||
|
@ -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) &&
|
||||||
type = value -> u.integer;
|
(value->type == omapi_datatype_int))
|
||||||
|
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")) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user