Mercurial > gftp.yaz
diff lib/protocols.c @ 666:8ff1c1647b95
2005-1-18 Brian Masney <masneyb@gftp.org>
* lib/protocols.c (gftp_get_next_file) - if the remote server sends a
path with the filename, then strip the path off of the filename. If the
path didn't match the current directory, then give the user a warning.
A malicious server could change the path of the downloaded by adding
/../ to the path
author | masneyb |
---|---|
date | Wed, 19 Jan 2005 01:56:48 +0000 |
parents | cd38f25b7c5e |
children | 72a6de68d9c8 |
line wrap: on
line diff
--- a/lib/protocols.c Mon Jan 17 20:58:21 2005 +0000 +++ b/lib/protocols.c Wed Jan 19 01:56:48 2005 +0000 @@ -595,6 +595,7 @@ gftp_get_next_file (gftp_request * request, const char *filespec, gftp_file * fle) { + char *slashpos, *newfile; int fd, ret; g_return_val_if_fail (request != NULL, GFTP_EFATAL); @@ -612,6 +613,26 @@ { gftp_file_destroy (fle, 0); ret = request->get_next_file (request, fle, fd); + if (fle->file != NULL && (slashpos = strrchr (fle->file, '/')) != NULL) + { + if (*(slashpos + 1) == '\0') + { + gftp_file_destroy (fle, 0); + continue; + } + + *slashpos = '\0'; + newfile = g_strdup (slashpos + 1); + + if (strcmp (fle->file, request->directory) != 0) + request->logging_function (gftp_logging_error, request, + _("Warning: Stripping path off of file '%s'. The stripped path (%s) doesn't match the current directory (%s)\n"), + newfile, fle->file, request->directory, + g_strerror (errno)); + + g_free (fle->file); + fle->file = newfile; + } if (ret >= 0 && fle->file != NULL) fle->utf8_file = gftp_string_to_utf8 (request, fle->file);