Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

memory leak when using fy_node_by_path with flag FYNWF_PTR_YPATH #136

Open
rivit98 opened this issue Jan 20, 2025 · 0 comments
Open

memory leak when using fy_node_by_path with flag FYNWF_PTR_YPATH #136

rivit98 opened this issue Jan 20, 2025 · 0 comments

Comments

@rivit98
Copy link

rivit98 commented Jan 20, 2025

Hi, I found the following problem while fuzzing libfyaml

Code version

6e52e4d8b6adb01cc2fc377fab7b7fd523364438

How to reproduce

#include <stdio.h>
#include <libfyaml.h>

  struct fy_document *fyd = NULL;

  int flags = FYNWF_PTR_YPATH;

  fyd = fy_document_create(NULL);
  struct fy_node *fyn = fy_node_create_sequence(fyd);
  assert(fyn);
  fy_document_set_root(fyd, fyn);
  struct fy_node *root = fy_document_root(fyd);
  assert(root);

  char data[] = "\x37\x40\x00";
  struct fy_node *node = fy_node_by_path(root, data, FY_NT, flags);
  printf("node: %p\n", node);
  fy_document_destroy(fyd);
}

compile & link with fuzzer support. Run and observe ASAN output:

==2300344==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 48 byte(s) in 1 object(s) allocated from:
    #0 0x59f19a2f4313 in malloc (/home/rivit/workspace/fuzzing/libfyaml/build/nofuzz+0x1ad313) (BuildId: 3ecbadf8c8d7ba7a43db64ce0d9a229f5c2bc772)
    #1 0x59f19a504098 in fy_walk_result_alloc_rl /home/rivit/workspace/fuzzing/libfyaml/src/lib/fy-walk.c:143:9

Indirect leak of 56 byte(s) in 1 object(s) allocated from:
    #0 0x59f19a2f4313 in malloc (/home/rivit/workspace/fuzzing/libfyaml/build/nofuzz+0x1ad313) (BuildId: 3ecbadf8c8d7ba7a43db64ce0d9a229f5c2bc772)
    #1 0x59f19a537253 in fy_path_exec_create /home/rivit/workspace/fuzzing/libfyaml/src/lib/fy-walk.c:3774:9

SUMMARY: AddressSanitizer: 104 byte(s) leaked in 2 allocation(s).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant