slirp: tftp: Cleanup tftp_prefix check
authorJan Kiszka <jan.kiszka@siemens.com>
Wed, 24 Jun 2009 12:42:29 +0000 (14:42 +0200)
committerAnthony Liguori <aliguori@us.ibm.com>
Mon, 29 Jun 2009 13:52:47 +0000 (08:52 -0500)
Perform check for set prefix early (if it's not given, tftp is disabled)
and drop redundant second check.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>

slirp/tftp.c

index 3358e2b..5d5614a 100644 (file)
@@ -287,6 +287,12 @@ static void tftp_handle_rrq(struct tftp_t *tp, int pktlen)
 
   spt = &tftp_sessions[s];
 
+  /* unspecifed prefix means service disabled */
+  if (!tftp_prefix) {
+      tftp_send_error(spt, 2, "Access violation", tp);
+      return;
+  }
+
   src = tp->x.tp_buf;
   dst = spt->filename;
   n = pktlen - ((uint8_t *)&tp->x.tp_buf[0] - (uint8_t *)tp);
@@ -333,13 +339,6 @@ static void tftp_handle_rrq(struct tftp_t *tp, int pktlen)
       return;
   }
 
-  /* only allow exported prefixes */
-
-  if (!tftp_prefix) {
-      tftp_send_error(spt, 2, "Access violation", tp);
-      return;
-  }
-
   /* check if the file exists */
 
   if (tftp_read_data(spt, 0, spt->filename, 0) < 0) {
@@ -370,7 +369,7 @@ static void tftp_handle_rrq(struct tftp_t *tp, int pktlen)
          int tsize = atoi(value);
          struct stat stat_p;
 
-         if (tsize == 0 && tftp_prefix) {
+         if (tsize == 0) {
              char buffer[1024];
              int len;