ipvsadm: Fix svc->pe_name conditional
PATCH 1/1 ipvsadm: Fix svc->pe_name conditional
The pe_name in ipvs_service_t is an array, so comparing it NULL has no effect. Use strlen to see if pe_name is set.
--- libipvs/libipvs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
libipvs/libipvs.c +1 -1
@@ -229,7 +229,7 @@ static int ipvs_nl_fill_service_attr(struct nl_msg *msg, ipvs_service_t *svc) }NLA_PUT_STRING (msg,IPVS_SVC_ATTR_SCHED_NAME , svc->sched_name); -if (svc->pe_name) +if (strlen (svc->pe_name))NLA_PUT_STRING (msg,IPVS_SVC_ATTR_PE_NAME , svc->pe_name);NLA_PUT (msg,IPVS_SVC_ATTR_FLAGS ,sizeof (flags), &flags);NLA_PUT_U32 (msg,IPVS_SVC_ATTR_TIMEOUT , svc->timeout);
Signature · 1 line
1.8.1.4
Hello,
Quoted 4 lines · Ryan O'Hara
The
pe_nameinipvs_service_tis an array, so comparing it NULL has no effect. Use strlen to see ifpe_nameis set.Signed-off-by Ryan O'Hara <[email protected]>
Looks good to me.
Or may be we can avoid strlen? Eg. svc->pe_name[0] ? It looks like CHECK_PE has similar problem and more:
- Do we really work without NL support if CHECK_PE always succeeds in 'if (s->pe_name)'? I have a doubt.
- CHECK_PE and CHECK_IPV4 as part of CHECK_COMPAT_SVC use 'return' and we can leak svc in ipvs_get_service()
- in ipvs_get_service() CHECK_PE does not need to be called, it is already part of CHECK_COMPAT_SVC
- ipvs_get_service uses malloc but later calls CHECK_PE, may be malloc should be changed with calloc
Quoted 19 lines
--- libipvs/libipvs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)libipvs/libipvs.c +1
-1@@ -229,7 +229,7 @@ static int ipvs_nl_fill_service_attr(struct nl_msg *msg, ipvs_service_t *svc) }NLA_PUT_STRING (msg,IPVS_SVC_ATTR_SCHED_NAME , svc->sched_name); -if (svc->pe_name) +if (strlen (svc->pe_name))NLA_PUT_STRING (msg,IPVS_SVC_ATTR_PE_NAME , svc->pe_name);NLA_PUT (msg,IPVS_SVC_ATTR_FLAGS ,sizeof (flags), &flags);NLA_PUT_U32 (msg,IPVS_SVC_ATTR_TIMEOUT , svc->timeout);Signature · 1 line
1.8.1.4
Regards
--
Julian Anastasov <[email protected]>
Quoted 8 lines · Julian Anastasov
Hello,
Quoted 3 lines · Ryan O'Hara
The
pe_nameinipvs_service_tis an array, so comparing it NULL has no effect. Use strlen to see ifpe_nameis set.
Quoted 7 lines
Quoted 1 line
Signed-off-by Ryan O'Hara <[email protected]>Looks good to me.
Acked-by Julian Anastasov <[email protected]>Or may be we can avoid strlen? Eg. svc->pe_name[0] ?
Agree. I'll resend the patch without strlen.
Quoted 4 lines
It looks like
CHECK_PEhas similar problem and more:- Do we really work without NL support if
CHECK_PEalways succeeds in 'if (s->pe_name)'? I have a doubt.
Not sure about this. I've always been under the impression that NL is absolutely required.
Quoted 5 lines
-
CHECK_PEandCHECK_IPV4as part ofCHECK_COMPAT_SVCuse 'return' and we can leak svc inipvs_get_service()- in
ipvs_get_service()CHECK_PEdoes not need to be called, it is already part ofCHECK_COMPAT_SVC
Yes. I'm tempted to remove these macros due to the 'return' issue. Thoughts?
Quoted 2 lines
-
ipvs_get_serviceuses malloc but later callsCHECK_PE, may be malloc should be changed with calloc
Aside from the fact that CHECK_PE could return without freeing memory, I don't see the problem here.
Ryan
Quoted 24 lines
Quoted 19 lines
--- libipvs/libipvs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)libipvs/libipvs.c +1
-1@@ -229,7 +229,7 @@ static int ipvs_nl_fill_service_attr(struct nl_msg *msg, ipvs_service_t *svc) }NLA_PUT_STRING (msg,IPVS_SVC_ATTR_SCHED_NAME , svc->sched_name); -if (svc->pe_name) +if (strlen (svc->pe_name))NLA_PUT_STRING (msg,IPVS_SVC_ATTR_PE_NAME , svc->pe_name);NLA_PUT (msg,IPVS_SVC_ATTR_FLAGS ,sizeof (flags), &flags);NLA_PUT_U32 (msg,IPVS_SVC_ATTR_TIMEOUT , svc->timeout);Signature · 1 line
1.8.1.4Regards
--
Julian Anastasov <[email protected]>
Julian Anastasov
maintainerHello,
Quoted 10 lines · Ryan O'Hara
Quoted 5 lines · Julian Anastasov
-
CHECK_PEandCHECK_IPV4as part ofCHECK_COMPAT_SVCuse 'return' and we can leak svc inipvs_get_service()- in
ipvs_get_service()CHECK_PEdoes not need to be called, it is already part ofCHECK_COMPAT_SVCYes. I'm tempted to remove these macros due to the 'return' issue. Thoughts?
May be they can use 'goto' instead of 'return':
if (condition) {
errno = XXX;
goto out_err;
}
and funcs can have such exit point:out_err:
free stuff on error return ret;
Quoted 5 lines
Quoted 2 lines
-
ipvs_get_serviceuses malloc but later callsCHECK_PE, may be malloc should be changed with callocAside from the fact that
CHECK_PEcould return without freeing memory, I don't see the problem here.
malloc does not initialize the memory and checking of
svc->pe_name[0] in CHECK_PE would give random results.
Regards
--
Julian Anastasov <[email protected]>
Quoted 25 lines · Julian Anastasov
Hello,
Quoted 10 lines · Ryan O'Hara
Quoted 5 lines · Julian Anastasov
-
CHECK_PEandCHECK_IPV4as part ofCHECK_COMPAT_SVCuse 'return' and we can leak svc inipvs_get_service()- in
ipvs_get_service()CHECK_PEdoes not need to be called, it is already part ofCHECK_COMPAT_SVCYes. I'm tempted to remove these macros due to the 'return' issue. Thoughts?
May be they can use 'goto' instead of 'return': if (condition) { errno = XXX; goto out_err; } and funcs can have such exit point:
Quoted 3 lines
out_err:free stuff on error return ret;
OK. It looks like ipvs_get_service() is the only function with a potential leak. The other functions that call any of the CHECK_* macros will just get an 'out_err: return -1'.
I also noticed that CHECK_COMPAT_DEST can be removed. This macro simply calls CHECK_IPV4, which is also called by CHECK_COMPAT_SVC. I noticed that CHECK_COMPAT_DEST is only called after CHECK_COMPAT_SVC, so this macro can be removed entirely. Agree?
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
-
ipvs_get_serviceuses malloc but later callsCHECK_PE, may be malloc should be changed with callocAside from the fact that
CHECK_PEcould return without freeing memory, I don't see the problem here.malloc does not initialize the memory and checking of
svc->pe_name[0] inCHECK_PEwould give random results.
I see. Thanks.
Ryan
Simon Horman
maintainerQuoted 30 lines · Ryan O'Hara
Quoted 25 lines · Julian Anastasov
Hello,
Quoted 10 lines · Ryan O'Hara
Quoted 5 lines · Julian Anastasov
-
CHECK_PEandCHECK_IPV4as part ofCHECK_COMPAT_SVCuse 'return' and we can leak svc inipvs_get_service()- in
ipvs_get_service()CHECK_PEdoes not need to be called, it is already part ofCHECK_COMPAT_SVCYes. I'm tempted to remove these macros due to the 'return' issue. Thoughts?
May be they can use 'goto' instead of 'return': if (condition) { errno = XXX; goto out_err; } and funcs can have such exit point:Quoted 3 lines
out_err:free stuff on error return ret;
Quoted 8 lines
OK. It looks like
ipvs_get_service()is the only function with a potential leak. The other functions that call any of the CHECK_* macros will just get an 'out_err: return -1'.I also noticed that
CHECK_COMPAT_DESTcan be removed. This macro simply callsCHECK_IPV4, which is also called byCHECK_COMPAT_SVC. I noticed thatCHECK_COMPAT_DESTis only called afterCHECK_COMPAT_SVC, so this macro can be removed entirely. Agree?
That sounds reasonable to me.
Quoted 14 lines
Quoted 9 lines
Quoted 6 lines
Quoted 3 lines
-
ipvs_get_serviceuses malloc but later callsCHECK_PE, may be malloc should be changed with callocAside from the fact that
CHECK_PEcould return without freeing memory, I don't see the problem here.malloc does not initialize the memory and checking of
svc->pe_name[0] inCHECK_PEwould give random results.I see. Thanks.
Ryan
Julian Anastasov
maintainerHello,
Quoted 11 lines · Ryan O'Hara
Quoted 10 lines · Julian Anastasov
May be they can use 'goto' instead of 'return': if (condition) { errno = XXX; goto out_err; } and funcs can have such exit point:
Quoted 7 lines
Quoted 3 lines
out_err:free stuff on error return ret;OK. It looks like
ipvs_get_service()is the only function with a potential leak. The other functions that call any of the CHECK_* macros will just get an 'out_err: return -1'.
Yes
Quoted 4 lines
I also noticed that
CHECK_COMPAT_DESTcan be removed. This macro simply callsCHECK_IPV4, which is also called byCHECK_COMPAT_SVC. I noticed thatCHECK_COMPAT_DESTis only called afterCHECK_COMPAT_SVC, so this macro can be removed entirely. Agree?
No. It looks like the macros work with more
than one structure: svc and dest. Same was for CHECK_PE where both structs were supported: ipvs_service_entry_t and ipvs_service_t when CHECK_PE was called from CHECK_COMPAT_SVC.
CHECK_COMPAT_SVC does not check the dest->af,
it checks svc->af. Without both checks, svc can come with address from AF_INET family while -r option has address from AF_INET6 family. IMHO, we need just the return->goto change.
Regards
--
Julian Anastasov <[email protected]>
Quoted 36 lines · Julian Anastasov
Hello,
Quoted 11 lines · Ryan O'Hara
Quoted 10 lines · Julian Anastasov
May be they can use 'goto' instead of 'return': if (condition) { errno = XXX; goto out_err; } and funcs can have such exit point:Quoted 7 lines
Quoted 3 lines
out_err:free stuff on error return ret;OK. It looks like
ipvs_get_service()is the only function with a potential leak. The other functions that call any of the CHECK_* macros will just get an 'out_err: return -1'.Yes
Quoted 4 lines
I also noticed that
CHECK_COMPAT_DESTcan be removed. This macro simply callsCHECK_IPV4, which is also called byCHECK_COMPAT_SVC. I noticed thatCHECK_COMPAT_DESTis only called afterCHECK_COMPAT_SVC, so this macro can be removed entirely. Agree?No. It looks like the macros work with more
than one structure: svc and dest. Same was forCHECK_PEwhere both structs were supported:ipvs_service_entry_tandipvs_service_twhenCHECK_PEwas called fromCHECK_COMPAT_SVC.
Quoted 5 lines
CHECK_COMPAT_SVC does not check the dest->af,it checks
svc->af. Without both checks, svc can come with address fromAF_INETfamily while -r option has address fromAF_INET6family. IMHO, we need just thereturn->gotochange.
You're right. Not sure how I missed that.
Ryan