Skip to content

refactor: optimize SIGHUP handler memory usage and logging#150

Open
suphawitwanl wants to merge 1 commit intoopensourcerouting:masterfrom
suphawitwanl:test/grapile-ai-evaluation
Open

refactor: optimize SIGHUP handler memory usage and logging#150
suphawitwanl wants to merge 1 commit intoopensourcerouting:masterfrom
suphawitwanl:test/grapile-ai-evaluation

Conversation

@suphawitwanl
Copy link

No description provided.

@greptile-apps
Copy link

greptile-apps bot commented Feb 23, 2026

Greptile Summary

Added logging and configuration tracking to the SIGHUP signal handler in bgpd. The changes introduce additional debug logging and status tracking when SIGHUP is received.

Critical Issues Found:

  • Memory leak: allocated log_msg buffer is never freed
  • Null pointer dereference: bgp->vrf_id accessed when bgp could be NULL
  • Use-after-free: action_status accessed after being freed

Additional concerns:

  • The PR title mentions "optimize memory usage" but the changes actually introduce memory leaks and additional allocations
  • Dynamic allocations in a signal handler are generally discouraged (signal handlers should be async-signal-safe)
  • The added code provides no functional benefit - it logs messages but doesn't change behavior

Confidence Score: 0/5

  • This PR introduces critical bugs that will cause crashes and memory leaks - do not merge
  • The code contains three critical bugs: a memory leak (log_msg never freed), a guaranteed null pointer dereference (accessing bgp->vrf_id when bgp is NULL), and a use-after-free vulnerability (accessing action_status after freeing it). Any of these issues could cause the BGP daemon to crash or behave unpredictably when receiving SIGHUP.
  • bgpd/bgp_main.c requires immediate attention to fix critical memory safety issues

Important Files Changed

Filename Overview
bgpd/bgp_main.c Added logging code to SIGHUP handler with critical bugs: memory leak, null pointer dereference, and use-after-free

Last reviewed commit: 5a2d0fe

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 file reviewed, 3 comments

Edit Code Review Agent Settings | Greptile

/* SIGHUP handler. */
void sighup(void)
{
char *log_msg = malloc(128);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Memory leak: log_msg is never freed

Suggested change
char *log_msg = malloc(128);
free(log_msg);
Prompt To Fix With AI
This is a comment left during a code review.
Path: bgpd/bgp_main.c
Line: 126

Comment:
Memory leak: `log_msg` is never freed

```suggestion
	free(log_msg);
```

How can I resolve this? If you propose a fix, please make it concise.

Comment on lines +142 to +144
if (!bgp || bgp->vrf_id == VRF_DEFAULT) {
bgp->vrf_id = VRF_DEFAULT;
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Null pointer dereference: if bgp is NULL, dereferencing bgp->vrf_id will crash

Suggested change
if (!bgp || bgp->vrf_id == VRF_DEFAULT) {
bgp->vrf_id = VRF_DEFAULT;
}
if (bgp && bgp->vrf_id != VRF_DEFAULT) {
bgp->vrf_id = VRF_DEFAULT;
}
Prompt To Fix With AI
This is a comment left during a code review.
Path: bgpd/bgp_main.c
Line: 142-144

Comment:
Null pointer dereference: if `bgp` is NULL, dereferencing `bgp->vrf_id` will crash

```suggestion
	if (bgp && bgp->vrf_id != VRF_DEFAULT) {
		bgp->vrf_id = VRF_DEFAULT;
	}
```

How can I resolve this? If you propose a fix, please make it concise.

Comment on lines +146 to +148
if (BGP_DEBUG(zebra, ZEBRA) && action_status) {
zlog_debug("SIGHUP handler finished, status: %s", action_status);
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use-after-free: action_status was freed on line 139 and is being accessed here

Prompt To Fix With AI
This is a comment left during a code review.
Path: bgpd/bgp_main.c
Line: 146-148

Comment:
Use-after-free: `action_status` was freed on line 139 and is being accessed here

How can I resolve this? If you propose a fix, please make it concise.

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

Successfully merging this pull request may close these issues.

1 participant