SHA256
1
0
forked from pool/dmidecode
dmidecode/dmidecode-03-let-read_file-return-the-actual-data-size.patch
Jean Delvare 925fc78f0a - dmidecode-01-add-no-sysfs-option-description-to-h-output.patch:
Add "--no-sysfs" option description to -h output.
- dmidecode-02-fix-no-smbios-nor-dmi-entry-point-found-on-smbios3.patch:
  Fix 'No SMBIOS nor DMI entry point found' on SMBIOS3.
- dmidecode-03-let-read_file-return-the-actual-data-size.patch:
  Let read_file return the actual data size.
- dmidecode-04-use-read_file-to-read-the-dmi-table-from-sysfs.patch:
  Use read_file() to read the DMI table from sysfs.
  https://savannah.nongnu.org/bugs/?46176
- dmidecode-05-use-dword-for-structure-table-maximum-size-in-smbios3.patch:
  Use DWORD for Structure table maximum size in SMBIOS3.
- dmidecode-06-hide-irrelevant-fixup-message.patch:
  Hide irrelevant fixup message.
  http://savannah.nongnu.org/support/?109024

OBS-URL: https://build.opensuse.org/package/show/Base:System/dmidecode?expand=0&rev=35
2016-05-03 14:15:10 +00:00

91 lines
2.9 KiB
Diff

From: Jean Delvare <jdelvare@suse.de>
Date: Mon, 2 Nov 2015 09:45:26 +0100
Subject: Let read_file return the actual data size
Git-commit: de9a74e1c60210bee229fcf55b1678a99d1b44dd
Let read_file return the actual data size to the caller. This gives
the caller the possibility to check that the data size is as expected
and large enough for the purpose, and report to the user if not.
---
dmidecode.c | 4 +++-
util.c | 11 +++++++----
util.h | 2 +-
3 files changed, 11 insertions(+), 6 deletions(-)
--- dmidecode-3.0.orig/dmidecode.c 2016-05-03 16:05:07.804884352 +0200
+++ dmidecode-3.0/dmidecode.c 2016-05-03 16:05:09.139896776 +0200
@@ -4748,6 +4748,7 @@ int main(int argc, char * const argv[])
int ret = 0; /* Returned value */
int found = 0;
off_t fp;
+ size_t size;
int efi;
u8 *buf;
@@ -4817,8 +4818,9 @@ int main(int argc, char * const argv[])
* contain one of several types of entry points, so read enough for
* the largest one, then determine what type it contains.
*/
+ size = 0x20;
if (!(opt.flags & FLAG_NO_SYSFS)
- && (buf = read_file(0x20, SYS_ENTRY_FILE)) != NULL)
+ && (buf = read_file(&size, SYS_ENTRY_FILE)) != NULL)
{
if (!(opt.flags & FLAG_QUIET))
printf("Getting SMBIOS data from sysfs.\n");
--- dmidecode-3.0.orig/util.c 2016-05-03 16:05:03.085840436 +0200
+++ dmidecode-3.0/util.c 2016-05-03 16:05:09.139896776 +0200
@@ -94,10 +94,11 @@ int checksum(const u8 *buf, size_t len)
* needs to be freed by the caller.
* This provides a similar usage model to mem_chunk()
*
- * Returns pointer to buffer of max_len bytes, or NULL on error
+ * Returns pointer to buffer of max_len bytes, or NULL on error, and
+ * sets max_len to the length actually read.
*
*/
-void *read_file(size_t max_len, const char *filename)
+void *read_file(size_t *max_len, const char *filename)
{
int fd;
size_t r2 = 0;
@@ -115,7 +116,7 @@ void *read_file(size_t max_len, const ch
return(NULL);
}
- if ((p = malloc(max_len)) == NULL)
+ if ((p = malloc(*max_len)) == NULL)
{
perror("malloc");
return NULL;
@@ -123,7 +124,7 @@ void *read_file(size_t max_len, const ch
do
{
- r = read(fd, p + r2, max_len - r2);
+ r = read(fd, p + r2, *max_len - r2);
if (r == -1)
{
if (errno != EINTR)
@@ -140,6 +141,8 @@ void *read_file(size_t max_len, const ch
while (r != 0);
close(fd);
+ *max_len = r2;
+
return p;
}
--- dmidecode-3.0.orig/util.h 2016-05-03 16:05:03.085840436 +0200
+++ dmidecode-3.0/util.h 2016-05-03 16:05:09.139896776 +0200
@@ -25,7 +25,7 @@
#define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0]))
int checksum(const u8 *buf, size_t len);
-void *read_file(size_t len, const char *filename);
+void *read_file(size_t *len, const char *filename);
void *mem_chunk(off_t base, size_t len, const char *devmem);
int write_dump(size_t base, size_t len, const void *data, const char *dumpfile, int add);
u64 u64_range(u64 start, u64 end);