[haiku-commits] Re: haiku: hrev47024 - src/build/libbe/storage

  • From: John Scipione <jscipione@xxxxxxxxx>
  • To: "haiku-commits@xxxxxxxxxxxxx" <haiku-commits@xxxxxxxxxxxxx>
  • Date: Mon, 17 Mar 2014 14:04:08 -0400

On Mon, Mar 17, 2014 at 1:22 PM,  <superstippi@xxxxxx> wrote:
> diff --git a/src/build/libbe/storage/Entry.cpp 
> b/src/build/libbe/storage/Entry.cpp
> index 2f6accf..93dd8f8 100644
> --- a/src/build/libbe/storage/Entry.cpp
> +++ b/src/build/libbe/storage/Entry.cpp
> @@ -985,10 +985,11 @@ BEntry::set(int dirFD, const char *path, bool traverse)
>                         // we need to traverse the symlink
>                         if (--linkLimit < 0)
>                                 return B_LINK_LIMIT;
> -                       size_t bufferSize = B_PATH_NAME_LENGTH;
> +                       size_t bufferSize = B_PATH_NAME_LENGTH - 1;
>                         error = _kern_read_link(dirFD, leafName, tmpPath, 
> &bufferSize);
>                         if (error < 0)
>                                 return error;
> +                       tmpPath[bufferSize] = '\0';
>                         path = tmpPath;
>                         // next round...
>                 }

This is not right.

B_PATH_NAME_LENGTH is defined as PATH_MAX

According to this:
http://pubs.opengroup.org/onlinepubs/009695399/basedefs/limits.h.html

{PATH_MAX} Maximum number of bytes in a pathname, including the
terminating null character.

So B_PATH_NAME_LENGTH should include the termination \0.

So it should be:

size_t bufferSize = B_PATH_NAME_LENGTH;

and then:

tmpPath[bufferSize - 1] = '\0';

Other related posts: