This add a static inline version of `g_memdup2` if the version of glib we're
compiling against doesn't have the function.
GHSL-2021-045 was originally reported to glib at
https://gitlab.gnome.org/GNOME/glib/-/issues/2319.
More information about the entire situation can be found on the gnome
desktop-devel-list at
https://mail.gnome.org/archives/desktop-devel-list/2021-February/msg00000.html
Testing Done:
Compiled and ran tests locally.
Reviewed at https://reviews.imfreedom.org/r/483/
/*
* Purple's oscar protocol plugin
* This file is the legal property of its developers.
* Please see the AUTHORS file distributed alongside this file.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
*/
#include"oscar.h"
#include"glibcompat.h"
staticaim_tlv_t*
createtlv(guint16type,guint16length,guint8*value)
{
aim_tlv_t*ret;
ret=g_new(aim_tlv_t,1);
ret->type=type;
ret->length=length;
ret->value=value;
returnret;
}
staticvoid
freetlv(aim_tlv_t*oldtlv)
{
g_free(oldtlv->value);
g_free(oldtlv);
}
staticGSList*
aim_tlv_read(GSList*list,ByteStream*bs)
{
guint16type,length;
aim_tlv_t*tlv;
type=byte_stream_get16(bs);
length=byte_stream_get16(bs);
if(length>byte_stream_bytes_left(bs)){
aim_tlvlist_free(list);
returnNULL;
}
tlv=createtlv(type,length,NULL);
if(tlv->length>0){
tlv->value=byte_stream_getraw(bs,length);
if(!tlv->value){
freetlv(tlv);
aim_tlvlist_free(list);
returnNULL;
}
}
returng_slist_prepend(list,tlv);
}
/**
* Read a TLV chain from a buffer.
*
* Reads and parses a series of TLV patterns from a data buffer; the
* returned structure is manipulatable with the rest of the TLV
* routines. When done with a TLV chain, aim_tlvlist_free() should
* be called to free the dynamic substructures.
*
* TODO: There should be a flag setable here to have the tlvlist contain
* bstream references, so that at least the ->value portion of each
* element doesn't need to be malloc/memcpy'd. This could prove to be
* just as efficient as the in-place TLV parsing used in a couple places
* in libfaim.
*
* @param bs Input bstream
* @return Return the TLV chain read
*/
GSList*aim_tlvlist_read(ByteStream*bs)
{
GSList*list=NULL;
while(byte_stream_bytes_left(bs)>0){
list=aim_tlv_read(list,bs);
if(list==NULL)
returnNULL;
}
returng_slist_reverse(list);
}
/**
* Read a TLV chain from a buffer.
*
* Reads and parses a series of TLV patterns from a data buffer; the
* returned structure is manipulatable with the rest of the TLV
* routines. When done with a TLV chain, aim_tlvlist_free() should
* be called to free the dynamic substructures.
*
* TODO: There should be a flag setable here to have the tlvlist contain
* bstream references, so that at least the ->value portion of each
* element doesn't need to be malloc/memcpy'd. This could prove to be
* just as efficient as the in-place TLV parsing used in a couple places
* in libfaim.
*
* @param bs Input bstream
* @param num The max number of TLVs that will be read, or -1 if unlimited.
* There are a number of places where you want to read in a tlvchain,
* but the chain is not at the end of the SNAC, and the chain is
* preceded by the number of TLVs. So you can limit that with this.