--- grub-1.95/fs/ufs.c 2006-06-04 17:55:56.000000000 +0900 +++ grub-1.95-new/fs/ufs.c 2007-04-12 08:05:09.698149332 +0900 @@ -394,16 +394,13 @@ static grub_err_t grub_ufs_find_file (struct grub_ufs_data *data, const char *path) { - char fpath[grub_strlen (path)]; - char *name = fpath; - char *next; + const char *name = path; + const char *next; unsigned int pos = 0; int dirino; - grub_strncpy (fpath, path, grub_strlen (path)); - /* Skip the first slash. */ - if (name[0] == '/') + if (*name == '/') { name++; if (!*name) @@ -412,17 +409,14 @@ /* Extract the actual part from the pathname. */ next = grub_strchr (name, '/'); - if (next) - { - next[0] = '\0'; - next++; - } + if (!next) + next = &name[grub_strlen(name)]; do { struct grub_ufs_dirent dirent; - if (grub_strlen (name) == 0) + if (next <= name) return GRUB_ERR_NONE; if (grub_ufs_read_file (data, 0, pos, sizeof (dirent), @@ -430,15 +424,13 @@ return grub_errno; { - char filename[dirent.namelen + 1]; + char filename[dirent.namelen]; if (grub_ufs_read_file (data, 0, pos + sizeof (dirent), dirent.namelen, filename) < 0) return grub_errno; - filename[dirent.namelen] = '\0'; - - if (!grub_strcmp (name, filename)) + if ((&name[dirent.namelen] == next) && !grub_strncmp (name, filename, dirent.namelen)) { dirino = data->ino; grub_ufs_read_inode (data, grub_le_to_cpu32 (dirent.ino)); @@ -450,18 +442,15 @@ return grub_errno; } - if (!next) + if (!*next) return 0; pos = 0; - name = next; - next = grub_strchr (name, '/'); - if (next) - { - next[0] = '\0'; - next++; - } + name = next + 1; + next = grub_strchr (name, '/'); + if (!next) + next = &name[grub_strlen(name)]; if (!(dirent.filetype & GRUB_UFS_FILETYPE_DIR)) return grub_error (GRUB_ERR_BAD_FILE_TYPE, "not a directory"); @@ -599,34 +588,43 @@ grub_ufs_open (struct grub_file *file, const char *name) { struct grub_ufs_data *data; + +#ifndef GRUB_UTIL + grub_dl_ref (my_mod); +#endif + data = grub_ufs_mount (file->device->disk); if (!data) return grub_errno; grub_ufs_read_inode (data, 2); if (grub_errno) - { - grub_free (data); - return grub_errno; - } + goto fail; if (!name || name[0] != '/') { grub_error (GRUB_ERR_BAD_FILENAME, "bad filename"); - return grub_errno; + goto fail; } grub_ufs_find_file (data, name); if (grub_errno) - { - grub_free (data); - return grub_errno; - } + goto fail; file->data = data; file->size = INODE_SIZE (data); return GRUB_ERR_NONE; + + fail: + + grub_free (data); + +#ifndef GRUB_UTIL + grub_dl_unref (my_mod); +#endif + + return grub_errno; }