From: Mathieu Desnoyers Date: Mon, 21 Sep 2015 19:47:09 +0000 (-0400) Subject: Fix: Argument with 'nonnull' attribute passed null X-Git-Tag: v2.8.0-rc1~74 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=99b99b470fddbc81b9c7d01320616efdbe1cb55b;p=lttng-ust.git Fix: Argument with 'nonnull' attribute passed null Reported by scan-build API Argument with 'nonnull' attribute passed null libringbuffer /ring_buffer_backend.c 380 API Argument with 'nonnull' attribute passed null libringbuffer /ring_buffer_backend.c 420 Signed-off-by: Mathieu Desnoyers --- diff --git a/libringbuffer/ring_buffer_backend.c b/libringbuffer/ring_buffer_backend.c index 40fae801..54fe627c 100644 --- a/libringbuffer/ring_buffer_backend.c +++ b/libringbuffer/ring_buffer_backend.c @@ -374,6 +374,7 @@ size_t lib_ring_buffer_read(struct lttng_ust_lib_ring_buffer_backend *bufb, size ssize_t orig_len; struct lttng_ust_lib_ring_buffer_backend_pages_shmp *rpages; unsigned long sb_bindex, id; + void *src; orig_len = len; offset &= chanb->buf_size - 1; @@ -390,7 +391,11 @@ size_t lib_ring_buffer_read(struct lttng_ust_lib_ring_buffer_backend *bufb, size CHAN_WARN_ON(chanb, offset >= chanb->buf_size); CHAN_WARN_ON(chanb, config->mode == RING_BUFFER_OVERWRITE && subbuffer_id_is_noref(config, id)); - memcpy(dest, shmp_index(handle, shmp(handle, rpages->shmp)->p, offset & (chanb->subbuf_size - 1)), len); + src = shmp_index(handle, shmp(handle, rpages->shmp)->p, + offset & (chanb->subbuf_size - 1)); + if (caa_unlikely(!src)) + return 0; + memcpy(dest, src, len); return orig_len; } @@ -430,6 +435,8 @@ int lib_ring_buffer_read_cstr(struct lttng_ust_lib_ring_buffer_backend *bufb, si CHAN_WARN_ON(chanb, config->mode == RING_BUFFER_OVERWRITE && subbuffer_id_is_noref(config, id)); str = shmp_index(handle, shmp(handle, rpages->shmp)->p, offset & (chanb->subbuf_size - 1)); + if (caa_unlikely(!str)) + return -EINVAL; string_len = strnlen(str, len); if (dest && len) { memcpy(dest, str, string_len);