]>
Commit | Line | Data |
---|---|---|
4ffb9f95 JS |
1 | diff --git a/dmidecode.c b/dmidecode.c |
2 | index 183ced4..a43cfd1 100644 | |
3 | --- a/dmidecode.c | |
4 | +++ b/dmidecode.c | |
5 | @@ -4751,6 +4751,7 @@ int main(int argc, char * const argv[]) | |
6 | int ret = 0; /* Returned value */ | |
7 | int found = 0; | |
8 | off_t fp; | |
9 | + size_t size; | |
10 | int efi; | |
11 | u8 *buf; | |
12 | ||
13 | @@ -4820,8 +4821,9 @@ int main(int argc, char * const argv[]) | |
14 | * contain one of several types of entry points, so read enough for | |
15 | * the largest one, then determine what type it contains. | |
16 | */ | |
17 | + size = 0x20; | |
18 | if (!(opt.flags & FLAG_NO_SYSFS) | |
19 | - && (buf = read_file(0x20, SYS_ENTRY_FILE)) != NULL) | |
20 | + && (buf = read_file(&size, SYS_ENTRY_FILE)) != NULL) | |
21 | { | |
22 | if (!(opt.flags & FLAG_QUIET)) | |
23 | printf("Getting SMBIOS data from sysfs.\n"); | |
24 | diff --git a/util.c b/util.c | |
25 | index f97ac0d..52ed413 100644 | |
26 | --- a/util.c | |
27 | +++ b/util.c | |
28 | @@ -94,10 +94,11 @@ int checksum(const u8 *buf, size_t len) | |
29 | * needs to be freed by the caller. | |
30 | * This provides a similar usage model to mem_chunk() | |
31 | * | |
32 | - * Returns pointer to buffer of max_len bytes, or NULL on error | |
33 | + * Returns pointer to buffer of max_len bytes, or NULL on error, and | |
34 | + * sets max_len to the length actually read. | |
35 | * | |
36 | */ | |
37 | -void *read_file(size_t max_len, const char *filename) | |
38 | +void *read_file(size_t *max_len, const char *filename) | |
39 | { | |
40 | int fd; | |
41 | size_t r2 = 0; | |
42 | @@ -115,7 +116,7 @@ void *read_file(size_t max_len, const char *filename) | |
43 | return(NULL); | |
44 | } | |
45 | ||
46 | - if ((p = malloc(max_len)) == NULL) | |
47 | + if ((p = malloc(*max_len)) == NULL) | |
48 | { | |
49 | perror("malloc"); | |
50 | return NULL; | |
51 | @@ -123,7 +124,7 @@ void *read_file(size_t max_len, const char *filename) | |
52 | ||
53 | do | |
54 | { | |
55 | - r = read(fd, p + r2, max_len - r2); | |
56 | + r = read(fd, p + r2, *max_len - r2); | |
57 | if (r == -1) | |
58 | { | |
59 | if (errno != EINTR) | |
60 | @@ -140,6 +141,8 @@ void *read_file(size_t max_len, const char *filename) | |
61 | while (r != 0); | |
62 | ||
63 | close(fd); | |
64 | + *max_len = r2; | |
65 | + | |
66 | return p; | |
67 | } | |
68 | ||
69 | diff --git a/util.h b/util.h | |
70 | index 9d409cd..b8748f1 100644 | |
71 | --- a/util.h | |
72 | +++ b/util.h | |
73 | @@ -25,7 +25,7 @@ | |
74 | #define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0])) | |
75 | ||
76 | int checksum(const u8 *buf, size_t len); | |
77 | -void *read_file(size_t len, const char *filename); | |
78 | +void *read_file(size_t *len, const char *filename); | |
79 | void *mem_chunk(off_t base, size_t len, const char *devmem); | |
80 | int write_dump(size_t base, size_t len, const void *data, const char *dumpfile, int add); | |
81 | u64 u64_range(u64 start, u64 end); | |
82 | -- | |
83 | 2.1.4 | |
84 |