diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2013-12-31 11:57:38 -0500 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2013-12-31 13:00:57 -0500 |
commit | 7a7c74cae4db0c35cbe54d9bad8418a605cb870f (patch) | |
tree | 019942adb3e3186d9fcaff32c895048449ed5afc /src/libsystemd-dhcp/dhcp-client.c | |
parent | aa9ed6538985d667aa6a0264c59622a51384ccd6 (diff) |
dhcp: fix creation of req_opts array
GREEDY_REALLOC needs to have two size variables: one for the
allocated size, and a second one for the used size. Using
the allocated size only lead to leaving some elements unitialized
and assigning some more than once.
Diffstat (limited to 'src/libsystemd-dhcp/dhcp-client.c')
-rw-r--r-- | src/libsystemd-dhcp/dhcp-client.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/src/libsystemd-dhcp/dhcp-client.c b/src/libsystemd-dhcp/dhcp-client.c index 9f7a826211..b9492a5a68 100644 --- a/src/libsystemd-dhcp/dhcp-client.c +++ b/src/libsystemd-dhcp/dhcp-client.c @@ -54,6 +54,7 @@ struct sd_dhcp_client { union sockaddr_union link; sd_event_source *receive_message; uint8_t *req_opts; + size_t req_opts_allocated; size_t req_opts_size; be32_t last_addr; struct ether_addr mac_addr; @@ -115,11 +116,11 @@ int sd_dhcp_client_set_request_option(sd_dhcp_client *client, uint8_t option) if (client->req_opts[i] == option) return -EEXIST; - if (!GREEDY_REALLOC(client->req_opts, client->req_opts_size, + if (!GREEDY_REALLOC(client->req_opts, client->req_opts_allocated, client->req_opts_size + 1)) return -ENOMEM; - client->req_opts[client->req_opts_size - 1] = option; + client->req_opts[client->req_opts_size++] = option; return 0; } |