- Timestamp:
- 02/23/09 00:23:45 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/reglookup-recover.c
r148 r149 252 252 */ 253 253 /* XXX: This is not terribly efficient, as it may reparse many keys 254 * repeatedly. Should try to add caching. Also, piecing the path 255 * together is slow and redundant. 254 * repeatedly. Should try to add caching. 256 255 */ 257 256 char* getParentPath(REGFI_FILE* f, REGFI_NK_REC* nk) … … 261 260 REGFI_NK_REC* cur_ancestor; 262 261 char* ret_val; 263 char* path_element; 264 char* tmp_str; 265 uint32 virt_offset, i, stack_size, ret_val_size, ret_val_left, element_size; 262 uint32 virt_offset, i, stack_size, ret_val_size, ret_val_used; 266 263 uint32 max_length; 267 264 /* A little hack so we don't have to walk a quoted string twice. */ 265 struct name_holder 266 { 267 char* quoted_name; 268 uint32_t length; 269 }; 270 struct name_holder* path_element; 271 272 268 273 /* The path_stack size limit should guarantee that we don't recurse forever. */ 269 274 virt_offset = nk->parent_off; 275 ret_val_size = 1; /* NUL */ 270 276 while(virt_offset != REGFI_OFFSET_NONE) 271 277 { … … 291 297 virt_offset = cur_ancestor->parent_off; 292 298 293 path_element = quote_string(cur_ancestor->keyname, key_special_chars); 294 if(path_element == NULL || !void_stack_push(path_stack, path_element)) 299 path_element = (struct name_holder*)malloc(sizeof(struct name_holder)); 300 if(path_element != NULL) 301 path_element->quoted_name = quote_string(cur_ancestor->keyname, 302 key_special_chars); 303 304 if(path_element == NULL || path_element->quoted_name == NULL 305 || !void_stack_push(path_stack, path_element)) 295 306 { 296 307 free(cur_ancestor->keyname); … … 300 311 } 301 312 313 /* Path element and preceeding delimiter 314 * Note that this integer can't overflow since key name lengths are 315 * 16 bits and the max depth is 512. 316 */ 317 path_element->length = strlen(path_element->quoted_name); 318 ret_val_size += path_element->length + 1; 319 302 320 regfi_key_free(cur_ancestor); 303 321 } … … 306 324 307 325 stack_size = void_stack_size(path_stack); 308 ret_val_size = 16*stack_size; 309 if(ret_val_size == 0) 310 ret_val_size = 1; 311 ret_val_left = ret_val_size; 326 ret_val_used = 0; 312 327 ret_val = malloc(ret_val_size); 313 328 if(ret_val == NULL) … … 321 336 { 322 337 path_element = void_stack_pop(path_stack); 323 element_size = strlen(path_element); 324 if(ret_val_left < element_size+2) 325 { 326 ret_val_size += element_size+16; 327 ret_val_left += element_size+16; 328 tmp_str = (char*)realloc(ret_val, ret_val_size); 329 if(tmp_str == NULL) 330 { 331 free(ret_val); 332 void_stack_free_deep(path_stack); 333 return NULL; 334 } 335 ret_val = tmp_str; 336 } 337 338 ret_val_left -= snprintf(ret_val+ret_val_size-ret_val_left,ret_val_left, "/%s", path_element); 338 snprintf(ret_val+ret_val_used, ret_val_size-ret_val_used, 339 "/%s", path_element->quoted_name); 340 ret_val_used += path_element->length + 1; 341 free(path_element->quoted_name); 339 342 free(path_element); 340 343 }
Note: See TracChangeset
for help on using the changeset viewer.