Fix double-free and broken logic in virt-login-shell

The virLoginShellAllowedUser method must not free the 'groups'
parameter it is given, as that is owned by the caller.

The virLoginShellAllowedUser method should be checking
'!*ptr' (ie empty string) rather than '!ptr' (NULL string)
since the latter cannot be true.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrange 2013-08-09 11:59:55 +01:00
parent f905cc9984
commit ac692e3af2

View File

@ -85,7 +85,7 @@ static int virLoginShellAllowedUser(virConfPtr conf,
*/ */
if (pp->str[0] == '%') { if (pp->str[0] == '%') {
ptr = &pp->str[1]; ptr = &pp->str[1];
if (!ptr) if (!*ptr)
continue; continue;
for (i = 0; groups[i]; i++) { for (i = 0; groups[i]; i++) {
if (!(gname = virGetGroupName(groups[i]))) if (!(gname = virGetGroupName(groups[i])))
@ -96,7 +96,6 @@ static int virLoginShellAllowedUser(virConfPtr conf,
} }
VIR_FREE(gname); VIR_FREE(gname);
} }
VIR_FREE(groups);
continue; continue;
} }
if (fnmatch(pp->str, name, 0) == 0) { if (fnmatch(pp->str, name, 0) == 0) {
@ -109,7 +108,6 @@ static int virLoginShellAllowedUser(virConfPtr conf,
virReportSystemError(EPERM, _("%s not listed as an allowed_users in %s"), name, conf_file); virReportSystemError(EPERM, _("%s not listed as an allowed_users in %s"), name, conf_file);
cleanup: cleanup:
VIR_FREE(gname); VIR_FREE(gname);
VIR_FREE(groups);
return ret; return ret;
} }