Directory traversal problem

This is a discussion on Directory traversal problem within the C Programming forums, part of the General Programming Boards category; Thanks!...

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    11

    Directory traversal problem

    Thanks!
    Last edited by phlook; 03-16-2009 at 12:30 AM. Reason: completed

  2. #2
    cas
    cas is offline
    Registered User
    Join Date
    Sep 2007
    Posts
    991
    But return_dir is not initialized. Trying to write there is undefined, and can cause real problems.

    Once you fix that, I'm not sure what precisely your program is trying to do. But there's an issue with this:
    Code:
    dir_path = strcat(dir,"/");
    dir_path = strcat(dir_path,dp->d_name);
    Here you are modifying the string contained in dir. This means you are modifying the original string as passed to the function. An easy way around this is something like:
    Code:
    ff_gather(data, dp->d_name);
    chdir("..");
    and nothing else inside your if block.

    Whether this works depends on your needs.

  3. #3
    Registered User
    Join Date
    Mar 2009
    Posts
    11
    you are a saviour. why didn't i think of that sooner?!

    thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Directory traversal issue
    By Mostly Harmless in forum Windows Programming
    Replies: 5
    Last Post: 12-21-2007, 11:44 AM
  2. C/C++ String Problem.
    By Jaken Veina in forum C++ Programming
    Replies: 7
    Last Post: 07-09-2005, 10:11 PM
  3. Replies: 6
    Last Post: 07-30-2003, 03:08 AM
  4. Need Help
    By GSLR in forum C Programming
    Replies: 1
    Last Post: 02-05-2002, 11:20 AM
  5. The Site Directory
    By kermi3 in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 01-22-2002, 07:19 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21