diff options
author | Elliott Hughes <enh@google.com> | 2013-10-28 13:21:06 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2013-10-28 13:21:06 -0700 |
commit | 27586ebe1a7f2f45651b855a26b3203d63d015d6 (patch) | |
tree | c1311b6ea1c32e15f7c7a9e3c81f1e0f78fa0737 | |
parent | d4e9f076d621dcf6450acba178e65d63c076ae6e (diff) | |
download | android_bionic-27586ebe1a7f2f45651b855a26b3203d63d015d6.tar.gz android_bionic-27586ebe1a7f2f45651b855a26b3203d63d015d6.tar.bz2 android_bionic-27586ebe1a7f2f45651b855a26b3203d63d015d6.zip |
Fix utime/utimes when passed a NULL pointer.
Bug: 11383777
Change-Id: If944a42f3adfa8a6ce91c167c249e009ed63300a
-rw-r--r-- | libc/bionic/utimes.cpp | 12 | ||||
-rw-r--r-- | libc/include/utime.h | 4 | ||||
-rw-r--r-- | tests/sys_time_test.cpp | 8 |
3 files changed, 18 insertions, 6 deletions
diff --git a/libc/bionic/utimes.cpp b/libc/bionic/utimes.cpp index 8950972a6..65f2d0b76 100644 --- a/libc/bionic/utimes.cpp +++ b/libc/bionic/utimes.cpp @@ -34,9 +34,13 @@ int utimes(const char* path, const timeval tv[2]) { timespec ts[2]; - if (!timespec_from_timeval(ts[0], tv[0]) || !timespec_from_timeval(ts[1], tv[1])) { - errno = EINVAL; - return -1; + timespec* ts_ptr = NULL; + if (tv != NULL) { + if (!timespec_from_timeval(ts[0], tv[0]) || !timespec_from_timeval(ts[1], tv[1])) { + errno = EINVAL; + return -1; + } + ts_ptr = ts; } - return utimensat(AT_FDCWD, path, ts, 0); + return utimensat(AT_FDCWD, path, ts_ptr, 0); } diff --git a/libc/include/utime.h b/libc/include/utime.h index fa7cd2f1b..3d72da4be 100644 --- a/libc/include/utime.h +++ b/libc/include/utime.h @@ -25,6 +25,7 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ + #ifndef _UTIME_H_ #define _UTIME_H_ @@ -34,9 +35,8 @@ __BEGIN_DECLS -extern int utime(const char *, const struct utimbuf *); +extern int utime(const char*, const struct utimbuf*); __END_DECLS #endif /* _UTIME_H_ */ - diff --git a/tests/sys_time_test.cpp b/tests/sys_time_test.cpp index 186aa16c9..730992fca 100644 --- a/tests/sys_time_test.cpp +++ b/tests/sys_time_test.cpp @@ -19,6 +19,8 @@ #include <errno.h> #include <sys/time.h> +#include "TemporaryFile.h" + TEST(sys_time, utimes) { timeval tv[2]; memset(&tv, 0, sizeof(tv)); @@ -38,3 +40,9 @@ TEST(sys_time, utimes) { ASSERT_EQ(-1, utimes("/", tv)); ASSERT_EQ(EINVAL, errno); } + +// http://b/11383777 +TEST(sys_time, utimes_NULL) { + TemporaryFile tf; + ASSERT_EQ(0, utimes(tf.filename, NULL)); +} |