Skip to content

Instantly share code, notes, and snippets.

@0minus273
Created July 31, 2014 10:51
Show Gist options
  • Save 0minus273/4d3bef8f3014e5cb59b2 to your computer and use it in GitHub Desktop.
Save 0minus273/4d3bef8f3014e5cb59b2 to your computer and use it in GitHub Desktop.
not_well.c
50 static bool
51 pack_str(struct whackpacker *wp, char **p)
52 {
53 const char *s = *p == NULL? "" : *p; /* note: NULL becomes ""! */
54 size_t len = strlen(s) + 1;
55
56 if (wp->str_roof - wp->str_next < (ptrdiff_t)len)
57 {
58 return FALSE; /* fishy: no end found */
59 }
60 else
61 {
62 strcpy((char *)wp->str_next, s);
63 wp->str_next += len;
64 *p = NULL; /* don't send pointers on the wire! */
65 return TRUE;
66 }
67 }
68
106 err_t pack_whack_msg (struct whackpacker *wp)
107 {
108 err_t ugh = NULL;
112 wp->str_next = wp->msg->string;
113 wp->str_roof = &wp->msg->string[sizeof(wp->msg->string)];
114
115 if (!pack_str(wp, &wp->msg->name) /* string 1 */
116 || !pack_str(wp, &wp->msg->left.id) /* string 2 */
117 || !pack_str(wp, &wp->msg->left.cert) /* string 3 */
118 || !pack_str(wp, &wp->msg->left.ca) /* string 4 */
119 || !pack_str(wp, &wp->msg->left.groups) /* string 5 */
120 || !pack_str(wp, &wp->msg->left.updown) /* string 6 */
121 || !pack_str(wp, &wp->msg->left.virt) /* string 7 */
122 || !pack_str(wp, &wp->msg->right.id) /* string 8 */
123 || !pack_str(wp, &wp->msg->right.cert) /* string 9 */
124 || !pack_str(wp, &wp->msg->right.ca) /* string 10 */
125 || !pack_str(wp, &wp->msg->right.groups)/* string 11 */
126 || !pack_str(wp, &wp->msg->right.updown)/* string 12 */
127 || !pack_str(wp, &wp->msg->right.virt) /* string 13 */
128 || !pack_str(wp, &wp->msg->keyid) /* string 14 */
129 || !pack_str(wp, &wp->msg->myid) /* string 15 */
130 || !pack_str(wp, &wp->msg->ike) /* string 16 */
131 || !pack_str(wp, &wp->msg->esp) /* string 17 */
132 || !pack_str(wp, &wp->msg->tpmeval) /* string 18 */
133 || !pack_str(wp, &wp->msg->left.xauth_name) /* string 19 */
134 || !pack_str(wp, &wp->msg->right.xauth_name) /* string 20 */
135 || !pack_str(wp, &wp->msg->connalias) /* string 21 */
136 || !pack_str(wp, &wp->msg->left.host_addr_name) /* string 22 */
137 || !pack_str(wp, &wp->msg->right.host_addr_name) /* string 23 */
138 || !pack_str(wp, &wp->msg->string1) /* string 24 */
139 || !pack_str(wp, &wp->msg->string2) /* string 25 */
140 || !pack_str(wp, &wp->msg->string3) /* string 26 */
141 || !pack_str(wp, &wp->msg->dnshostname) /* string 27 ? */
142 #ifdef HAVE_LABELED_IPSEC
143 || !pack_str(wp, &wp->msg->policy_label) /* string 28 */
144 #endif
145 || wp->str_roof - wp->str_next < (ptrdiff_t)wp->msg->keyval.len) /* chunk (sort of string 28) */
146 {
147 ugh = "too many bytes of strings to fit in message to pluto";
148 return ugh;
149 }
150
151 if(wp->msg->keyval.ptr)
152 {
153 memcpy(wp->str_next, wp->msg->keyval.ptr, wp->msg->keyval.len);
154 }
155 wp->msg->keyval.ptr = NULL;
156 wp->str_next += wp->msg->keyval.len;
157
158 return ugh;
159 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment