* grub-core/disk/ieee1275/ofdisk.c: Remove variable length arrays.

* grub-core/net/drivers/ieee1275/ofnet.c: Likewise.
This commit is contained in:
Vladimir Serbinenko 2013-12-04 08:10:01 +01:00
parent 0c0eab527f
commit 234d93464a
3 changed files with 81 additions and 48 deletions

View file

@ -1,3 +1,8 @@
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> 2013-12-03 Colin Watson <cjwatson@ubuntu.com>
* grub-core/Makefile.core.def (setjmp): Distribute * grub-core/Makefile.core.def (setjmp): Distribute

View file

@ -31,11 +31,14 @@ static grub_ieee1275_ihandle_t last_ihandle;
struct ofdisk_hash_ent struct ofdisk_hash_ent
{ {
char *devpath; char *devpath;
char *open_path;
char *grub_devpath;
int is_boot; int is_boot;
int is_cdrom; int is_cdrom;
/* Pointer to shortest available name on nodes representing canonical names, /* Pointer to shortest available name on nodes representing canonical names,
otherwise NULL. */ otherwise NULL. */
const char *shortest; const char *shortest;
const char *grub_shortest;
struct ofdisk_hash_ent *next; struct ofdisk_hash_ent *next;
}; };
@ -70,12 +73,50 @@ ofdisk_hash_add_real (char *devpath)
{ {
struct ofdisk_hash_ent *p; struct ofdisk_hash_ent *p;
struct ofdisk_hash_ent **head = &ofdisk_hash[ofdisk_hash_fn(devpath)]; struct ofdisk_hash_ent **head = &ofdisk_hash[ofdisk_hash_fn(devpath)];
const char *iptr;
char *optr;
p = grub_zalloc (sizeof (*p)); p = grub_zalloc (sizeof (*p));
if (!p) if (!p)
return NULL; return NULL;
p->devpath = devpath; 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; p->next = *head;
*head = p; *head = p;
return p; return p;
@ -104,7 +145,8 @@ ofdisk_hash_add (char *devpath, char *curcan)
if (!curcan) if (!curcan)
{ {
p->shortest = devpath; p->shortest = p->devpath;
p->grub_shortest = p->grub_devpath;
if (check_string_cdrom (devpath)) if (check_string_cdrom (devpath))
p->is_cdrom = 1; p->is_cdrom = 1;
return p; return p;
@ -125,7 +167,10 @@ ofdisk_hash_add (char *devpath, char *curcan)
{ {
if (!pcan->shortest if (!pcan->shortest
|| grub_strlen (pcan->shortest) > grub_strlen (devpath)) || grub_strlen (pcan->shortest) > grub_strlen (devpath))
pcan->shortest = devpath; {
pcan->shortest = p->devpath;
pcan->grub_shortest = p->grub_devpath;
}
} }
return p; return p;
@ -288,21 +333,8 @@ grub_ofdisk_iterate (grub_disk_dev_iterate_hook_t hook, void *hook_data,
if (!ent->is_boot && ent->is_cdrom) if (!ent->is_boot && ent->is_cdrom)
continue; continue;
{ if (hook (ent->grub_shortest, hook_data))
char buffer[sizeof ("ieee1275/") + 2 * grub_strlen (ent->shortest)]; return 1;
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;
}
} }
} }
return 0; return 0;
@ -396,7 +428,7 @@ grub_ofdisk_open (const char *name, grub_disk_t disk)
if (!op) if (!op)
return grub_errno; return grub_errno;
disk->id = (unsigned long) op; disk->id = (unsigned long) op;
disk->data = op->devpath; disk->data = op->open_path;
} }
return 0; return 0;
@ -428,20 +460,7 @@ grub_ofdisk_prepare (grub_disk_t disk, grub_disk_addr_t sector)
last_ihandle = 0; last_ihandle = 0;
last_devpath = NULL; last_devpath = NULL;
if (! grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_NO_PARTITION_0)) grub_ieee1275_open (disk->data, &last_ihandle);
{
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);
if (! last_ihandle) if (! last_ihandle)
return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't open device"); return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't open device");
last_devpath = disk->data; last_devpath = disk->data;

View file

@ -28,6 +28,7 @@ GRUB_MOD_LICENSE ("GPLv3+");
struct grub_ofnetcard_data struct grub_ofnetcard_data
{ {
char *path; char *path;
char *suffix;
grub_ieee1275_ihandle_t handle; grub_ieee1275_ihandle_t handle;
}; };
@ -37,18 +38,7 @@ card_open (struct grub_net_card *dev)
int status; int status;
struct grub_ofnetcard_data *data = dev->data; struct grub_ofnetcard_data *data = dev->data;
if (!grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_NO_OFNET_SUFFIX)) status = grub_ieee1275_open (data->path, &(data->handle));
{
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));
if (status) if (status)
return grub_error (GRUB_ERR_IO, "Couldn't open network card."); return grub_error (GRUB_ERR_IO, "Couldn't open network card.");
@ -146,8 +136,9 @@ grub_ieee1275_net_config_real (const char *devpath, char **device, char **path)
FOR_NET_CARDS (card) FOR_NET_CARDS (card)
{ {
char *bootp_response; char *bootp_response;
char *cardpath;
char *canon; char *canon;
char c;
struct grub_ofnetcard_data *data;
grub_ssize_t size = -1; grub_ssize_t size = -1;
unsigned int i; unsigned int i;
@ -155,8 +146,11 @@ grub_ieee1275_net_config_real (const char *devpath, char **device, char **path)
if (card->driver != &ofdriver) if (card->driver != &ofdriver)
continue; continue;
cardpath = ((struct grub_ofnetcard_data *) card->data)->path; data = card->data;
canon = grub_ieee1275_canonicalise_devname (cardpath); c = *data->suffix;
*data->suffix = '\0';
canon = grub_ieee1275_canonicalise_devname (data->path);
*data->suffix = c;
if (grub_strcmp (devpath, canon) != 0) if (grub_strcmp (devpath, canon) != 0)
{ {
grub_free (canon); grub_free (canon);
@ -224,7 +218,22 @@ search_net_devices (struct grub_ieee1275_devalias *alias)
return 1; 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); grub_ieee1275_finddevice (ofdata->path, &devhandle);