Skip to content

Commit

Permalink
Hurd: Fix linkat symlink handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
Emilio Pozuelo Monfort authored and Roland McGrath committed Jun 2, 2010
1 parent eb5ad2e commit 2a50c07
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
9 changes: 9 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
2010-06-02 Emilio Pozuelo Monfort <pochu27@gmail.com>

* hurd/lookup-at.c (__file_name_lookup_at): Accept
AT_SYMLINK_FOLLOW in AT_FLAGS. Fail with EINVAL if both
AT_SYMLINK_FOLLOW and AT_SYMLINK_NOFOLLOW are present
in AT_FLAGS.
* hurd/hurd/fd.h (__file_name_lookup_at): Update comment.
* sysdeps/mach/hurd/linkat.c (linkat): Pass O_NOLINK in FLAGS.

2010-05-28 Luis Machado <luisgpm@br.ibm.com>

* sysdeps/powerpc/powerpc32/power7/memcpy.S: Exchange srdi for srwi.
Expand Down
5 changes: 3 additions & 2 deletions hurd/hurd/fd.h
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,9 @@ extern int _hurd_select (int nfds, struct pollfd *pollfds,
const sigset_t *sigmask);

/* Variant of file_name_lookup used in *at function implementations.
AT_FLAGS should contain only AT_SYMLINK_NOFOLLOW; other bits
cause EINVAL. */
AT_FLAGS may only contain AT_SYMLINK_FOLLOW or AT_SYMLINK_NOFOLLOW,
which will remove and add O_NOLINK from FLAGS respectively.
Other bits cause EINVAL. */
extern file_t __file_name_lookup_at (int fd, int at_flags,
const char *file_name,
int flags, mode_t mode);
Expand Down
6 changes: 6 additions & 0 deletions hurd/lookup-at.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,14 @@ __file_name_lookup_at (int fd, int at_flags,
error_t err;
file_t result;

if ((at_flags & AT_SYMLINK_FOLLOW) && (at_flags & AT_SYMLINK_NOFOLLOW))
return (__hurd_fail (EINVAL), MACH_PORT_NULL);

flags |= (at_flags & AT_SYMLINK_NOFOLLOW) ? O_NOLINK : 0;
at_flags &= ~AT_SYMLINK_NOFOLLOW;
if (at_flags & AT_SYMLINK_FOLLOW)
flags &= ~O_NOLINK;
at_flags &= ~AT_SYMLINK_FOLLOW;
if (at_flags != 0)
return (__hurd_fail (EINVAL), MACH_PORT_NULL);

Expand Down
6 changes: 4 additions & 2 deletions sysdeps/mach/hurd/linkat.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Make a link between file names relative to open directories. Hurd version.
Copyright (C) 2006 Free Software Foundation, Inc.
Copyright (C) 2006,2010 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
Expand Down Expand Up @@ -38,7 +38,9 @@ linkat (fromfd, from, tofd, to, flags)
file_t oldfile, linknode, todir;
char *toname;

oldfile = __file_name_lookup_at (fromfd, flags, from, 0, 0);
/* POSIX says linkat doesn't follow symlinks by default, so pass
O_NOLINK. That can be overridden by AT_SYMLINK_FOLLOW in FLAGS. */
oldfile = __file_name_lookup_at (fromfd, flags, from, O_NOLINK, 0);
if (oldfile == MACH_PORT_NULL)
return -1;

Expand Down

0 comments on commit 2a50c07

Please sign in to comment.