diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c index e9ee1a7bf4..1ec42c1d93 100644 --- a/src/openvz/openvz_conf.c +++ b/src/openvz/openvz_conf.c @@ -245,7 +245,9 @@ openvzReadNetworkConf(virDomainDefPtr def, /*parse string*/ do { - char *next = strchrnul(p, ','); + char *next = strchr(p, ','); + if (!next) + next = strchr(p, '\0'); if (STRPREFIX(p, "ifname=")) { /* skip in libvirt */ } else if (STRPREFIX(p, "host_ifname=")) { diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c index ce46df09da..3f6968a57a 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -721,14 +721,14 @@ virSecuritySELinuxQEMUInitialize(virSecurityManagerPtr mgr) goto error; } - ptr = strchrnul(data->domain_context, '\n'); - if (ptr && *ptr == '\n') { + ptr = strchr(data->domain_context, '\n'); + if (ptr) { *ptr = '\0'; ptr++; if (*ptr != '\0') { data->alt_domain_context = g_strdup(ptr); - ptr = strchrnul(data->alt_domain_context, '\n'); - if (ptr && *ptr == '\n') + ptr = strchr(data->alt_domain_context, '\n'); + if (ptr) *ptr = '\0'; } } @@ -743,12 +743,12 @@ virSecuritySELinuxQEMUInitialize(virSecurityManagerPtr mgr) goto error; } - ptr = strchrnul(data->file_context, '\n'); - if (ptr && *ptr == '\n') { + ptr = strchr(data->file_context, '\n'); + if (ptr) { *ptr = '\0'; data->content_context = g_strdup(ptr + 1); - ptr = strchrnul(data->content_context, '\n'); - if (ptr && *ptr == '\n') + ptr = strchr(data->content_context, '\n'); + if (ptr) *ptr = '\0'; } diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index dff2f6fd3a..526ce9da03 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -174,9 +174,13 @@ virCgroupPartitionNeedsEscaping(const char *path) if (STRPREFIX(line, "#subsys_name")) continue; - tmp = strchrnul(line, ' '); - *tmp = '\0'; - len = tmp - line; + tmp = strchr(line, ' '); + if (tmp) { + *tmp = '\0'; + len = tmp - line; + } else { + len = strlen(line); + } if (STRPREFIX(path, line) && path[len] == '.') { diff --git a/src/util/virdnsmasq.c b/src/util/virdnsmasq.c index 2555f3110f..adc6f96bb6 100644 --- a/src/util/virdnsmasq.c +++ b/src/util/virdnsmasq.c @@ -640,6 +640,7 @@ dnsmasqCapsSet(dnsmasqCapsPtr caps, static int dnsmasqCapsSetFromBuffer(dnsmasqCapsPtr caps, const char *buf) { + int len; const char *p; caps->noRefresh = true; @@ -675,10 +676,14 @@ dnsmasqCapsSetFromBuffer(dnsmasqCapsPtr caps, const char *buf) return 0; fail: - p = strchrnul(buf, '\n'); + p = strchr(buf, '\n'); + if (!p) + len = strlen(buf); + else + len = p - buf; virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot parse %s version number in '%.*s'"), - caps->binaryPath, (int) (p - buf), buf); + caps->binaryPath, len, buf); return -1; } diff --git a/src/util/virsysinfo.c b/src/util/virsysinfo.c index c526c0322f..4cc4523be0 100644 --- a/src/util/virsysinfo.c +++ b/src/util/virsysinfo.c @@ -460,18 +460,20 @@ virSysinfoReadARM(void) return g_steal_pointer(&ret); } -static char * +static const char * virSysinfoParseS390Delimited(const char *base, const char *name, char **value, char delim1, char delim2) { const char *start; - char *end; + const char *end; if (delim1 != delim2 && (start = strstr(base, name)) && (start = strchr(start, delim1))) { start += 1; - end = strchrnul(start, delim2); + end = strchr(start, delim2); + if (!end) + end = start + strlen(start); virSkipSpaces(&start); *value = g_strndup(start, end - start); virTrimSpaces(*value, NULL); @@ -480,7 +482,7 @@ virSysinfoParseS390Delimited(const char *base, const char *name, char **value, return NULL; } -static char * +static const char * virSysinfoParseS390Line(const char *base, const char *name, char **value) { return virSysinfoParseS390Delimited(base, name, value, ':', '\n'); @@ -521,7 +523,7 @@ virSysinfoParseS390System(const char *base, virSysinfoSystemDefPtr *sysdef) static int virSysinfoParseS390Processor(const char *base, virSysinfoDefPtr ret) { - char *tmp_base; + const char *tmp_base; char *manufacturer = NULL; char *procline = NULL; char *ncpu = NULL; @@ -555,7 +557,7 @@ virSysinfoParseS390Processor(const char *base, virSysinfoDefPtr ret) } /* now, for each processor found, extract the frequency information */ - tmp_base = (char *) base; + tmp_base = base; while ((tmp_base = strstr(tmp_base, "cpu number")) && (tmp_base = virSysinfoParseS390Line(tmp_base, "cpu number", &ncpu))) { diff --git a/tests/testutils.c b/tests/testutils.c index b490609e36..248f9ee8be 100644 --- a/tests/testutils.c +++ b/tests/testutils.c @@ -1200,7 +1200,7 @@ virTestCounterReset(const char *prefix) virtTestCounter = 0; ignore_value(virStrcpyStatic(virtTestCounterStr, prefix)); - virtTestCounterPrefixEndOffset = strchrnul(virtTestCounterStr, '\0'); + virtTestCounterPrefixEndOffset = virtTestCounterStr + strlen(virtTestCounterStr); }