1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2024-12-12 10:04:14 +02:00

Add CodeQL static code analysis.

Also fix some minor issues identified, specifically using gmtime_r()/localtime_r() vs gmtime()/localtime().
This commit is contained in:
David Steele 2021-07-09 14:16:10 -04:00 committed by GitHub
parent 849ab343aa
commit 3c8819e10f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 67 additions and 12 deletions

View File

@ -7,6 +7,10 @@ on:
- '**-ci' - '**-ci'
- '**-cig' - '**-cig'
pull_request: pull_request:
branches:
- integration
- '**-ci'
- '**-cig'
jobs: jobs:
test: test:
@ -50,3 +54,32 @@ jobs:
- name: Run Test - name: Run Test
run: cd ${HOME?} && ${GITHUB_WORKSPACE?}/pgbackrest/test/ci.pl ${{matrix.param}} --param=build-max=2 run: cd ${HOME?} && ${GITHUB_WORKSPACE?}/pgbackrest/test/ci.pl ${{matrix.param}} --param=build-max=2
codeql:
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write
strategy:
fail-fast: false
matrix:
language:
- cpp
steps:
- name: Checkout Code
uses: actions/checkout@v2
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: ${{matrix.language}}
- name: Build
run: ${GITHUB_WORKSPACE?}/src/configure && make -j 2
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1

View File

@ -127,6 +127,17 @@
<release-test-list> <release-test-list>
<release-improvement-list> <release-improvement-list>
<release-item>
<github-pull-request id="1457"/>
<release-item-contributor-list>
<release-item-contributor id="david.steele"/>
<release-item-reviewer id="cynthia.shang"/>
</release-item-contributor-list>
<p>Add CodeQL static code analysis.</p>
</release-item>
<release-item> <release-item>
<commit subject="Update command/expire test to use standard patterns."> <commit subject="Update command/expire test to use standard patterns.">
<github-pull-request id="1420"/> <github-pull-request id="1420"/>

View File

@ -30,9 +30,12 @@ backupLabelFormat(BackupType type, const String *backupLabelPrior, time_t timest
ASSERT(timestamp > 0); ASSERT(timestamp > 0);
// Format the timestamp // Format the timestamp
struct tm timePart;
char buffer[16]; char buffer[16];
THROW_ON_SYS_ERROR( THROW_ON_SYS_ERROR(
strftime(buffer, sizeof(buffer), "%Y%m%d-%H%M%S", localtime(&timestamp)) == 0, AssertError, "unable to format time"); strftime(buffer, sizeof(buffer), "%Y%m%d-%H%M%S", localtime_r(&timestamp, &timePart)) == 0, AssertError,
"unable to format time");
// If full label // If full label
String *result = NULL; String *result = NULL;

View File

@ -785,13 +785,14 @@ formatTextBackup(const DbGroup *dbGroup, String *resultStr)
// Get and format the backup start/stop time // Get and format the backup start/stop time
KeyValue *timestampInfo = varKv(kvGet(backupInfo, BACKUP_KEY_TIMESTAMP_VAR)); KeyValue *timestampInfo = varKv(kvGet(backupInfo, BACKUP_KEY_TIMESTAMP_VAR));
struct tm timePart;
char timeBufferStart[20]; char timeBufferStart[20];
char timeBufferStop[20]; char timeBufferStop[20];
time_t timeStart = (time_t)varUInt64(kvGet(timestampInfo, KEY_START_VAR)); time_t timeStart = (time_t)varUInt64(kvGet(timestampInfo, KEY_START_VAR));
time_t timeStop = (time_t)varUInt64(kvGet(timestampInfo, KEY_STOP_VAR)); time_t timeStop = (time_t)varUInt64(kvGet(timestampInfo, KEY_STOP_VAR));
strftime(timeBufferStart, sizeof(timeBufferStart), "%Y-%m-%d %H:%M:%S", localtime(&timeStart)); strftime(timeBufferStart, sizeof(timeBufferStart), "%Y-%m-%d %H:%M:%S", localtime_r(&timeStart, &timePart));
strftime(timeBufferStop, sizeof(timeBufferStop), "%Y-%m-%d %H:%M:%S", localtime(&timeStop)); strftime(timeBufferStop, sizeof(timeBufferStop), "%Y-%m-%d %H:%M:%S", localtime_r(&timeStop, &timePart));
strCatFmt(resultStr, " timestamp start/stop: %s / %s\n", timeBufferStart, timeBufferStop); strCatFmt(resultStr, " timestamp start/stop: %s / %s\n", timeBufferStart, timeBufferStop);
strCatZ(resultStr, " wal start/stop: "); strCatZ(resultStr, " wal start/stop: ");

View File

@ -1831,9 +1831,11 @@ restoreRecoveryWrite(const Manifest *manifest)
else else
{ {
// Generate a label used to identify this restore in the recovery file // Generate a label used to identify this restore in the recovery file
struct tm timePart;
char restoreTimestamp[20]; char restoreTimestamp[20];
time_t timestamp = time(NULL); time_t timestamp = time(NULL);
strftime(restoreTimestamp, sizeof(restoreTimestamp), "%Y-%m-%d %H:%M:%S", localtime(&timestamp));
strftime(restoreTimestamp, sizeof(restoreTimestamp), "%Y-%m-%d %H:%M:%S", localtime_r(&timestamp, &timePart));
const String *restoreLabel = STR(restoreTimestamp); const String *restoreLabel = STR(restoreTimestamp);
// Write recovery file based on PostgreSQL version // Write recovery file based on PostgreSQL version

View File

@ -53,19 +53,20 @@ httpDateToTime(const String *lastModified)
} }
String * String *
httpDateFromTime(time_t time) httpDateFromTime(const time_t time)
{ {
FUNCTION_TEST_BEGIN(); FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(TIME, time); FUNCTION_TEST_PARAM(TIME, time);
FUNCTION_TEST_END(); FUNCTION_TEST_END();
struct tm *timePart = gmtime(&time); struct tm timePart;
gmtime_r(&time, &timePart);
FUNCTION_TEST_RETURN( FUNCTION_TEST_RETURN(
strNewFmt( strNewFmt(
"%s, %02d %s %04d %02d:%02d:%02d GMT", httpCommonDayList[timePart->tm_wday], timePart->tm_mday, "%s, %02d %s %04d %02d:%02d:%02d GMT", httpCommonDayList[timePart.tm_wday], timePart.tm_mday,
httpCommonMonthList[timePart->tm_mon], timePart->tm_year + 1900, timePart->tm_hour, timePart->tm_min, httpCommonMonthList[timePart.tm_mon], timePart.tm_year + 1900, timePart.tm_hour, timePart.tm_min,
timePart->tm_sec)); timePart.tm_sec));
} }
/**********************************************************************************************************************************/ /**********************************************************************************************************************************/

View File

@ -371,11 +371,13 @@ logPre(LogLevel logLevel, unsigned int processId, const char *fileName, const ch
// Add time // Add time
if (logTimestamp) if (logTimestamp)
{ {
struct tm timePart;
TimeMSec logTimeMSec = timeMSec(); TimeMSec logTimeMSec = timeMSec();
time_t logTimeSec = (time_t)(logTimeMSec / MSEC_PER_SEC); time_t logTimeSec = (time_t)(logTimeMSec / MSEC_PER_SEC);
result.bufferPos += strftime( result.bufferPos += strftime(
logBuffer + result.bufferPos, sizeof(logBuffer) - result.bufferPos, "%Y-%m-%d %H:%M:%S", localtime(&logTimeSec)); logBuffer + result.bufferPos, sizeof(logBuffer) - result.bufferPos, "%Y-%m-%d %H:%M:%S",
localtime_r(&logTimeSec, &timePart));
result.bufferPos += (size_t)snprintf( result.bufferPos += (size_t)snprintf(
logBuffer + result.bufferPos, sizeof(logBuffer) - result.bufferPos, ".%03d ", (int)(logTimeMSec % 1000)); logBuffer + result.bufferPos, sizeof(logBuffer) - result.bufferPos, ".%03d ", (int)(logTimeMSec % 1000));
} }

View File

@ -374,7 +374,8 @@ cvtTimeToZ(time_t value, char *buffer, size_t bufferSize)
ASSERT(buffer != NULL); ASSERT(buffer != NULL);
size_t result = strftime(buffer, bufferSize, "%s", localtime(&value)); struct tm timePart;
size_t result = strftime(buffer, bufferSize, "%s", localtime_r(&value, &timePart));
if (result == 0) if (result == 0)
THROW(AssertError, "buffer overflow"); THROW(AssertError, "buffer overflow");

View File

@ -141,10 +141,11 @@ storageS3DateTime(time_t authTime)
FUNCTION_TEST_PARAM(TIME, authTime); FUNCTION_TEST_PARAM(TIME, authTime);
FUNCTION_TEST_END(); FUNCTION_TEST_END();
struct tm timePart;
char buffer[ISO_8601_DATE_TIME_SIZE + 1]; char buffer[ISO_8601_DATE_TIME_SIZE + 1];
THROW_ON_SYS_ERROR( THROW_ON_SYS_ERROR(
strftime(buffer, sizeof(buffer), "%Y%m%dT%H%M%SZ", gmtime(&authTime)) != ISO_8601_DATE_TIME_SIZE, AssertError, strftime(buffer, sizeof(buffer), "%Y%m%dT%H%M%SZ", gmtime_r(&authTime, &timePart)) != ISO_8601_DATE_TIME_SIZE, AssertError,
"unable to format date"); "unable to format date");
FUNCTION_TEST_RETURN(strNewZ(buffer)); FUNCTION_TEST_RETURN(strNewZ(buffer));