diff options
author | Jessica Wagantall <jwagantall@cyngn.com> | 2016-04-04 16:08:30 -0700 |
---|---|---|
committer | Jessica Wagantall <jwagantall@cyngn.com> | 2016-04-04 16:08:30 -0700 |
commit | 38a40fc34e83416e9fd5351f13bc723105ac4e7b (patch) | |
tree | 884e8e395afb4fa32b970fde1e99b59e0f8c57e7 | |
parent | 60ea6f57e1e380b0451da94138b94c336acd1896 (diff) | |
parent | 1390ace71179f04a09c300ee8d0300aa69d9db09 (diff) | |
download | android_external_dhcpcd-cm-12.1.tar.gz android_external_dhcpcd-cm-12.1.tar.bz2 android_external_dhcpcd-cm-12.1.zip |
Merge tag 'android-5.1.1_r37' into HEADcm-12.1
Ticket: CYNGNOS-2213
Android 5.1.1 release 37
-rw-r--r-- | dhcp.c | 29 |
1 files changed, 21 insertions, 8 deletions
@@ -271,21 +271,34 @@ valid_length(uint8_t option, int dl, int *type) if (type) *type = opt->type; - + /* The size of RFC3442 and RFC5969 options is checked at a later + * stage in the code */ if (opt->type == 0 || opt->type & (STRING | RFC3442 | RFC5969)) return 0; - + /* The code does not use SINT16 / SINT32 together with ARRAY. + * It is however far easier to reason about the code if all + * possible array elements are included, and also does not code + * any additional CPU resources. sizeof(uintXX_t) == + * sizeof(intXX_t) can be assumed. */ sz = 0; - if (opt->type & (UINT32 | IPV4)) + if (opt->type & (UINT32 | SINT32 | IPV4)) sz = sizeof(uint32_t); - if (opt->type & UINT16) + else if (opt->type & (UINT16 | SINT16)) sz = sizeof(uint16_t); - if (opt->type & UINT8) + else if (opt->type & UINT8) sz = sizeof(uint8_t); - if (opt->type & (IPV4 | ARRAY)) - return dl % sz; - return (dl == sz ? 0 : -1); + if (opt->type & ARRAY) { + /* The result of modulo zero is undefined. There are no + * options defined in this file that do not match one of + * the if-clauses above, so the following is not really + * necessary. However, to avoid confusion and unexpected + * behavior if the defined options are ever extended, + * returning false here seems sensible. */ + if (!sz) return -1; + return (dl % sz == 0) ? 0 : -1; + } + return (sz == dl) ? 0 : -1; } /* unknown option, so let it pass */ |