comparison lib/rfc959.c @ 572:ce1e83470207

2004-9-29 Brian Masney <masneyb@gftp.org> * lib/rfc959.c lib/protocols.c lib/gftp.h - when making an IPv6 FTP connection, make sure the proper addrinfo structure is used. Added more error checks to the EPSV parsing
author masneyb
date Wed, 29 Sep 2004 22:43:59 +0000
parents 447f40a61ee8
children fa0838b22b14
comparison
equal deleted inserted replaced
571:de0128b73daa 572:ce1e83470207
806 return (GFTP_ERETRYABLE); 806 return (GFTP_ERETRYABLE);
807 } 807 }
808 808
809 data_addr_len = sizeof (data_addr); 809 data_addr_len = sizeof (data_addr);
810 /* This condition shouldn't happen. We better check anyway... */ 810 /* This condition shouldn't happen. We better check anyway... */
811 if (data_addr_len != request->hostp->ai_addrlen) 811 if (data_addr_len != request->current_hostp->ai_addrlen)
812 { 812 {
813 request->logging_function (gftp_logging_error, request, 813 request->logging_function (gftp_logging_error, request,
814 _("Error: It doesn't look like we are connected via IPv6. Aborting connection.\n")); 814 _("Error: It doesn't look like we are connected via IPv6. Aborting connection.\n"));
815 gftp_disconnect (request); 815 gftp_disconnect (request);
816 return (GFTP_EFATAL); 816 return (GFTP_EFATAL);
833 } 833 }
834 834
835 pos = request->last_ftp_response + 4; 835 pos = request->last_ftp_response + 4;
836 while (*pos != '(' && *pos != '\0') 836 while (*pos != '(' && *pos != '\0')
837 pos++; 837 pos++;
838 pos++; 838
839 839 if (*pos == '\0' || *(pos + 1) == '\0')
840 if (*pos == '\0')
841 { 840 {
842 request->logging_function (gftp_logging_error, request, 841 request->logging_function (gftp_logging_error, request,
843 _("Invalid EPSV response '%s'\n"), 842 _("Invalid EPSV response '%s'\n"),
844 request->last_ftp_response); 843 request->last_ftp_response);
845 gftp_disconnect (request); 844 gftp_disconnect (request);
846 return (GFTP_EFATAL); 845 return (GFTP_EFATAL);
847 } 846 }
848 847
849 if (sscanf (pos, "|||%u|", &port) != 1) 848 if (sscanf (pos + 1, "|||%u|", &port) != 1)
850 { 849 {
851 request->logging_function (gftp_logging_error, request, 850 request->logging_function (gftp_logging_error, request,
852 _("Invalid EPSV response '%s'\n"), 851 _("Invalid EPSV response '%s'\n"),
853 request->last_ftp_response); 852 request->last_ftp_response);
854 gftp_disconnect (request); 853 gftp_disconnect (request);
855 return (GFTP_EFATAL); 854 return (GFTP_EFATAL);
856 } 855 }
857 856
858 memcpy (&data_addr, request->hostp->ai_addr, data_addr_len); 857 memcpy (&data_addr, request->current_hostp->ai_addr, data_addr_len);
859 data_addr.sin6_port = htons (port); 858 data_addr.sin6_port = htons (port);
860 859
861 if (connect (parms->data_connection, (struct sockaddr *) &data_addr, 860 if (connect (parms->data_connection, (struct sockaddr *) &data_addr,
862 data_addr_len) == -1) 861 data_addr_len) == -1)
863 { 862 {
868 return (GFTP_ERETRYABLE); 867 return (GFTP_ERETRYABLE);
869 } 868 }
870 } 869 }
871 else 870 else
872 { 871 {
873 memcpy (&data_addr, request->hostp->ai_addr, data_addr_len); 872 memcpy (&data_addr, request->current_hostp->ai_addr, data_addr_len);
874 data_addr.sin6_port = 0; 873 data_addr.sin6_port = 0;
875 874
876 if (bind (parms->data_connection, (struct sockaddr *) &data_addr, 875 if (bind (parms->data_connection, (struct sockaddr *) &data_addr,
877 data_addr_len) == -1) 876 data_addr_len) == -1)
878 { 877 {