X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=src%2Frmr%2Fcommon%2Fsrc%2Fmbuf_api.c;h=84996ee7b6be6a5f869129510d97e8e95f91ffc4;hb=refs%2Fchanges%2F77%2F1977%2F1;hp=e88ab233436c13ea550a9b240078eb44a464a956;hpb=4ac73e3b9c0ff7aef80ad45f1bfead52bb2ffc99;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 e88ab23..84996ee 100644 --- a/src/rmr/common/src/mbuf_api.c +++ b/src/rmr/common/src/mbuf_api.c @@ -22,7 +22,9 @@ Mnemonic: mbuf_api.c Abstract: These are common functions which work only on the mbuf and thus (because they do not touch an endpoint or context) - can be agnostic to the underlying transport. + can be agnostic to the underlying transport, or the transport + layer provides a transport specific function (e.g. payload + reallocation). Author: E. Scott Daniels Date: 8 February 2019 @@ -51,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; @@ -64,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; } @@ -222,7 +239,7 @@ extern unsigned char* rmr_get_xact( rmr_mbuf_t* mbuf, unsigned char* dest ) { } /* - Extracts the meid (managed equipment) from the header and copies the bytes + Extracts the meid (managed entity) from the header and copies the bytes to the user supplied area. If the user supplied pointer is nil, then a buffer will be allocated and it is the user's responsibilty to free. A pointer is returned to the destination memory (allocated or not) @@ -447,3 +464,4 @@ extern unsigned char* rmr_get_srcip( rmr_mbuf_t* msg, unsigned char* dest ) { return rstr; } +