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