diff options
-rw-r--r-- | com32/include/dmi/dmi_bios.h | 14 | ||||
-rw-r--r-- | com32/include/sys/pci.h | 6 | ||||
-rw-r--r-- | com32/lib/pci/scan.c | 42 | ||||
-rw-r--r-- | com32/modules/dmi_utils.c | 6 |
4 files changed, 33 insertions, 35 deletions
diff --git a/com32/include/dmi/dmi_bios.h b/com32/include/dmi/dmi_bios.h index d9be233b..0241f0b2 100644 --- a/com32/include/dmi/dmi_bios.h +++ b/com32/include/dmi/dmi_bios.h @@ -22,7 +22,7 @@ #define BIOS_BIOS_REVISION_SIZE 16 #define BIOS_FIRMWARE_REVISION_SIZE 16 -#define BIOS_CHAR_NB_ELEMENTS 27 +#define BIOS_CHAR_NB_ELEMENTS 28 #define BIOS_CHAR_X1_NB_ELEMENTS 8 #define BIOS_CHAR_X2_NB_ELEMENTS 3 @@ -58,8 +58,8 @@ static const char *bios_charac_strings[]={ "NEC PC-98" /* 31 */ }; -/* this struct have BIOS_CHAR_NB_ELEMENTS */ -/* each bool is associated to the relevant message above */ +/* this struct has BIOS_CHAR_NB_ELEMENTS */ +/* each bool is associated with the relevant message above */ typedef struct { bool bios_characteristics_not_supported; bool isa; @@ -102,8 +102,8 @@ static const char *bios_charac_x1_strings[]={ "Smart battery is supported" /* 7 */ }; -/* this struct have BIOS_CHAR_X1_NB_ELEMENTS */ -/* each bool is associated to the relevant message above */ +/* this struct has BIOS_CHAR_X1_NB_ELEMENTS */ +/* each bool is associated with the relevant message above */ typedef struct { bool acpi; bool usb_legacy; @@ -121,8 +121,8 @@ static const char *bios_charac_x2_strings[]={ "Targeted content distribution is supported" /* 2 */ }; -/* this struct have BIOS_CHAR_X2_NB_ELEMENTS */ -/* each bool is associated to the relevant message above */ +/* this struct has BIOS_CHAR_X2_NB_ELEMENTS */ +/* each bool is associated with the relevant message above */ typedef struct { bool bios_boot_specification; bool bios_network_boot_by_keypress; diff --git a/com32/include/sys/pci.h b/com32/include/sys/pci.h index 3f9b0d97..a49475b6 100644 --- a/com32/include/sys/pci.h +++ b/com32/include/sys/pci.h @@ -11,9 +11,9 @@ typedef uint32_t pciaddr_t; /* a structure for extended pci information */ struct pci_dev_info { - char *vendor_name; - char *product_name; - char *linux_kernel_module; + char vendor_name[255]; + char product_name[255]; + char linux_kernel_module[64]; }; /* a struct to represent a pci device */ diff --git a/com32/lib/pci/scan.c b/com32/lib/pci/scan.c index 11869930..94c83bbe 100644 --- a/com32/lib/pci/scan.c +++ b/com32/lib/pci/scan.c @@ -92,13 +92,14 @@ void get_module_name_from_pci_ids(struct pci_device_list *pci_device_list) /* initialize the pci_dev_info structure if it doesn't exist yet. */ if (! pci_device->pci_dev_info) { - pci_device->pci_dev_info = calloc(1,sizeof (struct pci_device)); + pci_device->pci_dev_info = calloc(1,sizeof *pci_device->pci_dev_info); + if (!pci_device->pci_dev_info) { printf("Can't allocate memory\n"); return; } } - pci_device->pci_dev_info->linux_kernel_module=strdup("unknown"); + strlcpy(pci_device->pci_dev_info->linux_kernel_module,"unknown",7); } /* Opening the modules.pcimap (ofa linux kernel) from the boot device*/ @@ -162,9 +163,9 @@ void get_module_name_from_pci_ids(struct pci_device_list *pci_device_list) void get_name_from_pci_ids(struct pci_device_list *pci_device_list) { char line[MAX_LINE]; - char *vendor=NULL; + char vendor[255]; char vendor_id[5]; - char *product=NULL; + char product[255]; char product_id[5]; char sub_product_id[5]; char sub_vendor_id[5]; @@ -178,7 +179,7 @@ void get_name_from_pci_ids(struct pci_device_list *pci_device_list) /* initialize the pci_dev_info structure if it doesn't exist yet. */ if (! pci_device->pci_dev_info) { - pci_device->pci_dev_info = calloc(1,sizeof (struct pci_device)); + pci_device->pci_dev_info = calloc(1,sizeof *pci_device->pci_dev_info); if (!pci_device->pci_dev_info) { printf("Can't allocate memory\n"); @@ -186,15 +187,14 @@ void get_name_from_pci_ids(struct pci_device_list *pci_device_list) } } - pci_device->pci_dev_info->vendor_name=strdup("unknown"); - pci_device->pci_dev_info->product_name=strdup("unknown"); + strlcpy(pci_device->pci_dev_info->vendor_name,"unknown",7); + strlcpy(pci_device->pci_dev_info->product_name,"unknown",7); } /* Opening the pci.ids from the boot device*/ f=fopen("pci.ids","r"); if (!f) return; - strcpy(vendor_id,"0000"); strcpy(product_id,"0000"); strcpy(sub_product_id,"0000"); @@ -203,7 +203,6 @@ void get_name_from_pci_ids(struct pci_device_list *pci_device_list) /* for each line we found in the pci.ids*/ while ( fgets(line, sizeof line, f) ) { - /* Skipping uncessary lines */ if ((line[0] == '#') || (line[0] == ' ') || (line[0] == 'C') || (line[0] == 10)) @@ -212,13 +211,13 @@ void get_name_from_pci_ids(struct pci_device_list *pci_device_list) if (line[0] != '\t') { /* the 4th first chars are the vendor_id */ - strncpy(vendor_id,line,4); + strlcpy(vendor_id,line,4); /* the vendor name is the next field*/ vendor_id[4]=0; - vendor=strdup(skipspace(strstr(line," "))); - remove_eol(vendor); + strlcpy(vendor,skipspace(strstr(line," ")),255); + remove_eol(vendor); /* init product_id, sub_product and sub_vendor */ strcpy(product_id,"0000"); strcpy(sub_product_id,"0000"); @@ -226,24 +225,23 @@ void get_name_from_pci_ids(struct pci_device_list *pci_device_list) /* ffff is an invalid vendor id */ if (strstr(vendor_id,"ffff")) break; - /* assign the vendor_name to any matching pci device*/ for (pci_dev=0; pci_dev < pci_device_list->count; pci_dev++) { struct pci_device *pci_device = &pci_device_list->pci_device[pci_dev]; if (hex_to_int(vendor_id) == pci_device->vendor) - pci_device->pci_dev_info->vendor_name=strdup(vendor); + strlcpy(pci_device->pci_dev_info->vendor_name,vendor,255); } /* if we have a tab + a char, it means this is a product id */ } else if ((line[0] == '\t') && (line[1] != '\t')) { /* the product name the second field */ - product=strdup(skipspace(strstr(line," "))); + strlcpy(product,skipspace(strstr(line," ")),255); remove_eol(product); /* the product id is first field */ - strncpy(product_id,&line[1],4); + strlcpy(product_id,&line[1],4); product_id[4]=0; /* init sub_product and sub_vendor */ @@ -256,23 +254,23 @@ void get_name_from_pci_ids(struct pci_device_list *pci_device_list) &pci_device_list->pci_device[pci_dev]; if (hex_to_int(vendor_id) == pci_device->vendor && hex_to_int(product_id) == pci_device->product) - pci_device->pci_dev_info->product_name=strdup(product); + strlcpy(pci_device->pci_dev_info->product_name,product,255); } /* if we have two tabs, it means this is a sub product */ } else if ((line[0] == '\t') && (line[1] == '\t')) { /* the product name is last field */ - product=skipspace(strstr(line," ")); - product=strdup(skipspace(strstr(product," "))); + strlcpy(product,skipspace(strstr(line," ")),255); + strlcpy(product,skipspace(strstr(product," ")),255); remove_eol(product); /* the sub_vendor id is first field */ - strncpy(sub_vendor_id,&line[2],4); + strlcpy(sub_vendor_id,&line[2],4); sub_vendor_id[4]=0; /* the sub_vendor id is second field */ - strncpy(sub_product_id,&line[7],4); + strlcpy(sub_product_id,&line[7],4); sub_product_id[4]=0; /* assign the product_name to any matching pci device*/ @@ -284,7 +282,7 @@ void get_name_from_pci_ids(struct pci_device_list *pci_device_list) hex_to_int(product_id) == pci_device->product && hex_to_int(sub_product_id) == pci_device->sub_product && hex_to_int(sub_vendor_id) == pci_device->sub_vendor) - pci_device->pci_dev_info->product_name=strdup(product); + strlcpy(pci_device->pci_dev_info->product_name,product,255); } } } diff --git a/com32/modules/dmi_utils.c b/com32/modules/dmi_utils.c index 83b50d82..df03ba7c 100644 --- a/com32/modules/dmi_utils.c +++ b/com32/modules/dmi_utils.c @@ -31,18 +31,18 @@ void display_bios_characteristics(s_dmi *dmi) { int i; - for (i=0;i<=BIOS_CHAR_NB_ELEMENTS; i++) { + for (i=0;i<BIOS_CHAR_NB_ELEMENTS; i++) { if (((bool *)(& dmi->bios.characteristics))[i] == true) { moreprintf("\t\t%s\n", bios_charac_strings[i]); } } - for (i=0;i<=BIOS_CHAR_X1_NB_ELEMENTS; i++) { + for (i=0;i<BIOS_CHAR_X1_NB_ELEMENTS; i++) { if (((bool *)(& dmi->bios.characteristics_x1))[i] == true) { moreprintf("\t\t%s\n", bios_charac_x1_strings[i]); } } - for (i=0;i<=BIOS_CHAR_X2_NB_ELEMENTS; i++) { + for (i=0;i<BIOS_CHAR_X2_NB_ELEMENTS; i++) { if (((bool *)(& dmi->bios.characteristics_x2))[i] == true) { moreprintf("\t\t%s\n", bios_charac_x2_strings[i]); } |