Skip to content
This repository was archived by the owner on Jan 17, 2019. It is now read-only.

Commit 9033d35

Browse files
authored
Merge pull request #100 from bkokoszx/logger_kw
rmbox: fix rmbox KW issues
2 parents 9df6d36 + 7ad6c23 commit 9033d35

2 files changed

Lines changed: 28 additions & 3 deletions

File tree

rmbox/logger_convert.c

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424

2525
#define CEIL(a, b) ((a+b-1)/b)
2626

27+
#define TRACE_MAX_PARAMS_COUNT 4
28+
#define TRACE_MAX_TEXT_LEN 1024
29+
#define TRACE_MAX_FILENAME_LEN 128
30+
2731
/* logs file signature */
2832
#define SND_SOF_LOGS_SIG_SIZE 4
2933
#define SND_SOF_LOGS_SIG "Logs"
@@ -172,8 +176,13 @@ static int fetch_entry(struct convert_config *config, uint32_t base_address,
172176
ret = -ferror(config->ldc_fd);
173177
goto out;
174178
}
175-
179+
if (entry.header.file_name_len > TRACE_MAX_FILENAME_LEN) {
180+
fprintf(stderr, "Error: Invalid filename length. \n");
181+
ret = -EINVAL;
182+
goto out;
183+
}
176184
entry.file_name = (char *)malloc(entry.header.file_name_len);
185+
177186
if (!entry.file_name) {
178187
fprintf(stderr, "error: can't allocate %d byte for "
179188
"entry.file_name\n", entry.header.file_name_len);
@@ -200,23 +209,39 @@ static int fetch_entry(struct convert_config *config, uint32_t base_address,
200209
}
201210

202211
/* fetching text */
212+
if (entry.text_len > TRACE_MAX_TEXT_LEN) {
213+
fprintf(stderr, "Error: Invalid text length. \n");
214+
ret = -EINVAL;
215+
goto out;
216+
}
203217
entry.text = (char *)malloc(entry.text_len);
204218
if (entry.text == NULL) {
205219
fprintf(stderr, "error: can't allocate %d byte for "
206220
"entry.text\n", entry.text_len);
207221
ret = -ENOMEM;
208222
goto out;
209223
}
210-
211224
ret = fread(entry.text, sizeof(char), entry.text_len, config->ldc_fd);
212225
if (ret != entry.text_len) {
213226
ret = -ferror(config->ldc_fd);
214227
goto out;
215228
}
216229

217230
/* fetching entry params from dma dump */
231+
if (entry.header.params_num > TRACE_MAX_PARAMS_COUNT) {
232+
fprintf(stderr, "Error: Invalid number of parameters. \n");
233+
ret = -EINVAL;
234+
goto out;
235+
}
218236
entry.params = (uint32_t *)malloc(sizeof(uint32_t) *
219237
entry.header.params_num);
238+
if (entry.params == NULL) {
239+
fprintf(stderr, "error: can't allocate %d byte for "
240+
"entry.params\n", (int)(sizeof(uint32_t) *
241+
entry.header.params_num));
242+
ret = -ENOMEM;
243+
goto out;
244+
}
220245
ret = fread(entry.params, sizeof(uint32_t), entry.header.params_num,
221246
config->in_fd);
222247
if (ret != entry.header.params_num) {

rmbox/rmbox.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ int main(int argc, char *argv[])
214214

215215
out:
216216
/* close files */
217-
if (config.out_file)
217+
if (config.out_fd)
218218
fclose(config.out_fd);
219219

220220
if (config.in_fd)

0 commit comments

Comments
 (0)