MCPcopy Create free account
hub / github.com/F-Stack/f-stack / get_fp

Function get_fp

freebsd/security/mac_veriexec_parser/mac_veriexec_parser.c:141–217  ·  view source on GitHub ↗

* Parse a single line of manifest looking for a digest and its type. * We expect it to be in form of "path shaX=hash". * The line will be split into path, hash type and hash value. */

Source from the content-addressed store, hash-verified

139 * The line will be split into path, hash type and hash value.
140 */
141static int
142get_fp(const char *entry, char **type, unsigned char **digest, int *flags)
143{
144 char *delimiter;
145 char *local_digest;
146 char *fp_type;
147 char *prev_fp_type;
148 size_t min_len;
149 int i;
150
151 delimiter = NULL;
152 fp_type = NULL;
153 prev_fp_type = NULL;
154
155 for (i = 0; fp_table[i].fp_type != NULL; i++) {
156 fp_type = strstr(entry, fp_table[i].fp_type);
157 /* Look for the last "shaX=hash" in line */
158 while (fp_type != NULL) {
159 prev_fp_type = fp_type;
160 fp_type++;
161 fp_type = strstr(fp_type, fp_table[i].fp_type);
162 }
163 fp_type = prev_fp_type;
164 if (fp_type != NULL) {
165 if (fp_type == entry || fp_type[-1] != ' ')
166 return (EINVAL);
167
168 /*
169 * The entry should contain at least
170 * fp_type and digest in hexadecimal form.
171 */
172 min_len = strlen(fp_table[i].fp_type) +
173 2 * fp_table[i].fp_size;
174
175 if (strnlen(fp_type, min_len) < min_len)
176 return (EINVAL);
177
178 local_digest = &fp_type[strlen(fp_table[i].fp_type)];
179 delimiter = &local_digest[2 * fp_table[i].fp_size];
180
181 /*
182 * Make sure that digest is followed by
183 * some kind of delimiter.
184 */
185 if (*delimiter != '\n' &&
186 *delimiter != '\0' &&
187 *delimiter != ' ')
188 return (EINVAL);
189
190 /*
191 * Does the entry contain flags we need to parse?
192 */
193 if (*delimiter == ' ' && flags != NULL)
194 *flags = get_flags(delimiter);
195
196 /*
197 * Split entry into three parts:
198 * path, fp_type and digest.

Callers 1

parse_entryFunction · 0.85

Calls 3

strstrFunction · 0.85
strnlenFunction · 0.85
get_flagsFunction · 0.85

Tested by

no test coverage detected