Bug 3426 - canonicalize_file_name's behavior differs from documentation
Summary: canonicalize_file_name's behavior differs from documentation
Status: RESOLVED FIXED
Alias: None
Product: glibc
Classification: Unclassified
Component: libc (show other bugs)
Version: 2.3.5
: P2 normal
Target Milestone: ---
Assignee: Ulrich Drepper
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-10-26 05:38 UTC by abcdef
Modified: 2018-04-20 14:11 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:
fweimer: security-


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description abcdef 2006-10-26 05:38:18 UTC
In GNU libc 2.3.5, the header file /usr/lib/stdlib.h reads:

#ifdef  __USE_GNU                                                               
/* Return a malloc'd string containing the canonical absolute name of the       
   named file.  The last file name component need not exist, and may be a       
   symlink to a nonexistent file.  */                                           
extern char *canonicalize_file_name (__const char *__name)                      
     __THROW __nonnull ((1));                                                   
#endif                            


However, canonicalize_file_name() returns NULL when passed a path where the last
component does not exist.

// file: can-test.c

#define _GNU_SOURCE                                                             
#include <stdlib.h>                                                             
#include <stdio.h>                                                              

int main(void)                                                                  
{                                                                               
   char *p = canonicalize_file_name("no-such-file");                            
                                                                                
   if (!p)                                                                      
     perror(NULL);                                                              
                                                                                
   return 0;                                                                    
}

The same applies to realpath() and its description. As of version 2.3.5, either
the documentation or the implementation is wrong.

Best

Juergen Lemke
Comment 1 Jakub Jelinek 2006-10-26 07:13:00 UTC
__nonnull ((1)) means that the first argument must not be NULL, not that
the function can't return NULL.
Comment 2 abcdef 2006-10-26 20:13:43 UTC
Hello,

jakub at redhat dot com wrote:

> __nonnull ((1)) means that the first argument must
> not be NULL, not that
> the function can't return NULL.

That is not what I was referring to. Just above the declaration of
canonicalize_file_name() you can read:

"The last file name component need not exist [...]"

However, as of GNU libc 2.3.5, this function always fails (returning NULL) when
passed a path to a inexistent file.

Best,

Juergen
Comment 3 Dmitry V. Levin 2006-10-26 21:16:41 UTC
As of glibc HEAD, stdlib/stdlib.h really contains wrong comments about
canonicalize_file_name() and realpath().  The comment in stdlib/canonicalize.c
is correct, though.
Comment 4 Ulrich Drepper 2006-10-27 18:47:43 UTC
I adjusted the comment.