Changeset 34a74ab in mainline for uspace/lib/libc/generic/vfs/vfs.c


Ignore:
Timestamp:
2008-08-11T16:40:29Z (16 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
17b2aac
Parents:
9fcdb2e
Message:

Fix absolutize() wrt. to relative paths.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/libc/generic/vfs/vfs.c

    r9fcdb2e r34a74ab  
    6363{
    6464        char *ncwd_path;
     65        char *ncwd_path_nc;
    6566
    6667        futex_down(&cwd_futex);
     
    7172                        return NULL;
    7273                }
    73                 ncwd_path = malloc(len + cwd_len + 1);
    74                 if (!ncwd_path) {
     74                ncwd_path_nc = malloc(len + cwd_len + 1);
     75                if (!ncwd_path_nc) {
    7576                        futex_up(&cwd_futex);
    7677                        return NULL;
    7778                }
    78                 strcpy(ncwd_path, cwd_path);
    79                 ncwd_path[cwd_len] = '/';
    80                 ncwd_path[cwd_len + 1] = '\0';
     79                strcpy(ncwd_path_nc, cwd_path);
     80                ncwd_path_nc[cwd_len] = '/';
     81                ncwd_path_nc[cwd_len + 1] = '\0';
    8182        } else {
    82                 ncwd_path = malloc(len + 1);
    83                 if (!ncwd_path) {
     83                ncwd_path_nc = malloc(len + 1);
     84                if (!ncwd_path_nc) {
    8485                        futex_up(&cwd_futex);
    8586                        return NULL;
    8687                }
    87                 ncwd_path[0] = '\0';
    88         }
    89         strcat(ncwd_path, path);
    90         if (!canonify(ncwd_path, retlen)) {
     88                ncwd_path_nc[0] = '\0';
     89        }
     90        strcat(ncwd_path_nc, path);
     91        ncwd_path = canonify(ncwd_path_nc, retlen);
     92        if (!ncwd_path) {
    9193                futex_up(&cwd_futex);
    92                 free(ncwd_path);
     94                free(ncwd_path_nc);
     95                return NULL;
     96        }
     97        /*
     98         * We need to clone ncwd_path because canonify() works in-place and thus
     99         * the address in ncwd_path need not be the same as ncwd_path_nc, even
     100         * though they both point into the same dynamically allocated buffer.
     101         */
     102        ncwd_path = strdup(ncwd_path);
     103        free(ncwd_path_nc);
     104        if (!ncwd_path) {
     105                futex_up(&cwd_futex);
    93106                return NULL;
    94107        }
Note: See TracChangeset for help on using the changeset viewer.