Remove newlines from config output

Spurious newlines output while writing the config file can
corrupt the wpa_supplicant configuration.  Avoid writing these.

Bug: 27371366
Change-Id: I3bb99b8c46dba1c81cbccc76ed0cd01abc3ccef9
diff --git a/wpa_supplicant/config.c b/wpa_supplicant/config.c
index 4d801cc..4051ae1 100644
--- a/wpa_supplicant/config.c
+++ b/wpa_supplicant/config.c
@@ -2602,8 +2602,16 @@
 
 	for (i = 0; i < NUM_SSID_FIELDS; i++) {
 		const struct parse_data *field = &ssid_fields[i];
-		if (os_strcmp(var, field->name) == 0)
-			return field->writer(field, ssid);
+		if (os_strcmp(var, field->name) == 0) {
+			char *ret = field->writer(field, ssid);
+			if (os_strchr(ret, '\r') != NULL || os_strchr(ret, '\n') != NULL) {
+				wpa_printf(MSG_ERROR, "Found newline in value for %s; "
+					"not returning it", var);
+				os_free(ret);
+				ret = NULL;
+			}
+			return ret;
+		}
 	}
 
 	return NULL;