* grub-core/net/drivers/ieee1275/ofnet.c: Likewise.
+2013-12-04 Vladimir Serbinenko <phcoder@gmail.com>
+
+ * grub-core/disk/ieee1275/ofdisk.c: Remove variable length arrays.
+ * grub-core/net/drivers/ieee1275/ofnet.c: Likewise.
+
2013-12-03 Colin Watson <cjwatson@ubuntu.com>
* grub-core/Makefile.core.def (setjmp): Distribute
struct ofdisk_hash_ent
{
char *devpath;
+ char *open_path;
+ char *grub_devpath;
int is_boot;
int is_cdrom;
/* Pointer to shortest available name on nodes representing canonical names,
otherwise NULL. */
const char *shortest;
+ const char *grub_shortest;
struct ofdisk_hash_ent *next;
};
{
struct ofdisk_hash_ent *p;
struct ofdisk_hash_ent **head = &ofdisk_hash[ofdisk_hash_fn(devpath)];
+ const char *iptr;
+ char *optr;
p = grub_zalloc (sizeof (*p));
if (!p)
return NULL;
p->devpath = devpath;
+
+ p->grub_devpath = grub_malloc (sizeof ("ieee1275/")
+ + 2 * grub_strlen (p->devpath));
+
+ if (!p->grub_devpath)
+ {
+ grub_free (p);
+ return NULL;
+ }
+
+ if (! grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_NO_PARTITION_0))
+ {
+ p->open_path = grub_malloc (grub_strlen (p->devpath) + 3);
+ if (!p->open_path)
+ {
+ grub_free (p->grub_devpath);
+ grub_free (p);
+ return NULL;
+ }
+ optr = grub_stpcpy (p->open_path, p->devpath);
+ *optr++ = ':';
+ *optr++ = '0';
+ *optr = '\0';
+ }
+ else
+ p->open_path = p->devpath;
+
+ optr = grub_stpcpy (p->grub_devpath, "ieee1275/");
+ for (iptr = p->devpath; *iptr; )
+ {
+ if (*iptr == ',')
+ *optr++ = '\\';
+ *optr++ = *iptr++;
+ }
+ *optr = 0;
+
p->next = *head;
*head = p;
return p;
if (!curcan)
{
- p->shortest = devpath;
+ p->shortest = p->devpath;
+ p->grub_shortest = p->grub_devpath;
if (check_string_cdrom (devpath))
p->is_cdrom = 1;
return p;
{
if (!pcan->shortest
|| grub_strlen (pcan->shortest) > grub_strlen (devpath))
- pcan->shortest = devpath;
+ {
+ pcan->shortest = p->devpath;
+ pcan->grub_shortest = p->grub_devpath;
+ }
}
return p;
if (!ent->is_boot && ent->is_cdrom)
continue;
- {
- char buffer[sizeof ("ieee1275/") + 2 * grub_strlen (ent->shortest)];
- const char *iptr;
- char *optr;
- optr = grub_stpcpy (buffer, "ieee1275/");
- for (iptr = ent->shortest; *iptr; )
- {
- if (*iptr == ',')
- *optr++ = '\\';
- *optr++ = *iptr++;
- }
- *optr = 0;
- if (hook (buffer, hook_data))
- return 1;
- }
+ if (hook (ent->grub_shortest, hook_data))
+ return 1;
}
}
return 0;
if (!op)
return grub_errno;
disk->id = (unsigned long) op;
- disk->data = op->devpath;
+ disk->data = op->open_path;
}
return 0;
last_ihandle = 0;
last_devpath = NULL;
- if (! grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_NO_PARTITION_0))
- {
- char name2[grub_strlen (disk->data) + 3];
- char *p;
-
- grub_strcpy (name2, disk->data);
- p = name2 + grub_strlen (name2);
- *p++ = ':';
- *p++ = '0';
- *p = 0;
- grub_ieee1275_open (name2, &last_ihandle);
- }
- else
- grub_ieee1275_open (disk->data, &last_ihandle);
+ grub_ieee1275_open (disk->data, &last_ihandle);
if (! last_ihandle)
return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't open device");
last_devpath = disk->data;
struct grub_ofnetcard_data
{
char *path;
+ char *suffix;
grub_ieee1275_ihandle_t handle;
};
int status;
struct grub_ofnetcard_data *data = dev->data;
- if (!grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_NO_OFNET_SUFFIX))
- {
- char path[grub_strlen (data->path) +
- sizeof (":speed=auto,duplex=auto,1.1.1.1,dummy,1.1.1.1,1.1.1.1,5,5,1.1.1.1,512")];
-
- /* The full string will prevent a bootp packet to be sent. Just put some valid ip in there. */
- grub_snprintf (path, sizeof (path), "%s%s", data->path,
- ":speed=auto,duplex=auto,1.1.1.1,dummy,1.1.1.1,1.1.1.1,5,5,1.1.1.1,512");
- status = grub_ieee1275_open (path, &(data->handle));
- }
- else
- status = grub_ieee1275_open (data->path, &(data->handle));
+ status = grub_ieee1275_open (data->path, &(data->handle));
if (status)
return grub_error (GRUB_ERR_IO, "Couldn't open network card.");
FOR_NET_CARDS (card)
{
char *bootp_response;
- char *cardpath;
char *canon;
+ char c;
+ struct grub_ofnetcard_data *data;
grub_ssize_t size = -1;
unsigned int i;
if (card->driver != &ofdriver)
continue;
- cardpath = ((struct grub_ofnetcard_data *) card->data)->path;
- canon = grub_ieee1275_canonicalise_devname (cardpath);
+ data = card->data;
+ c = *data->suffix;
+ *data->suffix = '\0';
+ canon = grub_ieee1275_canonicalise_devname (data->path);
+ *data->suffix = c;
if (grub_strcmp (devpath, canon) != 0)
{
grub_free (canon);
return 1;
}
- ofdata->path = grub_strdup (alias->path);
+#define SUFFIX ":speed=auto,duplex=auto,1.1.1.1,dummy,1.1.1.1,1.1.1.1,5,5,1.1.1.1,512"
+
+ if (!grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_NO_OFNET_SUFFIX))
+ ofdata->path = grub_malloc (grub_strlen (alias->path) + sizeof (SUFFIX));
+ else
+ ofdata->path = grub_malloc (grub_strlen (alias->path) + 1);
+ if (!ofdata->path)
+ {
+ grub_print_error ();
+ return 0;
+ }
+ ofdata->suffix = grub_stpcpy (ofdata->path, alias->path);
+ if (!grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_NO_OFNET_SUFFIX))
+ grub_memcpy (ofdata->suffix, SUFFIX, sizeof (SUFFIX));
+ else
+ *ofdata->suffix = '\0';
grub_ieee1275_finddevice (ofdata->path, &devhandle);