[PATCH] write CISCO_SPLIT_INC in order

Corey Hickey bugfood-ml at fatooh.org
Mon Jul 10 15:44:01 PDT 2017


The linked list implementation results in routes being queued in
reverse of the order in which they were received. So, when dequeuing
them, write to the buffer backwards.

Signed-off-by: Corey Hickey <bugfood-ml at fatooh.org>
---
 script.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/script.c b/script.c
index 4a78e67..5f14029 100644
--- a/script.c
+++ b/script.c
@@ -301,16 +301,19 @@ void prepare_script_env(struct openconnect_info *vpninfo)
 		}
 		list = malloc(len);
 		if (list) {
-			char *p = list;
+			/* position at last element before NULL */
+			char *p = list+len-1;
 
 			dns = vpninfo->ip_info.split_dns;
 			while (1) {
-				strcpy(p, dns->route);
-				p += strlen(p);
+				int route_len = strlen(dns->route);
+				/* back up pointer to make room to copy */
+				p -= route_len;
+				strncpy(p, dns->route, route_len);
 				dns = dns->next;
 				if (!dns)
 					break;
-				*(p++) = ',';
+				*(--p) = ',';
 			}
 			script_setenv(vpninfo, "CISCO_SPLIT_DNS", list, 0);
 			free(list);
-- 
2.13.2




More information about the openconnect-devel mailing list