diff mbox

[ovs-dev] windows: Incorrect check while fetching adapter addresses

Message ID 20161213185223.4868-1-aserdean@cloudbasesolutions.com
State Accepted
Headers show

Commit Message

Alin Serdean Dec. 13, 2016, 6:52 p.m. UTC
Checking for ERROR_INSUFFICIENT_BUFFER is incorrect per
MSFT documentation:
https://msdn.microsoft.com/en-us/library/windows/desktop/aa365915(v=vs.85).aspx

Also, the initial call to GetAdaptersAddresses was wrong. In the case
of a successful return 'all_addr' was not allocated leading to a crash.

Signed-off-by: Alin Gabriel Serdean <aserdean@cloudbasesolutions.com>
Reported-by: Lior Baram <lior.baram@hpe.com>
---
 lib/netdev-windows.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Sairam Venugopal Dec. 20, 2016, 6:02 a.m. UTC | #1
Acked-by: Sairam Venugopal <vsairam@vmware.com>


On 12/13/16, 10:52 AM, "Alin Serdean" <aserdean@cloudbasesolutions.com>
wrote:

>Checking for ERROR_INSUFFICIENT_BUFFER is incorrect per
>MSFT documentation:
>https://urldefense.proofpoint.com/v2/url?u=https-3A__msdn.microsoft.com_en
>-2Dus_library_windows_desktop_aa365915-28v-3Dvs.85-29.aspx&d=DgICAg&c=uila
>K90D4TOVoH58JNXRgQ&r=Z6vowHUOjP5ysP_g372c49Nqc1vEKqHKNBkR5Q5Z7uo&m=saWOLiw
>2hhYRR-nDW2OSb-CDDqaeeOHF6HqdETLEQp4&s=w-oSMEuJM9I1cw5cvsjHBLFkuttr6pX_7eV
>dLs-wM_8&e= 
>
>Also, the initial call to GetAdaptersAddresses was wrong. In the case
>of a successful return 'all_addr' was not allocated leading to a crash.
>
>Signed-off-by: Alin Gabriel Serdean <aserdean@cloudbasesolutions.com>
>Reported-by: Lior Baram <lior.baram@hpe.com>
>---
> lib/netdev-windows.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
>diff --git a/lib/netdev-windows.c b/lib/netdev-windows.c
>index f5e809e..c2fbe42 100644
>--- a/lib/netdev-windows.c
>+++ b/lib/netdev-windows.c
>@@ -425,16 +425,16 @@ netdev_windows_get_next_hop(const struct in_addr
>*host,
> {
>     uint32_t ret_val = 0;
>     /* The buffer length of all addresses */
>-    uint32_t buffer_length = 1000;
>+    uint32_t buffer_length = 0;
>     PIP_ADAPTER_ADDRESSES all_addr = NULL;
>     PIP_ADAPTER_ADDRESSES cur_addr = NULL;
> 
>     ret_val = GetAdaptersAddresses(AF_INET,
>                                    GAA_FLAG_INCLUDE_PREFIX |
>                                    GAA_FLAG_INCLUDE_GATEWAYS,
>-                                   NULL, all_addr, &buffer_length);
>+                                   NULL, NULL, &buffer_length);
> 
>-    if (ret_val != ERROR_INSUFFICIENT_BUFFER ) {
>+    if (ret_val != ERROR_BUFFER_OVERFLOW ) {
>         VLOG_ERR("Call to GetAdaptersAddresses failed with error: %s",
>                  ovs_format_message(ret_val));
>         return ENXIO;
>-- 
>2.10.2.windows.1
>_______________________________________________
>dev mailing list
>dev@openvswitch.org
>https://urldefense.proofpoint.com/v2/url?u=https-3A__mail.openvswitch.org_
>mailman_listinfo_ovs-2Ddev&d=DgICAg&c=uilaK90D4TOVoH58JNXRgQ&r=Z6vowHUOjP5
>ysP_g372c49Nqc1vEKqHKNBkR5Q5Z7uo&m=saWOLiw2hhYRR-nDW2OSb-CDDqaeeOHF6HqdETL
>EQp4&s=KKVliSW_g6NKJQXyZNk7hcNOoSAT5xwld5a77-RmzsI&e=
diff mbox

Patch

diff --git a/lib/netdev-windows.c b/lib/netdev-windows.c
index f5e809e..c2fbe42 100644
--- a/lib/netdev-windows.c
+++ b/lib/netdev-windows.c
@@ -425,16 +425,16 @@  netdev_windows_get_next_hop(const struct in_addr *host,
 {
     uint32_t ret_val = 0;
     /* The buffer length of all addresses */
-    uint32_t buffer_length = 1000;
+    uint32_t buffer_length = 0;
     PIP_ADAPTER_ADDRESSES all_addr = NULL;
     PIP_ADAPTER_ADDRESSES cur_addr = NULL;
 
     ret_val = GetAdaptersAddresses(AF_INET,
                                    GAA_FLAG_INCLUDE_PREFIX |
                                    GAA_FLAG_INCLUDE_GATEWAYS,
-                                   NULL, all_addr, &buffer_length);
+                                   NULL, NULL, &buffer_length);
 
-    if (ret_val != ERROR_INSUFFICIENT_BUFFER ) {
+    if (ret_val != ERROR_BUFFER_OVERFLOW ) {
         VLOG_ERR("Call to GetAdaptersAddresses failed with error: %s",
                  ovs_format_message(ret_val));
         return ENXIO;