use count instead of length for request list
authorDenis Vinogradov <denis.vinogradov@samsung.com>
Fri, 4 Sep 2020 04:21:33 +0000 (13:21 +0900)
committerSeongsik Kim <sz.kim@samsung.com>
Wed, 9 Sep 2020 04:36:34 +0000 (13:36 +0900)
Change-Id: If9cd48244a91a36c38b2f1e4ad88cad37a4962d3
Signed-off-by: Denis Vinogradov <denis.vinogradov@samsung.com>
src/libcharon/comm/vendor_request_list.c

index 4aef3f1b26958d7a421cfbd88211813d20249db4..0d4c913043f087c234c5ebf0adffde3ad7fcacc4 100755 (executable)
@@ -63,16 +63,19 @@ vendor_request_list_t* build_vendor_request_list(char *buffer)
        );
        if (buffer != NULL)
        {
-               unsigned int size = *((unsigned int*)buffer);
-               unsigned short *values = (unsigned short*)(buffer + sizeof(int));
+               typedef struct {
+                       unsigned int count;
+                       unsigned short values[0];
+               } packed_ushort_list_t;
 
-               if (size)
+               packed_ushort_list_t *request = (packed_ushort_list_t*)buffer;
+               if (request->count)
                {
-                       this->size = size / 2;
+                       this->size = request->count;
                        this->values = calloc(this->size, sizeof(unsigned int));
                        for (int i = 0; i < this->size; i++)
                        {
-                               this->values[i] = values[i] & 0xFFFF;
+                               this->values[i] = request->values[i] & 0xFFFF;
                        }
                }
        }