comparison libcommon/hexread.c @ 141:a1aa8ee2da85

read_hex_data_file(): add maxlen argument
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 24 Feb 2021 17:25:28 +0000
parents 94d87d05f6c5
children
comparison
equal deleted inserted replaced
140:13ab44761ea6 141:a1aa8ee2da85
8 #include <stdio.h> 8 #include <stdio.h>
9 #include <stdlib.h> 9 #include <stdlib.h>
10 10
11 extern FILE *open_script_input_file(); 11 extern FILE *open_script_input_file();
12 12
13 read_hex_data_file(filename, databuf) 13 read_hex_data_file(filename, databuf, maxlen)
14 char *filename; 14 char *filename;
15 u_char *databuf; 15 u_char *databuf;
16 unsigned maxlen;
16 { 17 {
17 FILE *inf; 18 FILE *inf;
18 unsigned count; 19 unsigned count;
19 int c, c2; 20 int c, c2;
20 21
36 return(-1); 37 return(-1);
37 } 38 }
38 c2 = getc(inf); 39 c2 = getc(inf);
39 if (!isxdigit(c2)) 40 if (!isxdigit(c2))
40 goto inv_input; 41 goto inv_input;
41 if (count >= 255) { 42 if (count >= maxlen) {
42 fprintf(stderr, "%s: hex input data is too long\n", 43 fprintf(stderr, "%s: hex input data is too long\n",
43 filename); 44 filename);
44 fclose(inf); 45 fclose(inf);
45 return(-1); 46 return(-1);
46 } 47 }