[SSSD] [PATCH] Fix dereference after a NULL check in tests.
Lukas Slebodnik
lslebodn at redhat.com
Mon Jun 10 09:56:30 UTC 2013
On (10/06/13 11:46), Jakub Hrozek wrote:
>On Mon, Jun 10, 2013 at 10:53:15AM +0200, Lukas Slebodnik wrote:
>> ehlo,
>>
>> Do not call unlink with NULL pointer.
>>
>> https://fedorahosted.org/sssd/ticket/1972
>> Coverity IDs: 11870,11871
>>
>> Patch is attached.
>>
>> LS
>
>> From 0895c29c074526c4888758f06ba450a0e797e049 Mon Sep 17 00:00:00 2001
>> From: Lukas Slebodnik <lslebodn at redhat.com>
>> Date: Mon, 10 Jun 2013 10:23:44 +0200
>> Subject: [PATCH] Fix dereference after a NULL check in tests.
>>
>> https://fedorahosted.org/sssd/ticket/1972
>> Coverity IDs: 11870,11871
>>
>> Do not call unlink with NULL pointer.
>
>
>> - talloc_free(conf_db);
>> - talloc_free(sys_db);
>> +cleanup:
>> + talloc_free(tmp_ctx);
>
>The code is fine but we usually name the labels "done" especially if
>they can be reached on both success and failure.
I changed the label.
LS
-------------- next part --------------
>From ffdb1f43e2fb11e7e96227c5a18d2b502fca5cfb Mon Sep 17 00:00:00 2001
From: Lukas Slebodnik <lslebodn at redhat.com>
Date: Mon, 10 Jun 2013 10:23:44 +0200
Subject: [PATCH] Fix dereference after a NULL check in tests.
https://fedorahosted.org/sssd/ticket/1972
Coverity IDs: 11870,11871
Do not call unlink with NULL pointer.
---
src/tests/common_dom.c | 26 ++++++++++++++++++++------
1 file changed, 20 insertions(+), 6 deletions(-)
diff --git a/src/tests/common_dom.c b/src/tests/common_dom.c
index 661271d3b416d222525e9ecb1af72ba532170ed6..9edb237e793040518102f90801f4acca048e061d 100644
--- a/src/tests/common_dom.c
+++ b/src/tests/common_dom.c
@@ -132,12 +132,19 @@ void test_dom_suite_cleanup(const char *tests_path,
errno_t ret;
char *conf_db;
char *sys_db;
+ TALLOC_CTX *tmp_ctx;
- conf_db = talloc_asprintf(NULL, "%s/%s", tests_path, confdb_path);
- sys_db = talloc_asprintf(NULL, "%s/%s", tests_path, sysdb_path);
- if (!conf_db || !sys_db) {
+ tmp_ctx = talloc_new(NULL);
+ if (!tmp_ctx) {
+ DEBUG(SSSDBG_CRIT_FAILURE, ("talloc_new failed\n"));
+ return;
+ }
+
+ conf_db = talloc_asprintf(tmp_ctx, "%s/%s", tests_path, confdb_path);
+ if (!conf_db) {
DEBUG(SSSDBG_CRIT_FAILURE,
- ("Could not construct db paths\n"));
+ ("Could not construct conf_db path\n"));
+ goto done;
}
errno = 0;
@@ -148,6 +155,13 @@ void test_dom_suite_cleanup(const char *tests_path,
errno, strerror(errno)));
}
+ sys_db = talloc_asprintf(tmp_ctx, "%s/%s", tests_path, sysdb_path);
+ if (!sys_db) {
+ DEBUG(SSSDBG_CRIT_FAILURE,
+ ("Could not construct sys_db path\n"));
+ goto done;
+ }
+
errno = 0;
ret = unlink(sys_db);
if (ret != 0 && errno != ENOENT) {
@@ -164,6 +178,6 @@ void test_dom_suite_cleanup(const char *tests_path,
errno, strerror(errno)));
}
- talloc_free(conf_db);
- talloc_free(sys_db);
+done:
+ talloc_free(tmp_ctx);
}
--
1.8.1.4
More information about the sssd-devel
mailing list