提交 25d3fc7a 编写于 作者: J Ján Tomko

security: use g_strdup instead of VIR_STRDUP

Replace all occurrences of
  if (VIR_STRDUP(a, b) < 0)
     /* effectively dead code */
with:
  a = g_strdup(b);
Signed-off-by: NJán Tomko <jtomko@redhat.com>
Reviewed-by: NMichal Privoznik <mprivozn@redhat.com>
上级 45bf10ba
......@@ -452,12 +452,10 @@ AppArmorGenSecurityLabel(virSecurityManagerPtr mgr G_GNUC_UNUSED,
if ((profile_name = get_profile_name(def)) == NULL)
return rc;
if (VIR_STRDUP(secdef->label, profile_name) < 0)
goto cleanup;
secdef->label = g_strdup(profile_name);
/* set imagelabel the same as label (but we won't use it) */
if (VIR_STRDUP(secdef->imagelabel, profile_name) < 0)
goto err;
secdef->imagelabel = g_strdup(profile_name);
if (!secdef->model)
secdef->model = g_strdup(SECURITY_APPARMOR_NAME);
......
......@@ -111,8 +111,7 @@ virSecurityDACChownListAppend(virSecurityDACChownListPtr list,
if (VIR_ALLOC(item) < 0)
return -1;
if (VIR_STRDUP(tmp, path) < 0)
goto cleanup;
tmp = g_strdup(path);
item->path = tmp;
item->src = src;
......@@ -2311,11 +2310,8 @@ virSecurityDACGenLabel(virSecurityManagerPtr mgr,
return rc;
}
if (seclabel->relabel && !seclabel->imagelabel &&
VIR_STRDUP(seclabel->imagelabel, seclabel->label) < 0) {
VIR_FREE(seclabel->label);
return rc;
}
if (seclabel->relabel && !seclabel->imagelabel)
seclabel->imagelabel = g_strdup(seclabel->label);
return 0;
}
......
......@@ -130,8 +130,8 @@ virSecuritySELinuxContextListAppend(virSecuritySELinuxContextListPtr list,
if (VIR_ALLOC(item) < 0)
return -1;
if (VIR_STRDUP(item->path, path) < 0 || VIR_STRDUP(item->tcon, tcon) < 0)
goto cleanup;
item->path = g_strdup(path);
item->tcon = g_strdup(tcon);
item->remember = remember;
item->restore = restore;
......@@ -444,8 +444,7 @@ virSecuritySELinuxMCSGetProcessRange(char **sens,
if (!(contextRange = context_range_get(ourContext)))
contextRange = "s0";
if (VIR_STRDUP(*sens, contextRange) < 0)
goto cleanup;
*sens = g_strdup(contextRange);
/* Find and blank out the category part (if any) */
tmp = strchr(*sens, ':');
......@@ -622,8 +621,7 @@ virSecuritySELinuxGenNewContext(const char *basecontext,
_("Unable to format SELinux context"));
goto cleanup;
}
if (VIR_STRDUP(ret, str) < 0)
goto cleanup;
ret = g_strdup(str);
VIR_DEBUG("Generated context '%s'", ret);
cleanup:
freecon(ourSecContext);
......@@ -740,8 +738,7 @@ virSecuritySELinuxQEMUInitialize(virSecurityManagerPtr mgr)
*ptr = '\0';
ptr++;
if (*ptr != '\0') {
if (VIR_STRDUP(data->alt_domain_context, ptr) < 0)
goto error;
data->alt_domain_context = g_strdup(ptr);
ptr = strchrnul(data->alt_domain_context, '\n');
if (ptr && *ptr == '\n')
*ptr = '\0';
......@@ -761,8 +758,7 @@ virSecuritySELinuxQEMUInitialize(virSecurityManagerPtr mgr)
ptr = strchrnul(data->file_context, '\n');
if (ptr && *ptr == '\n') {
*ptr = '\0';
if (VIR_STRDUP(data->content_context, ptr + 1) < 0)
goto error;
data->content_context = g_strdup(ptr + 1);
ptr = strchrnul(data->content_context, '\n');
if (ptr && *ptr == '\n')
*ptr = '\0';
......@@ -868,8 +864,7 @@ virSecuritySELinuxGenLabel(virSecurityManagerPtr mgr,
virReportSystemError(errno, "%s", _("unable to get selinux context range"));
goto cleanup;
}
if (VIR_STRDUP(mcs, range) < 0)
goto cleanup;
mcs = g_strdup(range);
break;
case VIR_DOMAIN_SECLABEL_DYNAMIC:
......@@ -919,8 +914,7 @@ virSecuritySELinuxGenLabel(virSecurityManagerPtr mgr,
&catMax) < 0)
goto cleanup;
if (VIR_STRDUP(mcs, sens) < 0)
goto cleanup;
mcs = g_strdup(sens);
break;
......@@ -2214,8 +2208,7 @@ virSecuritySELinuxSetHostdevCapsLabel(virSecurityManagerPtr mgr,
dev->source.caps.u.storage.block) < 0)
return -1;
} else {
if (VIR_STRDUP(path, dev->source.caps.u.storage.block) < 0)
return -1;
path = g_strdup(dev->source.caps.u.storage.block);
}
ret = virSecuritySELinuxSetFilecon(mgr, path, secdef->imagelabel, true);
VIR_FREE(path);
......@@ -2228,8 +2221,7 @@ virSecuritySELinuxSetHostdevCapsLabel(virSecurityManagerPtr mgr,
dev->source.caps.u.misc.chardev) < 0)
return -1;
} else {
if (VIR_STRDUP(path, dev->source.caps.u.misc.chardev) < 0)
return -1;
path = g_strdup(dev->source.caps.u.misc.chardev);
}
ret = virSecuritySELinuxSetFilecon(mgr, path, secdef->imagelabel, true);
VIR_FREE(path);
......@@ -2449,8 +2441,7 @@ virSecuritySELinuxRestoreHostdevCapsLabel(virSecurityManagerPtr mgr,
dev->source.caps.u.storage.block) < 0)
return -1;
} else {
if (VIR_STRDUP(path, dev->source.caps.u.storage.block) < 0)
return -1;
path = g_strdup(dev->source.caps.u.storage.block);
}
ret = virSecuritySELinuxRestoreFileLabel(mgr, path, true);
VIR_FREE(path);
......@@ -2463,8 +2454,7 @@ virSecuritySELinuxRestoreHostdevCapsLabel(virSecurityManagerPtr mgr,
dev->source.caps.u.misc.chardev) < 0)
return -1;
} else {
if (VIR_STRDUP(path, dev->source.caps.u.misc.chardev) < 0)
return -1;
path = g_strdup(dev->source.caps.u.misc.chardev);
}
ret = virSecuritySELinuxRestoreFileLabel(mgr, path, true);
VIR_FREE(path);
......@@ -3335,8 +3325,7 @@ virSecuritySELinuxGenImageLabel(virSecurityManagerPtr mgr,
}
range = context_range_get(ctx);
if (range) {
if (VIR_STRDUP(mcs, range) < 0)
goto cleanup;
mcs = g_strdup(range);
if (!(label = virSecuritySELinuxGenNewContext(data->file_context,
mcs, true)))
goto cleanup;
......
......@@ -772,8 +772,7 @@ vah_add_path(virBufferPtr buf, const char *path, const char *perms, bool recursi
* 3. re-combine the realpath with the remaining suffix
* Note: A totally non existent path is used as-is
*/
if (VIR_STRDUP_QUIET(pathdir, path) < 0)
goto cleanup;
pathdir = g_strdup(path);
while (!virFileExists(pathdir)) {
if ((pathtmp = mdir_name(pathdir)) == NULL)
goto cleanup;
......@@ -783,11 +782,9 @@ vah_add_path(virBufferPtr buf, const char *path, const char *perms, bool recursi
if (strlen(pathdir) == 1) {
/* nothing of the path does exist yet */
if (VIR_STRDUP_QUIET(tmp, path) < 0)
goto cleanup;
tmp = g_strdup(path);
} else {
if (VIR_STRDUP_QUIET(pathtmp, path+strlen(pathdir)) < 0)
goto cleanup;
pathtmp = g_strdup(path + strlen(pathdir));
if ((pathreal = realpath(pathdir, NULL)) == NULL) {
vah_error(NULL, 0, pathdir);
vah_error(NULL, 0, _("could not find realpath"));
......@@ -797,8 +794,7 @@ vah_add_path(virBufferPtr buf, const char *path, const char *perms, bool recursi
goto cleanup;
}
if (VIR_STRDUP_QUIET(perms_new, perms) < 0)
goto cleanup;
perms_new = g_strdup(perms);
if (strchr(perms_new, 'w') != NULL) {
readonly = false;
......@@ -1367,8 +1363,7 @@ vahParseArgv(vahControl * ctl, int argc, char **argv)
break;
case 'f':
case 'F':
if (VIR_STRDUP_QUIET(ctl->newfile, optarg) < 0)
vah_error(ctl, 1, _("could not allocate memory for disk"));
ctl->newfile = g_strdup(optarg);
ctl->append = arg == 'F';
break;
case 'h':
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册