Remove newlines from wpa_supplicant config network output

Spurious newlines output while writing the config file can corrupt the
wpa_supplicant configuration. Avoid writing these for the network block
parameters. This is a generic filter that cover cases that may not have
been explicitly addressed with a more specific commit to avoid control
characters in the psk parameter.

Signed-off-by: Paul Stewart <pstew@google.com>
This commit is contained in:
Paul Stewart 2016-03-03 15:40:19 -08:00 committed by Jouni Malinen
parent 5594df44c7
commit 0fe5a23424
3 changed files with 25 additions and 2 deletions

View File

@ -709,6 +709,17 @@ int has_ctrl_char(const u8 *data, size_t len)
}
int has_newline(const char *str)
{
while (*str) {
if (*str == '\n' || *str == '\r')
return 1;
str++;
}
return 0;
}
size_t merge_byte_arrays(u8 *res, size_t res_len,
const u8 *src1, size_t src1_len,
const u8 *src2, size_t src2_len)

View File

@ -489,6 +489,7 @@ const char * wpa_ssid_txt(const u8 *ssid, size_t ssid_len);
char * wpa_config_parse_string(const char *value, size_t *len);
int is_hex(const u8 *data, size_t len);
int has_ctrl_char(const u8 *data, size_t len);
int has_newline(const char *str);
size_t merge_byte_arrays(u8 *res, size_t res_len,
const u8 *src1, size_t src1_len,
const u8 *src2, size_t src2_len);

View File

@ -2699,8 +2699,19 @@ char * wpa_config_get(struct wpa_ssid *ssid, const char *var)
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 (ret && has_newline(ret)) {
wpa_printf(MSG_ERROR,
"Found newline in value for %s; not returning it",
var);
os_free(ret);
ret = NULL;
}
return ret;
}
}
return NULL;