提交 16251193 编写于 作者: M Michal Privoznik

Adapt to VIR_STRDUP and VIR_STRNDUP in src/rpc/*

上级 d2846c25
...@@ -626,12 +626,10 @@ elsif ($mode eq "server") { ...@@ -626,12 +626,10 @@ elsif ($mode eq "server") {
# SPECIAL: virConnectGetType returns a constant string that must # SPECIAL: virConnectGetType returns a constant string that must
# not be freed. Therefore, duplicate the string here. # not be freed. Therefore, duplicate the string here.
push(@vars_list, "const char *$1"); push(@vars_list, "const char *$1");
push(@ret_list, "/* We have to strdup because remoteDispatchClientRequest will"); push(@ret_list, "/* We have to VIR_STRDUP because remoteDispatchClientRequest will");
push(@ret_list, " * free this string after it's been serialised. */"); push(@ret_list, " * free this string after it's been serialised. */");
push(@ret_list, "if (!(ret->type = strdup(type))) {"); push(@ret_list, "if (VIR_STRDUP(ret->type, type) < 0)");
push(@ret_list, " virReportOOMError();");
push(@ret_list, " goto cleanup;"); push(@ret_list, " goto cleanup;");
push(@ret_list, "}");
} else { } else {
push(@vars_list, "char *$1"); push(@vars_list, "char *$1");
push(@ret_list, "ret->$1 = $1;"); push(@ret_list, "ret->$1 = $1;");
...@@ -652,11 +650,8 @@ elsif ($mode eq "server") { ...@@ -652,11 +650,8 @@ elsif ($mode eq "server") {
" goto cleanup;\n" . " goto cleanup;\n" .
" }\n" . " }\n" .
" \n" . " \n" .
" *$1_p = strdup($1);\n" . " if (VIR_STRDUP(*$1_p, $1) < 0)\n".
" if (*$1_p == NULL) {\n" . " goto cleanup;\n");
" virReportOOMError();\n" .
" goto cleanup;\n" .
" }\n");
$single_ret_var = $1; $single_ret_var = $1;
$single_ret_by_ref = 0; $single_ret_by_ref = 0;
...@@ -1578,16 +1573,14 @@ elsif ($mode eq "client") { ...@@ -1578,16 +1573,14 @@ elsif ($mode eq "client") {
print "\n"; print "\n";
print " /* This call is caller-frees (although that isn't clear from\n"; print " /* This call is caller-frees (although that isn't clear from\n";
print " * the documentation). However xdr_free will free up both the\n"; print " * the documentation). However xdr_free will free up both the\n";
print " * names and the list of pointers, so we have to strdup the\n"; print " * names and the list of pointers, so we have to VIR_STRDUP the\n";
print " * names here. */\n"; print " * names here. */\n";
print " for (i = 0; i < ret.$single_ret_list_name.${single_ret_list_name}_len; ++i) {\n"; print " for (i = 0; i < ret.$single_ret_list_name.${single_ret_list_name}_len; ++i) {\n";
print " ${single_ret_list_name}[i] = strdup(ret.$single_ret_list_name.${single_ret_list_name}_val[i]);\n"; print " if (VIR_STRDUP(${single_ret_list_name}[i],\n";
print "\n"; print " ret.$single_ret_list_name.${single_ret_list_name}_val[i]) < 0) {\n";
print " if (${single_ret_list_name}[i] == NULL) {\n";
print " for (--i; i >= 0; --i)\n"; print " for (--i; i >= 0; --i)\n";
print " VIR_FREE(${single_ret_list_name}[i]);\n"; print " VIR_FREE(${single_ret_list_name}[i]);\n";
print "\n"; print "\n";
print " virReportOOMError();\n";
print " goto cleanup;\n"; print " goto cleanup;\n";
print " }\n"; print " }\n";
print " }\n"; print " }\n";
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include "virlog.h" #include "virlog.h"
#include "virutil.h" #include "virutil.h"
#include "virerror.h" #include "virerror.h"
#include "virstring.h"
#define VIR_FROM_THIS VIR_FROM_RPC #define VIR_FROM_THIS VIR_FROM_RPC
...@@ -317,17 +318,14 @@ static virNetClientPtr virNetClientNew(virNetSocketPtr sock, ...@@ -317,17 +318,14 @@ static virNetClientPtr virNetClientNew(virNetSocketPtr sock,
client->wakeupSendFD = wakeupFD[1]; client->wakeupSendFD = wakeupFD[1];
wakeupFD[0] = wakeupFD[1] = -1; wakeupFD[0] = wakeupFD[1] = -1;
if (hostname && if (VIR_STRDUP(client->hostname, hostname) < 0)
!(client->hostname = strdup(hostname))) goto error;
goto no_memory;
PROBE(RPC_CLIENT_NEW, PROBE(RPC_CLIENT_NEW,
"client=%p sock=%p", "client=%p sock=%p",
client, client->sock); client, client->sock);
return client; return client;
no_memory:
virReportOOMError();
error: error:
VIR_FORCE_CLOSE(wakeupFD[0]); VIR_FORCE_CLOSE(wakeupFD[0]);
VIR_FORCE_CLOSE(wakeupFD[1]); VIR_FORCE_CLOSE(wakeupFD[1]);
...@@ -414,8 +412,8 @@ virNetClientPtr virNetClientNewLibSSH2(const char *host, ...@@ -414,8 +412,8 @@ virNetClientPtr virNetClientNewLibSSH2(const char *host,
goto no_memory; goto no_memory;
} }
} else { } else {
if (!(knownhosts = strdup(knownHostsPath))) if (VIR_STRDUP(knownhosts, knownHostsPath) < 0)
goto no_memory; goto cleanup;
} }
} }
...@@ -438,8 +436,8 @@ virNetClientPtr virNetClientNewLibSSH2(const char *host, ...@@ -438,8 +436,8 @@ virNetClientPtr virNetClientNewLibSSH2(const char *host,
VIR_FREE(privkey); VIR_FREE(privkey);
} }
} else { } else {
if (!(privkey = strdup(privkeyPath))) if (VIR_STRDUP(privkey, privkeyPath) < 0)
goto no_memory; goto cleanup;
} }
} }
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include "virlog.h" #include "virlog.h"
#include "virfile.h" #include "virfile.h"
#include "virutil.h" #include "virutil.h"
#include "virstring.h"
#define VIR_FROM_THIS VIR_FROM_RPC #define VIR_FROM_THIS VIR_FROM_RPC
...@@ -514,22 +515,28 @@ void virNetMessageSaveError(virNetMessageErrorPtr rerr) ...@@ -514,22 +515,28 @@ void virNetMessageSaveError(virNetMessageErrorPtr rerr)
if (verr) { if (verr) {
rerr->code = verr->code; rerr->code = verr->code;
rerr->domain = verr->domain; rerr->domain = verr->domain;
if (verr->message && VIR_ALLOC(rerr->message) == 0) if (verr->message && VIR_ALLOC(rerr->message) == 0 &&
*rerr->message = strdup(verr->message); VIR_STRDUP_QUIET(*rerr->message, verr->message) < 0)
VIR_FREE(rerr->message);
rerr->level = verr->level; rerr->level = verr->level;
if (verr->str1 && VIR_ALLOC(rerr->str1) == 0) if (verr->str1 && VIR_ALLOC(rerr->str1) == 0 &&
*rerr->str1 = strdup(verr->str1); VIR_STRDUP_QUIET(*rerr->str1, verr->str1) < 0)
if (verr->str2 && VIR_ALLOC(rerr->str2) == 0) VIR_FREE(verr->str1);
*rerr->str2 = strdup(verr->str2); if (verr->str2 && VIR_ALLOC(rerr->str2) == 0 &&
if (verr->str3 && VIR_ALLOC(rerr->str3) == 0) VIR_STRDUP_QUIET(*rerr->str2, verr->str2) < 0)
*rerr->str3 = strdup(verr->str3); VIR_FREE(verr->str2);
if (verr->str3 && VIR_ALLOC(rerr->str3) == 0 &&
VIR_STRDUP_QUIET(*rerr->str3, verr->str3) < 0)
VIR_FREE(verr->str2);
rerr->int1 = verr->int1; rerr->int1 = verr->int1;
rerr->int2 = verr->int2; rerr->int2 = verr->int2;
} else { } else {
rerr->code = VIR_ERR_INTERNAL_ERROR; rerr->code = VIR_ERR_INTERNAL_ERROR;
rerr->domain = VIR_FROM_RPC; rerr->domain = VIR_FROM_RPC;
if (VIR_ALLOC(rerr->message) == 0) if (VIR_ALLOC(rerr->message) == 0 &&
*rerr->message = strdup(_("Library function returned error but did not set virError")); VIR_STRDUP_QUIET(*rerr->message,
_("Library function returned error but did not set virError")) < 0)
VIR_FREE(rerr->message);
rerr->level = VIR_ERR_ERROR; rerr->level = VIR_ERR_ERROR;
} }
} }
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include "viralloc.h" #include "viralloc.h"
#include "virthread.h" #include "virthread.h"
#include "virlog.h" #include "virlog.h"
#include "virstring.h"
#define VIR_FROM_THIS VIR_FROM_RPC #define VIR_FROM_THIS VIR_FROM_RPC
...@@ -385,10 +386,7 @@ char *virNetSASLSessionListMechanisms(virNetSASLSessionPtr sasl) ...@@ -385,10 +386,7 @@ char *virNetSASLSessionListMechanisms(virNetSASLSessionPtr sasl)
err, sasl_errdetail(sasl->conn)); err, sasl_errdetail(sasl->conn));
goto cleanup; goto cleanup;
} }
if (!(ret = strdup(mechlist))) { ignore_value(VIR_STRDUP(ret, mechlist));
virReportOOMError();
goto cleanup;
}
cleanup: cleanup:
virObjectUnlock(sasl); virObjectUnlock(sasl);
......
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include "virfile.h" #include "virfile.h"
#include "virnetservermdns.h" #include "virnetservermdns.h"
#include "virdbus.h" #include "virdbus.h"
#include "virstring.h"
#ifndef SA_SIGINFO #ifndef SA_SIGINFO
# define SA_SIGINFO 0 # define SA_SIGINFO 0
...@@ -387,11 +388,8 @@ virNetServerPtr virNetServerNew(size_t min_workers, ...@@ -387,11 +388,8 @@ virNetServerPtr virNetServerNew(size_t min_workers,
srv->privileged = geteuid() == 0; srv->privileged = geteuid() == 0;
srv->autoShutdownInhibitFd = -1; srv->autoShutdownInhibitFd = -1;
if (mdnsGroupName && if (VIR_STRDUP(srv->mdnsGroupName, mdnsGroupName) < 0)
!(srv->mdnsGroupName = strdup(mdnsGroupName))) {
virReportOOMError();
goto error; goto error;
}
if (srv->mdnsGroupName) { if (srv->mdnsGroupName) {
if (!(srv->mdns = virNetServerMDNSNew())) if (!(srv->mdns = virNetServerMDNSNew()))
goto error; goto error;
......
...@@ -693,22 +693,16 @@ virNetServerClientCreateIdentity(virNetServerClientPtr client) ...@@ -693,22 +693,16 @@ virNetServerClientCreateIdentity(virNetServerClientPtr client)
#if WITH_SASL #if WITH_SASL
if (client->sasl) { if (client->sasl) {
const char *identity = virNetSASLSessionGetIdentity(client->sasl); const char *identity = virNetSASLSessionGetIdentity(client->sasl);
if (identity && if (VIR_STRDUP(saslname, identity) < 0)
!(saslname = strdup(identity))) {
virReportOOMError();
goto cleanup; goto cleanup;
}
} }
#endif #endif
#if WITH_GNUTLS #if WITH_GNUTLS
if (client->tls) { if (client->tls) {
const char *identity = virNetTLSSessionGetX509DName(client->tls); const char *identity = virNetTLSSessionGetX509DName(client->tls);
if (identity && if (VIR_STRDUP(x509dname, identity) < 0)
!(x509dname = strdup(identity))) {
virReportOOMError();
goto cleanup; goto cleanup;
}
} }
#endif #endif
......
...@@ -479,9 +479,8 @@ virNetServerMDNSGroupPtr virNetServerMDNSAddGroup(virNetServerMDNS *mdns, ...@@ -479,9 +479,8 @@ virNetServerMDNSGroupPtr virNetServerMDNSAddGroup(virNetServerMDNS *mdns,
return NULL; return NULL;
} }
if (!(group->name = strdup(name))) { if (VIR_STRDUP(group->name, name) < 0) {
VIR_FREE(group); VIR_FREE(group);
virReportOOMError();
return NULL; return NULL;
} }
group->mdns = mdns; group->mdns = mdns;
...@@ -525,9 +524,8 @@ virNetServerMDNSEntryPtr virNetServerMDNSAddEntry(virNetServerMDNSGroupPtr group ...@@ -525,9 +524,8 @@ virNetServerMDNSEntryPtr virNetServerMDNSAddEntry(virNetServerMDNSGroupPtr group
} }
entry->port = port; entry->port = port;
if (!(entry->type = strdup(type))) { if (VIR_STRDUP(entry->type, type) < 0) {
VIR_FREE(entry); VIR_FREE(entry);
virReportOOMError();
return NULL; return NULL;
} }
entry->next = group->entry; entry->next = group->entry;
......
...@@ -800,10 +800,10 @@ virNetSocketNewConnectLibSSH2(const char *host, ...@@ -800,10 +800,10 @@ virNetSocketNewConnectLibSSH2(const char *host,
if (virNetSSHSessionSetChannelCommand(sess, command) != 0) if (virNetSSHSessionSetChannelCommand(sess, command) != 0)
goto error; goto error;
if (!(authMethodNext = authMethodsCopy = strdup(authMethods))) { if (VIR_STRDUP(authMethodsCopy, authMethods) < 0)
virReportOOMError();
goto error; goto error;
}
authMethodNext = authMethodsCopy;
while ((authMethod = strsep(&authMethodNext, ","))) { while ((authMethod = strsep(&authMethodNext, ","))) {
if (STRCASEEQ(authMethod, "keyboard-interactive")) if (STRCASEEQ(authMethod, "keyboard-interactive"))
...@@ -1191,10 +1191,8 @@ int virNetSocketGetSELinuxContext(virNetSocketPtr sock, ...@@ -1191,10 +1191,8 @@ int virNetSocketGetSELinuxContext(virNetSocketPtr sock,
goto cleanup; goto cleanup;
} }
if (!(*context = strdup(seccon))) { if (VIR_STRDUP(*context, seccon) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
ret = 0; ret = 0;
cleanup: cleanup:
......
...@@ -234,10 +234,12 @@ virNetSSHKbIntCb(const char *name ATTRIBUTE_UNUSED, ...@@ -234,10 +234,12 @@ virNetSSHKbIntCb(const char *name ATTRIBUTE_UNUSED,
/* fill data structures for auth callback */ /* fill data structures for auth callback */
for (i = 0; i < num_prompts; i++) { for (i = 0; i < num_prompts; i++) {
if (!(askcred[i].prompt = strdup(prompts[i].text))) { char *prompt;
if (VIR_STRDUP(prompt, prompts[i].text) < 0) {
priv->authCbErr = VIR_NET_SSH_AUTHCB_OOM; priv->authCbErr = VIR_NET_SSH_AUTHCB_OOM;
goto cleanup; goto cleanup;
} }
askcred[i].prompt = prompt;
/* remove colon and trailing spaces from prompts, as default behavior /* remove colon and trailing spaces from prompts, as default behavior
* of libvirt's auth callback is to add them */ * of libvirt's auth callback is to add them */
...@@ -739,7 +741,7 @@ virNetSSHAuthenticateKeyboardInteractive(virNetSSHSessionPtr sess, ...@@ -739,7 +741,7 @@ virNetSSHAuthenticateKeyboardInteractive(virNetSSHSessionPtr sess,
"authentication credentials")); "authentication credentials"));
return -1; return -1;
case VIR_NET_SSH_AUTHCB_OOM: case VIR_NET_SSH_AUTHCB_OOM:
virReportOOMError(); /* OOM error already reported */
return -1; return -1;
case VIR_NET_SSH_AUTHCB_RETR_ERR: case VIR_NET_SSH_AUTHCB_RETR_ERR:
virReportError(VIR_ERR_SSH, "%s", virReportError(VIR_ERR_SSH, "%s",
...@@ -960,12 +962,14 @@ virNetSSHSessionAuthAddPasswordAuth(virNetSSHSessionPtr sess, ...@@ -960,12 +962,14 @@ virNetSSHSessionAuthAddPasswordAuth(virNetSSHSessionPtr sess,
virObjectLock(sess); virObjectLock(sess);
if (!(user = strdup(username)) || if (VIR_STRDUP(user, username) < 0 ||
!(pass = strdup(password))) VIR_STRDUP(pass, password) < 0)
goto no_memory; goto error;
if (!(auth = virNetSSHSessionAuthMethodNew(sess))) if (!(auth = virNetSSHSessionAuthMethodNew(sess))) {
goto no_memory; virReportOOMError();
goto error;
}
auth->username = user; auth->username = user;
auth->password = pass; auth->password = pass;
...@@ -974,10 +978,9 @@ virNetSSHSessionAuthAddPasswordAuth(virNetSSHSessionPtr sess, ...@@ -974,10 +978,9 @@ virNetSSHSessionAuthAddPasswordAuth(virNetSSHSessionPtr sess,
virObjectUnlock(sess); virObjectUnlock(sess);
return 0; return 0;
no_memory: error:
VIR_FREE(user); VIR_FREE(user);
VIR_FREE(pass); VIR_FREE(pass);
virReportOOMError();
virObjectUnlock(sess); virObjectUnlock(sess);
return -1; return -1;
} }
...@@ -998,11 +1001,13 @@ virNetSSHSessionAuthAddAgentAuth(virNetSSHSessionPtr sess, ...@@ -998,11 +1001,13 @@ virNetSSHSessionAuthAddAgentAuth(virNetSSHSessionPtr sess,
virObjectLock(sess); virObjectLock(sess);
if (!(user = strdup(username))) if (VIR_STRDUP(user, username) < 0)
goto no_memory; goto error;
if (!(auth = virNetSSHSessionAuthMethodNew(sess))) if (!(auth = virNetSSHSessionAuthMethodNew(sess))) {
goto no_memory; virReportOOMError();
goto error;
}
auth->username = user; auth->username = user;
auth->method = VIR_NET_SSH_AUTH_AGENT; auth->method = VIR_NET_SSH_AUTH_AGENT;
...@@ -1010,9 +1015,8 @@ virNetSSHSessionAuthAddAgentAuth(virNetSSHSessionPtr sess, ...@@ -1010,9 +1015,8 @@ virNetSSHSessionAuthAddAgentAuth(virNetSSHSessionPtr sess,
virObjectUnlock(sess); virObjectUnlock(sess);
return 0; return 0;
no_memory: error:
VIR_FREE(user); VIR_FREE(user);
virReportOOMError();
virObjectUnlock(sess); virObjectUnlock(sess);
return -1; return -1;
} }
...@@ -1038,15 +1042,15 @@ virNetSSHSessionAuthAddPrivKeyAuth(virNetSSHSessionPtr sess, ...@@ -1038,15 +1042,15 @@ virNetSSHSessionAuthAddPrivKeyAuth(virNetSSHSessionPtr sess,
virObjectLock(sess); virObjectLock(sess);
if (!(user = strdup(username)) || if (VIR_STRDUP(user, username) < 0 ||
!(file = strdup(keyfile))) VIR_STRDUP(file, keyfile) < 0 ||
goto no_memory; VIR_STRDUP(pass, password) < 0)
goto error;
if (password && !(pass = strdup(password)))
goto no_memory;
if (!(auth = virNetSSHSessionAuthMethodNew(sess))) if (!(auth = virNetSSHSessionAuthMethodNew(sess))) {
goto no_memory; virReportOOMError();
goto error;
}
auth->username = user; auth->username = user;
auth->password = pass; auth->password = pass;
...@@ -1056,11 +1060,10 @@ virNetSSHSessionAuthAddPrivKeyAuth(virNetSSHSessionPtr sess, ...@@ -1056,11 +1060,10 @@ virNetSSHSessionAuthAddPrivKeyAuth(virNetSSHSessionPtr sess,
virObjectUnlock(sess); virObjectUnlock(sess);
return 0; return 0;
no_memory: error:
VIR_FREE(user); VIR_FREE(user);
VIR_FREE(pass); VIR_FREE(pass);
VIR_FREE(file); VIR_FREE(file);
virReportOOMError();
virObjectUnlock(sess); virObjectUnlock(sess);
return -1; return -1;
} }
...@@ -1082,11 +1085,13 @@ virNetSSHSessionAuthAddKeyboardAuth(virNetSSHSessionPtr sess, ...@@ -1082,11 +1085,13 @@ virNetSSHSessionAuthAddKeyboardAuth(virNetSSHSessionPtr sess,
virObjectLock(sess); virObjectLock(sess);
if (!(user = strdup(username))) if (VIR_STRDUP(user, username) < 0)
goto no_memory; goto error;
if (!(auth = virNetSSHSessionAuthMethodNew(sess))) if (!(auth = virNetSSHSessionAuthMethodNew(sess))) {
goto no_memory; virReportOOMError();
goto error;
}
auth->username = user; auth->username = user;
auth->tries = tries; auth->tries = tries;
...@@ -1095,9 +1100,8 @@ virNetSSHSessionAuthAddKeyboardAuth(virNetSSHSessionPtr sess, ...@@ -1095,9 +1100,8 @@ virNetSSHSessionAuthAddKeyboardAuth(virNetSSHSessionPtr sess,
virObjectUnlock(sess); virObjectUnlock(sess);
return 0; return 0;
no_memory: error:
VIR_FREE(user); VIR_FREE(user);
virReportOOMError();
virObjectUnlock(sess); virObjectUnlock(sess);
return -1; return -1;
...@@ -1112,10 +1116,8 @@ virNetSSHSessionSetChannelCommand(virNetSSHSessionPtr sess, ...@@ -1112,10 +1116,8 @@ virNetSSHSessionSetChannelCommand(virNetSSHSessionPtr sess,
VIR_FREE(sess->channelCommand); VIR_FREE(sess->channelCommand);
if (command && !(sess->channelCommand = strdup(command))) { if (VIR_STRDUP(sess->channelCommand, command) < 0)
virReportOOMError();
ret = -1; ret = -1;
}
virObjectUnlock(sess); virObjectUnlock(sess);
return ret; return ret;
...@@ -1138,8 +1140,8 @@ virNetSSHSessionSetHostKeyVerification(virNetSSHSessionPtr sess, ...@@ -1138,8 +1140,8 @@ virNetSSHSessionSetHostKeyVerification(virNetSSHSessionPtr sess,
VIR_FREE(sess->hostname); VIR_FREE(sess->hostname);
if (hostname && !(sess->hostname = strdup(hostname))) if (VIR_STRDUP(sess->hostname, hostname) < 0)
goto no_memory; goto error;
/* load the known hosts file */ /* load the known hosts file */
if (hostsfile) { if (hostsfile) {
...@@ -1163,16 +1165,14 @@ virNetSSHSessionSetHostKeyVerification(virNetSSHSessionPtr sess, ...@@ -1163,16 +1165,14 @@ virNetSSHSessionSetHostKeyVerification(virNetSSHSessionPtr sess,
/* set filename only if writing to the known hosts file is requested */ /* set filename only if writing to the known hosts file is requested */
if (!(flags & VIR_NET_SSH_HOSTKEY_FILE_READONLY)) { if (!(flags & VIR_NET_SSH_HOSTKEY_FILE_READONLY)) {
VIR_FREE(sess->knownHostsFile); VIR_FREE(sess->knownHostsFile);
if (!(sess->knownHostsFile = strdup(hostsfile))) if (VIR_STRDUP(sess->knownHostsFile, hostsfile) < 0)
goto no_memory; goto error;
} }
} }
virObjectUnlock(sess); virObjectUnlock(sess);
return 0; return 0;
no_memory:
virReportOOMError();
error: error:
virObjectUnlock(sess); virObjectUnlock(sess);
return -1; return -1;
......
...@@ -837,23 +837,23 @@ static int virNetTLSContextLocateCredentials(const char *pkipath, ...@@ -837,23 +837,23 @@ static int virNetTLSContextLocateCredentials(const char *pkipath,
*/ */
if (!*cacert) { if (!*cacert) {
VIR_DEBUG("Using default TLS CA certificate path"); VIR_DEBUG("Using default TLS CA certificate path");
if (!(*cacert = strdup(LIBVIRT_CACERT))) if (VIR_STRDUP(*cacert, LIBVIRT_CACERT) < 0)
goto out_of_memory; goto error;
} }
if (!*cacrl) { if (!*cacrl) {
VIR_DEBUG("Using default TLS CA revocation list path"); VIR_DEBUG("Using default TLS CA revocation list path");
if (!(*cacrl = strdup(LIBVIRT_CACRL))) if (VIR_STRDUP(*cacrl, LIBVIRT_CACRL) < 0)
goto out_of_memory; goto error;
} }
if (!*key && !*cert) { if (!*key && !*cert) {
VIR_DEBUG("Using default TLS key/certificate path"); VIR_DEBUG("Using default TLS key/certificate path");
if (!(*key = strdup(isServer ? LIBVIRT_SERVERKEY : LIBVIRT_CLIENTKEY))) if (VIR_STRDUP(*key, isServer ? LIBVIRT_SERVERKEY : LIBVIRT_CLIENTKEY) < 0)
goto out_of_memory; goto error;
if (!(*cert = strdup(isServer ? LIBVIRT_SERVERCERT : LIBVIRT_CLIENTCERT))) if (VIR_STRDUP(*cert, isServer ? LIBVIRT_SERVERCERT : LIBVIRT_CLIENTCERT) < 0)
goto out_of_memory; goto error;
} }
VIR_FREE(user_pki_path); VIR_FREE(user_pki_path);
...@@ -863,6 +863,7 @@ static int virNetTLSContextLocateCredentials(const char *pkipath, ...@@ -863,6 +863,7 @@ static int virNetTLSContextLocateCredentials(const char *pkipath,
out_of_memory: out_of_memory:
virReportOOMError(); virReportOOMError();
error:
VIR_FREE(*cacert); VIR_FREE(*cacert);
VIR_FREE(*cacrl); VIR_FREE(*cacrl);
VIR_FREE(*key); VIR_FREE(*key);
...@@ -1029,10 +1030,8 @@ static int virNetTLSContextValidCertificate(virNetTLSContextPtr ctxt, ...@@ -1029,10 +1030,8 @@ static int virNetTLSContextValidCertificate(virNetTLSContextPtr ctxt,
"[session]", gnutls_strerror(ret)); "[session]", gnutls_strerror(ret));
goto authfail; goto authfail;
} }
if (!(sess->x509dname = strdup(dname))) { if (VIR_STRDUP(sess->x509dname, dname) < 0)
virReportOOMError();
goto authfail; goto authfail;
}
VIR_DEBUG("Peer DN is %s", dname); VIR_DEBUG("Peer DN is %s", dname);
if (virNetTLSContextCheckCertDN(cert, "[session]", sess->hostname, dname, if (virNetTLSContextCheckCertDN(cert, "[session]", sess->hostname, dname,
...@@ -1169,11 +1168,8 @@ virNetTLSSessionPtr virNetTLSSessionNew(virNetTLSContextPtr ctxt, ...@@ -1169,11 +1168,8 @@ virNetTLSSessionPtr virNetTLSSessionNew(virNetTLSContextPtr ctxt,
if (!(sess = virObjectLockableNew(virNetTLSSessionClass))) if (!(sess = virObjectLockableNew(virNetTLSSessionClass)))
return NULL; return NULL;
if (hostname && if (VIR_STRDUP(sess->hostname, hostname) < 0)
!(sess->hostname = strdup(hostname))) {
virReportOOMError();
goto error; goto error;
}
if ((err = gnutls_init(&sess->session, if ((err = gnutls_init(&sess->session,
ctxt->isServer ? GNUTLS_SERVER : GNUTLS_CLIENT)) != 0) { ctxt->isServer ? GNUTLS_SERVER : GNUTLS_CLIENT)) != 0) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册