about summary refs log tree commit diff
path: root/src/nm-core-utils.c
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2017-01-25 21:09:50 +0100
committerMichael Biebl <biebl@debian.org>2017-01-25 21:09:50 +0100
commit7f4dff3943c64e1d0e5d13b2ac915088dde165e6 (patch)
treeabfbc3a4102d3bba349b3e25265c2213ad636954 /src/nm-core-utils.c
parentd462f64d6044349b0a4e3581cf2c97bbab7aec97 (diff)
New upstream version 1.6.0 upstream/1.6.0
Diffstat (limited to 'src/nm-core-utils.c')
-rw-r--r--src/nm-core-utils.c65
1 files changed, 31 insertions, 34 deletions
diff --git a/src/nm-core-utils.c b/src/nm-core-utils.c
index 79f9e117..631540a1 100644
--- a/src/nm-core-utils.c
+++ b/src/nm-core-utils.c
@@ -1232,67 +1232,64 @@ typedef struct {
 } MatchDeviceData;
 
 static gboolean
-match_device_s390_subchannels_parse (const char *s390_subchannels, guint32 *a, guint32 *b, guint32 *c)
+match_device_s390_subchannels_parse (const char *s390_subchannels, guint32 *out_a, guint32 *out_b, guint32 *out_c)
 {
-	const int BUFSIZE = 10;
-	long unsigned int tmp;
+	const int BUFSIZE = 30;
 	char buf[BUFSIZE + 1];
-	const char *p = s390_subchannels;
-	int i = 0;
+	guint i = 0;
 	char *pa = NULL, *pb = NULL, *pc = NULL;
+	gint64 a, b, c;
 
 	nm_assert (s390_subchannels);
-	nm_assert (a != NULL);
-	nm_assert (*a == 0);
-	nm_assert (b != NULL);
-	nm_assert (*b == 0);
-	nm_assert (c != NULL);
-	nm_assert (*c == 0);
-
-	/* sanity check */
+	nm_assert (out_a);
+	nm_assert (out_b);
+	nm_assert (out_c);
+
 	if (!g_ascii_isxdigit (s390_subchannels[0]))
 		return FALSE;
 
 	/* Get the first channel */
-	while (*p && (*p != ',')) {
-		if (!g_ascii_isxdigit (*p) && (*p != '.'))
+	for (i = 0; s390_subchannels[i]; i++) {
+		char ch = s390_subchannels[i];
+
+		if (!g_ascii_isxdigit (ch) && ch != '.') {
+			if (ch == ',') {
+				/* FIXME: currently we consider the first channel and ignore
+				 * everything after the first ',' separator. Maybe we should
+				 * validate all present channels? */
+				break;
+			}
 			return FALSE;  /* Invalid chars */
+		}
 		if (i >= BUFSIZE)
 			return FALSE;  /* Too long to be a subchannel */
-		buf[i++] = *p++;
+		buf[i] = ch;
 	}
 	buf[i] = '\0';
 
 	/* and grab each of its elements, there should be 3 */
 	pa = &buf[0];
-	pb = strchr (buf, '.');
+	pb = strchr (pa, '.');
 	if (pb)
 		pc = strchr (pb + 1, '.');
-	if (!pa || !pb || !pc)
+	if (!pb || !pc)
 		return FALSE;
-
-	/* Split the string */
 	*pb++ = '\0';
 	*pc++ = '\0';
 
-	errno = 0;
-	tmp = strtoul (pa, NULL, 16);
-	if (errno)
+	a = _nm_utils_ascii_str_to_int64 (pa, 16, 0, G_MAXUINT32, -1);
+	if (a == -1)
 		return FALSE;
-	*a = (guint32) tmp;
-
-	errno = 0;
-	tmp = strtoul (pb, NULL, 16);
-	if (errno)
+	b = _nm_utils_ascii_str_to_int64 (pb, 16, 0, G_MAXUINT32, -1);
+	if (b == -1)
 		return FALSE;
-	*b = (guint32) tmp;
-
-	errno = 0;
-	tmp = strtoul (pc, NULL, 16);
-	if (errno)
+	c = _nm_utils_ascii_str_to_int64 (pc, 16, 0, G_MAXUINT32, -1);
+	if (c == -1)
 		return FALSE;
-	*c = (guint32) tmp;
 
+	*out_a = (guint32) a;
+	*out_b = (guint32) b;
+	*out_c = (guint32) c;
 	return TRUE;
 }