[PATCH] Modeling for talloc
Andreas Schneider
asn at samba.org
Mon May 8 09:04:56 UTC 2017
Hi Volker,
here is a try to add modeling for talloc. After applying the patch you need to
upload it to scan.coverity.com
Descriptions are here:
https://scan.coverity.com/models
I haven't found out how to mark NTSTATUS.
Review much appreciated!
Andreas
--
Andreas Schneider GPG-ID: CC014E3D
Samba Team asn at samba.org
www.samba.org
-------------- next part --------------
>From 5644820d715590e10ba5605e969a19a74926bcf2 Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn at samba.org>
Date: Mon, 8 May 2017 10:07:35 +0200
Subject: [PATCH] coverity: Extend modelling file for talloc
See:
https://scan.coverity.com/models
Signed-off-by: Andreas Schneider <asn at samba.org>
---
coverity/coverity_assert_model.c | 281 +++++++++++++++++++++++++++++++++++++++
1 file changed, 281 insertions(+)
diff --git a/coverity/coverity_assert_model.c b/coverity/coverity_assert_model.c
index ba5c17d0a58..0e3a9e23b30 100644
--- a/coverity/coverity_assert_model.c
+++ b/coverity/coverity_assert_model.c
@@ -1,3 +1,39 @@
+/*
+ Unix SMB/CIFS implementation.
+
+ Coverity Modelling file
+
+ Copyright (c) 2016-2017 Andreas Schneider <asn at samba.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program 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 General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#define NULL ((void *)0)
+
+typedef unsigned char uint8_t;
+typedef char int8_t;
+typedef unsigned int uint32_t;
+typedef int int32_t;
+typedef long ssize_t;
+typedef unsigned long size_t;
+typedef unsigned long long uint64_t;
+typedef long long int64_t;
+
+/*
+ * CMOCKA
+ */
+
#define LargestIntegralType unsigned long long
void _assert_true(const LargestIntegralType result,
@@ -84,3 +120,248 @@ void _assert_not_in_set(
{
__coverity_panic__();
}
+
+/*
+ * TALLOC
+ */
+
+void *_talloc_get_type_abort(const void *ptr, const char *name, const char *location)
+{
+ __coverity_panic__();
+}
+
+void *talloc_named_const(const void *context, size_t size, const char *name)
+{
+ int has_memory;
+
+ __coverity_negative_sink__(size);
+
+ if (has_memory) {
+ return __coverity_alloc__(size);
+ }
+
+ return NULL;
+}
+
+int _talloc_free(void *ptr, const char *location)
+{
+ __coverity_free__(ptr);
+}
+
+void *_talloc_realloc(const void *context, void *ptr, size_t size, const char *name)
+{
+ _talloc_free(ptr, __location__);
+ return talloc_named_const(context, size, name);
+}
+
+void *_talloc_zero(const void *ctx, size_t size, const char *name)
+{
+ return talloc_named_const(ctx, size, name);
+}
+
+void *_talloc_memdup(const void *t, const void *p, size_t size, const char *name)
+{
+ void *newp = talloc_named_const(t, size, name);
+
+ if (newp != NULL) {
+ memcpy(newp, p, size);
+ }
+
+ return newp;
+}
+
+char *talloc_strdup(const void *t, const char *p)
+{
+ void *x;
+
+ x = __coverity_alloc__(strlen(p) + 1);
+ __coverity_writeall__(x);
+
+ return (x);
+}
+
+char *talloc_strndup(const void *t, const char *p, size_t n)
+{
+ void *x;
+
+ __coverity_negative_sink__(n);
+
+ x = __coverity_alloc__(n + 1);
+ __coverity_writeall__(x);
+
+ return (x);
+}
+
+char *talloc_strdup_append(char *s, const char *a)
+{
+ void *x;
+
+ x = __coverity_alloc__(strlen(s) + strlen(a) + 1);
+
+ __coverity_writeall__(x);
+
+ _talloc_free(s, __location__);
+
+ return (x);
+}
+
+char *talloc_strdup_append_buffer(char *s, const char *a)
+{
+ _talloc_free(s, __location__);
+ return __coverity_alloc_nosize__;
+}
+
+char *talloc_strndup_append(char *s, const char *a, size_t n)
+{
+ void *x;
+
+ __coverity_negative_sink__(n);
+
+ x = __coverity_alloc__(strlen(s) + n + 1);
+
+ __coverity_writeall__(x);
+
+ _talloc_free(s, __location__);
+
+ return (x);
+}
+
+char *talloc_strndup_append_buffer(char *s, const char *a, size_t n)
+{
+ void *x;
+
+ x = __coverity_alloc_nosize__;
+ _talloc_free(s, __location__);
+
+ return x;
+}
+
+char *talloc_vasprintf(const void *t, const char *fmt, va_list ap)
+{
+ char ch;
+ char *x;
+ size_t len;
+
+ __coverity_string_null_sink__(fmt);
+ __coverity_string_size_sink__(fmt);
+
+ ch = *format;
+ ch = *(char *)ap;
+
+ x = __coverity_alloc_nosize__;
+ __coverity_writeall__(x);
+
+ return x;
+}
+
+char *talloc_asprintf(const void *t, const char *fmt, ...)
+{
+ char ch;
+ char *x;
+ size_t len;
+
+ __coverity_string_null_sink__(fmt);
+ __coverity_string_size_sink__(fmt);
+
+ ch = *format;
+
+ x = __coverity_alloc_nosize__;
+ __coverity_writeall__(x);
+
+ return x;
+}
+
+char *talloc_vasprintf_append(char *s, const char *fmt, va_list ap)
+{
+ void *x;
+
+ __coverity_string_null_sink__(fmt);
+ __coverity_string_size_sink__(fmt);
+
+ ch = *format;
+ ch = *(char *)ap;
+
+ x = __coverity_alloc_nosize__;
+ __coverity_writeall__(x);
+ _talloc_free(s, __location__);
+
+ return x;
+}
+
+char *talloc_vasprintf_append_buffer(char *s, const char *fmt, va_list ap)
+{
+ void *x;
+
+ __coverity_string_null_sink__(fmt);
+ __coverity_string_size_sink__(fmt);
+
+ ch = *format;
+ ch = *(char *)ap;
+
+ x = __coverity_alloc_nosize__;
+ __coverity_writeall__(x);
+ _talloc_free(s, __location__);
+
+ return x;
+}
+
+char *talloc_asprintf_append(char *s, const char *fmt, ...)
+{
+ void *x;
+
+ __coverity_string_null_sink__(fmt);
+ __coverity_string_size_sink__(fmt);
+
+ ch = *format;
+
+ x = __coverity_alloc_nosize__;
+ __coverity_writeall__(x);
+ _talloc_free(s, __location__);
+
+ return x;
+}
+
+char *talloc_asprintf_append_buffer(char *s, const char *fmt, ...)
+{
+ void *x;
+
+ __coverity_string_null_sink__(fmt);
+ __coverity_string_size_sink__(fmt);
+
+ ch = *format;
+
+ x = __coverity_alloc_nosize__;
+ __coverity_writeall__(x);
+ _talloc_free(s, __location__);
+
+ return x;
+}
+
+void *_talloc_array(const void *ctx, size_t el_size, unsigned count, const char *name)
+{
+ __coverity_negative_sink__(el_size);
+ __coverity_negative_sink__(count);
+
+ return talloc_named_const(ctx, el_size * count, name);
+}
+
+void *_talloc_zero_array(const void *ctx, size_t el_size, unsigned count, const char *name)
+{
+ __coverity_negative_sink__(el_size);
+ __coverity_negative_sink__(count);
+
+ return talloc_named_const(ctx, el_size * count, name);
+}
+
+void *_talloc_realloc_array(const void *ctx, void *ptr, size_t el_size, unsigned count, const char *name)
+{
+ void *x;
+
+ __coverity_negative_sink__(el_size);
+ __coverity_negative_sink__(count);
+
+ x = talloc_named_const(ctx, el_size * count, name);
+ _talloc_free(ptr, __location__);
+
+ return x;
+}
--
2.12.2
More information about the samba-technical
mailing list