X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=src%2Frmr%2Fcommon%2Fsrc%2Fmbuf_api.c;h=c879d7c315420a3dd89a1dff3614b7bf755a7c8f;hb=0b79fc264eea2591ad6f645d0c90cc378ea5603b;hp=f7309581bfcb120d6db5f96f270f6ab3720857eb;hpb=d9de79acd9c205dc4f795e90a98331628ed6c85b;p=ric-plt%2Flib%2Frmr.git diff --git a/src/rmr/common/src/mbuf_api.c b/src/rmr/common/src/mbuf_api.c index f730958..c879d7c 100644 --- a/src/rmr/common/src/mbuf_api.c +++ b/src/rmr/common/src/mbuf_api.c @@ -53,6 +53,12 @@ EINVAL id poitner, buf or buf header are bad. EOVERFLOW if the bytes given would have overrun + We have been told that the meid will be a string, so we enforce that even if + the user is copying in bytes. We will add a 0 byte at len+1 when len is less + than the field size, or as the last byte (doing damage to their string) if + the caller didn't play by the rules. If they pass a non-nil terminated set + of bytes which are the field length, we'll indicate truncation. + */ extern int rmr_bytes2meid( rmr_mbuf_t* mbuf, unsigned char const* src, int len ) { uta_mhdr_t* hdr; @@ -66,11 +72,20 @@ extern int rmr_bytes2meid( rmr_mbuf_t* mbuf, unsigned char const* src, int len ) if( len > RMR_MAX_MEID ) { len = RMR_MAX_MEID; errno = EOVERFLOW; - } + } hdr = (uta_mhdr_t *) mbuf->header; memcpy( hdr->meid, src, len ); + if( len == RMR_MAX_MEID ) { + if( *(hdr->meid+len-1) != 0 ) { + *(hdr->meid+len-1) = 0; + errno = EOVERFLOW; + } + } else { + *(hdr->meid+len) = 0; + } + return len; }