Fix some minor bugs
Phil Sutter
reviewercover Fix some minor bugs
All these were identified by Covscan.
Phil Sutter (4):
conntrack: Fix potential array out of bounds access
conntrack: Fix for unused assignment in do_command_ct()
conntrack: Fix for unused assignment in ct_save_snprintf()
conntrack: Sanitize free_tmpl_objects()
src/conntrack.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
Signature · 1 line
2.38.0
Phil Sutter
reviewerPATCH 1/4 conntrack: Fix potential array out of bounds access
If the link target length exceeds 'sizeof(tmp)' bytes, readlink() will return 'sizeof(tmp)'. Using this value as index is illegal.
--- src/conntrack.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
src/conntrack.c +1 -1
@@ -1769,7 +1769,7 @@ static char *portid2name(pid_t pid, uint32_t portid, unsigned long inode)continue ; rl =readlink (procname, tmp,sizeof (tmp)); -if (rl <=0 || rl > (ssize_t )sizeof (tmp)) +if (rl <=0 || rl >= (ssize_t )sizeof (tmp))continue ; tmp[rl] =0 ;
Signature · 1 line
2.38.0
Phil Sutter
reviewerPATCH 2/4 conntrack: Fix for unused assignment in do_command_ct()
In reply to Phil SutterThe variable is overwritten immediately in the next iteration and the loop can't exit before doing that.
Instead of dropping the assignment, one could add a return code check - but since event_cb() never fails, that check is pointless as well.
--- src/conntrack.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
src/conntrack.c +1 -1
@@ -3479,7 +3479,7 @@ static int do_command_ct(const char *progname, struct ct_cmd *cmd, strerror(errno));break ; } - res =mnl_cb_run (buf, res,0 ,0 , event_cb, cmd); +mnl_cb_run (buf, res,0 ,0 , event_cb, cmd); }mnl_socket_close (event_sock->mnl);break ;
Signature · 1 line
2.38.0
Phil Sutter
reviewerPATCH 3/4 conntrack: Fix for unused assignment in ct_save_snprintf()
In reply to Phil SutterSetting 'ret' without calling BUFFER_SIZE() is pointless.
--- src/conntrack.c | 1 - 1 file changed, 1 deletion(-)
src/conntrack.c +0 -1
@@ -761,7 +761,6 @@ static int ct_save_snprintf(char *buf, size_t len,BUFFER_SIZE (ret, size, len, offset);break ;default : - ret =0 ;break ; }
Signature · 1 line
2.38.0
Phil Sutter
reviewerPATCH 4/4 conntrack: Sanitize free_tmpl_objects()
In reply to Phil SutterThe function unconditionally dereferenced its parameter, yet it is possible for the passed 'cur_tmpl' pointer when called from exit_error() to be still NULL: It is assigned to by alloc_tmpl_objects() at start of do_parse(), though callers of that function might call exit_error() in beforehand.
--- src/conntrack.c | 2 ++ 1 file changed, 2 insertions(+)
src/conntrack.c +2 -0
@@ -139,6 +139,8 @@ static int alloc_tmpl_objects(struct ct_tmpl *tmpl)static void free_tmpl_objects (struct ct_tmpl *tmpl) { +if (!tmpl) +return ;if (tmpl->ct)nfct_destroy (tmpl->ct);if (tmpl->exptuple)
Signature · 1 line
2.38.0
Pablo Neira Ayuso
maintainerQuoted 1 line · Phil Sutter
All these were identified by Covscan.
Series LGTM.
Phil Sutter
reviewerQuoted 4 lines · Pablo Neira Ayuso
Quoted 1 line · Phil Sutter
All these were identified by Covscan.
Series LGTM.
Series applied, thanks for the review!