bss_dgram.c: re-fix BIO_CTRL_DGRAM_GET_PEER (from HEAD).
authorAndy Polyakov <appro@openssl.org>
Thu, 26 Nov 2009 20:56:05 +0000 (20:56 +0000)
committerAndy Polyakov <appro@openssl.org>
Thu, 26 Nov 2009 20:56:05 +0000 (20:56 +0000)
crypto/bio/bss_dgram.c

index f63f1bf..fa886af 100644 (file)
@@ -565,21 +565,23 @@ static long dgram_ctrl(BIO *b, int cmd, long num, void *ptr)
                        }
                break;
        case BIO_CTRL_DGRAM_GET_PEER:
-               to = (struct sockaddr *) ptr;
-               switch (to->sa_family)
+               switch (data->peer.sa.sa_family)
                        {
                        case AF_INET:
-                               memcpy(to,&data->peer,(ret=sizeof(data->peer.sa_in)));
+                               ret=sizeof(data->peer.sa_in);
                                break;
 #if OPENSSL_USE_IPV6
                        case AF_INET6:
-                               memcpy(to,&data->peer,(ret=sizeof(data->peer.sa_in6)));
+                               ret=sizeof(data->peer.sa_in6);
                                break;
 #endif
                        default:
-                               memcpy(to,&data->peer,(ret=sizeof(data->peer.sa)));
+                               ret=sizeof(data->peer.sa);
                                break;
                        }
+               if (num==0 || num>ret)
+                       num=ret;
+               memcpy(ptr,&data->peer,(ret=num));
                break;
        case BIO_CTRL_DGRAM_SET_PEER:
                to = (struct sockaddr *) ptr;