Skip to content

Commit 6e597e1

Browse files
committed
Bug#17590095: COVERITY ANALYSIS RESULTS AND PATCHES
Bug#70591 : COVERITY ANALYSIS RESULTS AND PATCHES Fix various issues found by Coverity. Some by backporting the fix for Bug#16725945: USE_AFTER_FREE ERRORS - COVERITY SCAN Based on patches contributed by Honza Horak.
1 parent e2e9243 commit 6e597e1

File tree

5 files changed

+20
-8
lines changed

5 files changed

+20
-8
lines changed

mysql-test/lib/My/SafeProcess/safe_process.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -159,6 +159,7 @@ int main(int argc, char* const argv[] )
159159
sigemptyset(&sa.sa_mask);
160160

161161
sa_abort.sa_handler= handle_abort;
162+
sa_abort.sa_flags= 0;
162163
sigemptyset(&sa_abort.sa_mask);
163164
/* Install signal handlers */
164165
sigaction(SIGTERM, &sa,NULL);

mysys/my_copy.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -98,6 +98,10 @@ int my_copy(const char *from, const char *to, myf MyFlags)
9898
if (my_close(from_file,MyFlags) | my_close(to_file,MyFlags))
9999
DBUG_RETURN(-1); /* Error on close */
100100

101+
/* Reinitialize closed fd, so they won't be closed again. */
102+
from_file= -1;
103+
to_file= -1;
104+
101105
/* Copy modes if possible */
102106

103107
if (MyFlags & MY_HOLD_ORIGINAL_MODES && !new_file_stat)

mysys/my_malloc.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -85,6 +85,9 @@ void *my_realloc(void *oldpoint, size_t size, myf my_flags)
8585
(ulong) size, my_flags));
8686

8787
DBUG_ASSERT(size > 0);
88+
/* These flags are mutually exclusive. */
89+
DBUG_ASSERT(!((my_flags & MY_FREE_ON_ERROR) &&
90+
(my_flags & MY_HOLD_ON_ERROR)));
8891
DBUG_EXECUTE_IF("simulate_out_of_memory",
8992
point= NULL;
9093
goto end;);
@@ -100,10 +103,10 @@ void *my_realloc(void *oldpoint, size_t size, myf my_flags)
100103
#endif
101104
if (point == NULL)
102105
{
103-
if (my_flags & MY_FREE_ON_ERROR)
104-
my_free(oldpoint);
105106
if (my_flags & MY_HOLD_ON_ERROR)
106107
DBUG_RETURN(oldpoint);
108+
if (my_flags & MY_FREE_ON_ERROR)
109+
my_free(oldpoint);
107110
my_errno=errno;
108111
if (my_flags & (MY_FAE+MY_WME))
109112
my_error(EE_OUTOFMEMORY, MYF(ME_BELL+ ME_WAITTANG + ME_FATALERROR),

sql/sql_prepare.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3022,7 +3022,9 @@ void mysql_stmt_get_longdata(THD *thd, char *packet, ulong packet_length)
30223022
{
30233023
stmt->state= Query_arena::STMT_ERROR;
30243024
stmt->last_errno= thd->get_stmt_da()->sql_errno();
3025-
strncpy(stmt->last_error, thd->get_stmt_da()->message(), MYSQL_ERRMSG_SIZE);
3025+
size_t len= sizeof(stmt->last_error);
3026+
strncpy(stmt->last_error, thd->get_stmt_da()->message(), len - 1);
3027+
stmt->last_error[len - 1] = '\0';
30263028
}
30273029
thd->set_stmt_da(save_stmt_da);
30283030

sql/sql_trigger.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved.
33
44
This program is free software; you can redistribute it and/or modify
55
it under the terms of the GNU General Public License as published by
@@ -2303,7 +2303,9 @@ void Table_triggers_list::mark_fields_used(trg_event_type event)
23032303
void Table_triggers_list::set_parse_error_message(char *error_message)
23042304
{
23052305
m_has_unparseable_trigger= true;
2306-
strcpy(m_parse_error_message, error_message);
2306+
size_t len= sizeof(m_parse_error_message);
2307+
strncpy(m_parse_error_message, error_message, len - 1);
2308+
m_parse_error_message[len - 1] = '\0';
23072309
}
23082310

23092311

0 commit comments

Comments
 (0)