Skip to content

Commit 5b29820

Browse files
committed
Fix -Wstringop-truncation
For the Sphinx storage engine, this is a functional change (bug fix): we will ensure that the message buffer is always NUL-terminated.
1 parent 94e6a4f commit 5b29820

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

storage/perfschema/pfs_instr.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,7 +1265,6 @@ find_or_create_file(PFS_thread *thread, PFS_file_class *klass,
12651265
char dirbuffer[FN_REFLEN];
12661266
size_t dirlen;
12671267
const char *normalized_filename;
1268-
int normalized_length;
12691268

12701269
dirlen= dirname_length(safe_filename);
12711270
if (dirlen == 0)
@@ -1296,7 +1295,7 @@ find_or_create_file(PFS_thread *thread, PFS_file_class *klass,
12961295
*buf_end= '\0';
12971296

12981297
normalized_filename= buffer;
1299-
normalized_length= strlen(normalized_filename);
1298+
size_t normalized_length= strlen(normalized_filename);
13001299

13011300
PFS_file **entry;
13021301
uint retry_count= 0;
@@ -1345,7 +1344,7 @@ find_or_create_file(PFS_thread *thread, PFS_file_class *klass,
13451344
pfs->m_class= klass;
13461345
pfs->m_enabled= klass->m_enabled && flag_global_instrumentation;
13471346
pfs->m_timed= klass->m_timed;
1348-
strncpy(pfs->m_filename, normalized_filename, normalized_length);
1347+
strncpy(pfs->m_filename, normalized_filename, normalized_length + 1);
13491348
pfs->m_filename[normalized_length]= '\0';
13501349
pfs->m_filename_length= normalized_length;
13511350
pfs->m_file_stat.m_open_count= 1;

storage/sphinx/ha_sphinx.cc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2291,7 +2291,8 @@ int ha_sphinx::HandleMysqlError ( MYSQL * pConn, int iErrCode )
22912291
CSphSEThreadTable * pTable = GetTls ();
22922292
if ( pTable )
22932293
{
2294-
strncpy ( pTable->m_tStats.m_sLastMessage, mysql_error ( pConn ), sizeof ( pTable->m_tStats.m_sLastMessage ) );
2294+
strncpy ( pTable->m_tStats.m_sLastMessage, mysql_error ( pConn ), sizeof pTable->m_tStats.m_sLastMessage - 1 );
2295+
pTable->m_tStats.m_sLastMessage[sizeof pTable->m_tStats.m_sLastMessage - 1] = '\0';
22952296
pTable->m_tStats.m_bLastError = true;
22962297
}
22972298

@@ -2558,7 +2559,8 @@ bool ha_sphinx::UnpackSchema ()
25582559
CSphSEThreadTable * pTable = GetTls ();
25592560
if ( pTable )
25602561
{
2561-
strncpy ( pTable->m_tStats.m_sLastMessage, sMessage, sizeof(pTable->m_tStats.m_sLastMessage) );
2562+
strncpy ( pTable->m_tStats.m_sLastMessage, sMessage, sizeof pTable->m_tStats.m_sLastMessage - 1 );
2563+
pTable->m_tStats.m_sLastMessage[sizeof pTable->m_tStats.m_sLastMessage - 1] = '\0';
25622564
pTable->m_tStats.m_bLastError = ( uStatus==SEARCHD_ERROR );
25632565
}
25642566

@@ -2982,7 +2984,8 @@ int ha_sphinx::index_read ( byte * buf, const byte * key, uint key_len, enum ha_
29822984
SPH_RET ( HA_ERR_END_OF_FILE );
29832985
}
29842986

2985-
strncpy ( pTable->m_tStats.m_sLastMessage, sMessage, sizeof(pTable->m_tStats.m_sLastMessage) );
2987+
strncpy ( pTable->m_tStats.m_sLastMessage, sMessage, sizeof pTable->m_tStats.m_sLastMessage - 1 );
2988+
pTable->m_tStats.m_sLastMessage[sizeof pTable->m_tStats.m_sLastMessage - 1] = '\0';
29862989
SafeDeleteArray ( sMessage );
29872990

29882991
if ( uRespStatus!=SEARCHD_WARNING )

0 commit comments

Comments
 (0)