Browse Source

Don't try to fetch another packet once we've reached EOF.

tags/v0.9.3
Michael Brown 19 years ago
parent
commit
698e87277f
1 changed files with 12 additions and 6 deletions
  1. 12
    6
      src/proto/tftp.c

+ 12
- 6
src/proto/tftp.c View File

35
  * False return value always indicates an error that should abort the
35
  * False return value always indicates an error that should abort the
36
  * transfer.
36
  * transfer.
37
  */
37
  */
38
-static inline int process_tftp_data ( struct tftp_state *state,
38
+static inline int tftp_process_data ( struct tftp_state *state,
39
 				      struct tftp_data *data,
39
 				      struct tftp_data *data,
40
 				      struct buffer *buffer,
40
 				      struct buffer *buffer,
41
 				      int *eof ) {
41
 				      int *eof ) {
97
 	state.server = *server;
97
 	state.server = *server;
98
 	
98
 	
99
 	/* Open the file */
99
 	/* Open the file */
100
-	if ( ! tftp_open ( &state, file, &reply ) ) {
100
+	if ( ! tftp_open ( &state, file, &reply, 0 ) ) {
101
 		DBG ( "TFTP: could not open %@:%d/%s : %m\n",
101
 		DBG ( "TFTP: could not open %@:%d/%s : %m\n",
102
 		      server->sin_addr.s_addr, server->sin_port, file );
102
 		      server->sin_addr.s_addr, server->sin_port, file );
103
 		return 0;
103
 		return 0;
104
 	}
104
 	}
105
 	
105
 	
106
 	/* Fetch file, a block at a time */
106
 	/* Fetch file, a block at a time */
107
-	do {
107
+	while ( 1 ) {
108
 		twiddle();
108
 		twiddle();
109
 		switch ( ntohs ( reply->common.opcode ) ) {
109
 		switch ( ntohs ( reply->common.opcode ) ) {
110
 		case TFTP_DATA:
110
 		case TFTP_DATA:
111
-			if ( ! process_tftp_data ( &state, &reply->data,
111
+			if ( ! tftp_process_data ( &state, &reply->data,
112
 						   buffer, &eof ) ) {
112
 						   buffer, &eof ) ) {
113
 				tftp_error ( &state, TFTP_ERR_ILLEGAL_OP,
113
 				tftp_error ( &state, TFTP_ERR_ILLEGAL_OP,
114
 					     NULL );
114
 					     NULL );
138
 			tftp_error ( &state, TFTP_ERR_ILLEGAL_OP, NULL );
138
 			tftp_error ( &state, TFTP_ERR_ILLEGAL_OP, NULL );
139
 			return 0;
139
 			return 0;
140
 		}
140
 		}
141
+		/* If we have reached EOF, stop here */
142
+		if ( eof )
143
+			break;
141
 		/* Fetch the next data block */
144
 		/* Fetch the next data block */
142
 		if ( ! tftp_ack ( &state, &reply ) ) {
145
 		if ( ! tftp_ack ( &state, &reply ) ) {
143
 			DBG ( "TFTP: could not get next block: %m\n" );
146
 			DBG ( "TFTP: could not get next block: %m\n" );
144
-			tftp_error ( &state, TFTP_ERR_ILLEGAL_OP, NULL );
147
+			if ( ! reply ) {
148
+				tftp_error ( &state, TFTP_ERR_ILLEGAL_OP,
149
+					     NULL );
150
+			}
145
 			return 0;
151
 			return 0;
146
 		}
152
 		}
147
-	} while ( ! eof );
153
+	}
148
 
154
 
149
 	/* ACK the final packet, as a courtesy to the server */
155
 	/* ACK the final packet, as a courtesy to the server */
150
 	tftp_ack_nowait ( &state );
156
 	tftp_ack_nowait ( &state );

Loading…
Cancel
Save