aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Kiszka <jan.kiszka@web.de>2009-06-29 08:47:30 +0200
committerAnthony Liguori <aliguori@us.ibm.com>2009-06-29 14:18:08 -0500
commit256167dc15d3932b02404905f041fc56e34b18de (patch)
tree07c3faeebcaffc719b496f9c606d52b4319bb81c
parent16f7094801480524cbd231939691c433c29f3491 (diff)
downloadslirp-256167dc15d3932b02404905f041fc56e34b18de.zip
slirp-256167dc15d3932b02404905f041fc56e34b18de.tar.gz
slirp-256167dc15d3932b02404905f041fc56e34b18de.tar.bz2
slirp: tftp: Relax filename format check
[ Applies on top of my recently posted slirp series. ] Allow tftp requests with filenames that do not start with a slash. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
-rw-r--r--tftp.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/tftp.c b/tftp.c
index 59fc91d..838176b 100644
--- a/tftp.c
+++ b/tftp.c
@@ -283,11 +283,12 @@ static void tftp_handle_rrq(Slirp *slirp, struct tftp_t *tp, int pktlen)
/* prepend tftp_prefix */
prefix_len = strlen(slirp->tftp_prefix);
- spt->filename = qemu_malloc(prefix_len + TFTP_FILENAME_MAX + 1);
+ spt->filename = qemu_malloc(prefix_len + TFTP_FILENAME_MAX + 2);
memcpy(spt->filename, slirp->tftp_prefix, prefix_len);
+ spt->filename[prefix_len] = '/';
/* get name */
- req_fname = spt->filename + prefix_len;
+ req_fname = spt->filename + prefix_len + 1;
while (1) {
if (k >= TFTP_FILENAME_MAX || k >= pktlen) {
@@ -314,8 +315,8 @@ static void tftp_handle_rrq(Slirp *slirp, struct tftp_t *tp, int pktlen)
k += 6; /* skipping octet */
/* do sanity checks on the filename */
- if (req_fname[0] != '/' || req_fname[strlen(req_fname) - 1] == '/' ||
- strstr(req_fname, "/../")) {
+ if (!strncmp(req_fname, "../", 3) ||
+ req_fname[strlen(req_fname) - 1] == '/' || strstr(req_fname, "/../")) {
tftp_send_error(spt, 2, "Access violation", tp);
return;
}