aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorths <ths@c046a42c-6fe2-441c-8c8c-71466251a162>2007-02-20 00:12:07 +0000
committerths <ths@c046a42c-6fe2-441c-8c8c-71466251a162>2007-02-20 00:12:07 +0000
commitf20cbd66a57103d3fc7b0d4d7b99904af4dbf963 (patch)
tree357435b1dcaf85bab532ff9f009f55434c1d7e1f
parent18ace47fbc8ad8793b953aed140fcc24fe66d7f2 (diff)
downloadslirp-f20cbd66a57103d3fc7b0d4d7b99904af4dbf963.zip
slirp-f20cbd66a57103d3fc7b0d4d7b99904af4dbf963.tar.gz
slirp-f20cbd66a57103d3fc7b0d4d7b99904af4dbf963.tar.bz2
Change -tftp option to take a root directory, by Anthony Liguori.
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2441 c046a42c-6fe2-441c-8c8c-71466251a162
-rw-r--r--tftp.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/tftp.c b/tftp.c
index 95ab9d5..5b7a0cc 100644
--- a/tftp.c
+++ b/tftp.c
@@ -103,8 +103,14 @@ static int tftp_read_data(struct tftp_session *spt, u_int16_t block_nr,
{
int fd;
int bytes_read = 0;
+ char buffer[1024];
+ int n;
- fd = open(spt->filename, O_RDONLY | O_BINARY);
+ n = snprintf(buffer, sizeof(buffer), "%s/%s", tftp_prefix, spt->filename);
+ if (n >= sizeof(buffer))
+ return -1;
+
+ fd = open(buffer, O_RDONLY | O_BINARY);
if (fd < 0) {
return -1;
@@ -320,8 +326,7 @@ static void tftp_handle_rrq(struct tftp_t *tp, int pktlen)
/* only allow exported prefixes */
- if (!tftp_prefix ||
- (strncmp(spt->filename, tftp_prefix, strlen(tftp_prefix)) != 0)) {
+ if (!tftp_prefix) {
tftp_send_error(spt, 2, "Access violation", tp);
return;
}