]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
P2P: Filter control chars in group client device name similarly to peer
authorHu Wang <huw@qti.qualcomm.com>
Mon, 26 Oct 2015 21:40:59 +0000 (23:40 +0200)
committerJouni Malinen <j@w1.fi>
Mon, 26 Oct 2015 21:43:45 +0000 (23:43 +0200)
P2P device discovery can add peer entries based on a message directly
from a peer and from a Probe Response frame from a GO for all the P2P
Clients in the group. The former case for filtering out control
characters from the device name while the latter was not. Make this
consistent and filter both cases in the same way to avoid confusing
external programs using the device name of a P2P peer.

Signed-off-by: Jouni Malinen <jouni@qca.qualcomm.com>
src/p2p/p2p.c
src/p2p/p2p_i.h
src/p2p/p2p_parse.c

index 3e26011a02ee8e703bea1d83179018da11a67b3f..d90116910c1362a8992207e3f362f3cfec84aab2 100644 (file)
@@ -445,8 +445,9 @@ static struct p2p_device * p2p_create_device(struct p2p_data *p2p,
 static void p2p_copy_client_info(struct p2p_device *dev,
                                 struct p2p_client_info *cli)
 {
-       os_memcpy(dev->info.device_name, cli->dev_name, cli->dev_name_len);
-       dev->info.device_name[cli->dev_name_len] = '\0';
+       p2p_copy_filter_devname(dev->info.device_name,
+                               sizeof(dev->info.device_name),
+                               cli->dev_name, cli->dev_name_len);
        dev->info.dev_capab = cli->dev_capab;
        dev->info.config_methods = cli->config_methods;
        os_memcpy(dev->info.pri_dev_type, cli->pri_dev_type, 8);
index 0ce4058fe3e697b7fc87f27bd352fcde6be8f20e..7f65aceedbffafbc84388c316dbcc4c7a353ce7c 100644 (file)
@@ -691,6 +691,8 @@ int p2p_channel_random_social(struct p2p_channels *chans, u8 *op_class,
                              u8 *op_channel);
 
 /* p2p_parse.c */
+void p2p_copy_filter_devname(char *dst, size_t dst_len,
+                            const void *src, size_t src_len);
 int p2p_parse_p2p_ie(const struct wpabuf *buf, struct p2p_message *msg);
 int p2p_parse_ies(const u8 *data, size_t len, struct p2p_message *msg);
 int p2p_parse(const u8 *data, size_t len, struct p2p_message *msg);
index 9e16fc62fe75cc4bfaa148d7ba21e536868438c0..5d2299cb25c2e6420a2d18c690cd0c1f543d24bc 100644 (file)
 #include "p2p_i.h"
 
 
+void p2p_copy_filter_devname(char *dst, size_t dst_len,
+                            const void *src, size_t src_len)
+{
+       size_t i;
+
+       if (src_len >= dst_len)
+               src_len = dst_len - 1;
+       os_memcpy(dst, src, src_len);
+       dst[src_len] = '\0';
+       for (i = 0; i < src_len; i++) {
+               if (dst[i] == '\0')
+                       break;
+               if (is_ctrl_char(dst[i]))
+                       dst[i] = '_';
+       }
+}
+
+
 static int p2p_parse_attribute(u8 id, const u8 *data, u16 len,
                               struct p2p_message *msg)
 {
        const u8 *pos;
-       size_t i;
        u16 nlen;
        char devtype[WPS_DEV_TYPE_BUFSIZE];
 
@@ -156,14 +173,8 @@ static int p2p_parse_attribute(u8 id, const u8 *data, u16 len,
                                   (int) (data + len - pos));
                        return -1;
                }
-               os_memcpy(msg->device_name, pos, nlen);
-               msg->device_name[nlen] = '\0';
-               for (i = 0; i < nlen; i++) {
-                       if (msg->device_name[i] == '\0')
-                               break;
-                       if (is_ctrl_char(msg->device_name[i]))
-                               msg->device_name[i] = '_';
-               }
+               p2p_copy_filter_devname(msg->device_name,
+                                       sizeof(msg->device_name), pos, nlen);
                wpa_printf(MSG_DEBUG, "P2P: * Device Info: addr " MACSTR
                           " primary device type %s device name '%s' "
                           "config methods 0x%x",