[PATCH] write CISCO_SPLIT_INC in order

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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




[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux