[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: GRUB 1.95 cannot read the ufs filesystem

From: Hitoshi Ozeki
Subject: RE: GRUB 1.95 cannot read the ufs filesystem
Date: Wed, 18 Apr 2007 03:31:32 +0900

Hello, all.

        Johan Rydberg wrote:
        > GRUB 1.95 cannot read the ufs filesystem.
        > This patch fixes this problem, and make it a bit better.
        Could you maybe point out the problem for us?  
        Personally, I think the use of pointers make the code more complex.

At first, When we use the 'strcmp' for the purpose of comparision C-strings,
It requires to terminate with the NIL sentry('\0').

grub_ufs_find_file (struct grub_ufs_data *data, const char *path)
  char fpath[grub_strlen (path)];  <-- not enough.
  char *name = fpath;
  char *next;
  unsigned int pos = 0;
  int dirino;
  grub_strncpy (fpath, path, grub_strlen (path));   <--without NIL.

>From the manpage of 'strncpy(3)':
       The  strcpy()  function  copies the string pointed to by src
       the terminating `\0' character) to the array pointed to by  dest.
       strings  may not overlap, and the destination string dest must be
       enough to receive the copy.

       The strncpy() function is similar, except that not more than n bytes
       src  are copied. Thus, if there is no null byte among the first n
       of src, the result will not be null-terminated.

At second, However we have the filepath in 'const char* path',
The original code copies the filepath. It wastes the processor time.

If you think the use of pointers makes complex,
I recommend to use array and index.

In addition, ufs filesystem has no label.

static struct grub_fs grub_ufs_fs =
    .name = "ufs",
    .dir = grub_ufs_dir,
    .open = grub_ufs_open,
    .read = grub_ufs_read,
    .close = grub_ufs_close,
    .label = grub_ufs_label,
    .next = 0

The '.label' should set to 0.
On the original code, The 'label' function returns the invalid pointer,
so the 'ls -l' command gets wrong.

 Hitoshi Ozeki

reply via email to

[Prev in Thread] Current Thread [Next in Thread]