DHCP decoder handling of header string fields

Arran Cudbard-Bell a.cudbardb at freeradius.org
Fri Feb 5 06:32:07 CET 2016


>> 
>> 		case PW_TYPE_STRING:
>> 			if (*p != '\0') {
>> 				uint8_t *end;
>> 				int len;
>> 				end = memchr(p, '\0', dhcp_header_sizes[i]);
>> 				len = end ? end - p : dhcp_header_sizes[i];
>> 				q = talloc_array(vp, char, len + 1);
>> 				memcpy(q, p, len);
>> 				q[len] = '\0';
>> 				fr_pair_value_strsteal(vp, q);
>> 			}
>> 			if (vp->vp_length == 0) fr_pair_list_free(&vp);
> 
>  That should work.  Though the check for a vp_length == 0 should really be done before allocating any memory.

Agreed, also use talloc_bstrndup to create the buffer.  It does most of what you have above.

-Arran

Arran Cudbard-Bell <a.cudbardb at freeradius.org>
FreeRADIUS development team

FD31 3077 42EC 7FCD 32FE 5EE2 56CF 27F9 30A8 CAA2

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 872 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://lists.freeradius.org/pipermail/freeradius-devel/attachments/20160204/e5220f06/attachment.sig>


More information about the Freeradius-Devel mailing list