This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH v4] linux: make getcwd(3) fail if it cannot obtain an absolute path [BZ #22679]


On Fri, Jan 12, 2018 at 12:44:17AM +0100, Florian Weimer wrote:
> On 01/11/2018 11:03 PM, Dmitry V. Levin wrote:
> > +  char *cwd = getcwd (NULL, 0);
> > +  TEST_COMPARE (errno, ENOENT);
> > +  TEST_VERIFY (cwd == NULL);
> 
> Maybe also add this?
> 
>    cwd = realpath (".", NULL);

I don't mind adding this, but where do we stop?
This is a test of getcwd, after all.

>    TEST_VERIFY (cwd == NULL);
>    TEST_COMPARE (errno, ENOENT);

The check for errno should go first because TEST_VERIFY potentially
clobbers errno (it invokes printf).

> I assume that we expect to fail realpath with ENOENT as well.

Sure.  Would you be happy with the following amendment to the test?

@@ -36,10 +36,19 @@ static void
 getcwd_callback (void *closure)
 {
   xchroot (chroot_dir);
+
   errno = 0;
   char *cwd = getcwd (NULL, 0);
   TEST_COMPARE (errno, ENOENT);
   TEST_VERIFY (cwd == NULL);
+  free (cwd);
+
+  errno = 0;
+  cwd = realpath (".", NULL);
+  TEST_COMPARE (errno, ENOENT);
+  TEST_VERIFY (cwd == NULL);
+  free (cwd);
+
   _exit (0);
 }
 

-- 
ldv

Attachment: signature.asc
Description: PGP signature


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]