Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Codeql security #208

Merged
merged 6 commits into from
Feb 4, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -7,19 +7,15 @@ jobs:
name: CodeQL Analyze
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
language: [ 'cpp' ]

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: ${{ matrix.language }}
languages: cpp
queries: security-extended

- run: make

3 changes: 2 additions & 1 deletion include/re_sys.h
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
*
* Copyright (C) 2010 Creytiv.com
*/

#include <stdio.h>

#ifndef VERSION
#define VERSION "?"
@@ -73,3 +73,4 @@ int fs_mkdir(const char *path, uint16_t mode);
int fs_gethome(char *path, size_t sz);
bool fs_isdir(const char *path);
bool fs_isfile(const char *file);
int fs_fopen(FILE **fp, const char *file, const char *mode);
9 changes: 6 additions & 3 deletions src/dbg/dbg.c
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@
#include <re_fmt.h>
#include <re_list.h>
#include <re_tmr.h>
#include <re_sys.h>


#define DEBUG_MODULE "dbg"
@@ -99,14 +100,16 @@ void dbg_close(void)
*/
int dbg_logfile_set(const char *name)
{
int err;

dbg_close();

if (!name)
return 0;

dbg.f = fopen(name, "a+");
if (!dbg.f)
return errno;
err = fs_fopen(&dbg.f, name, "a+");
if (err)
return err;

(void)re_fprintf(dbg.f, "\n===== Log Started: %H", fmt_gmtime, NULL);
(void)fflush(dbg.f);
2 changes: 1 addition & 1 deletion src/fmt/print.c
Original file line number Diff line number Diff line change
@@ -163,7 +163,7 @@ static size_t local_ftoa(char *buf, double n, size_t dp)
int re_vhprintf(const char *fmt, va_list ap, re_vprintf_h *vph, void *arg)
{
uint8_t base, *bptr;
char pch, ch, num[NUM_SIZE], addr[64], msg[256];
char pch = 0, ch, num[NUM_SIZE], addr[64], msg[256];
enum length_modifier lenmod = LENMOD_NONE;
struct re_printf pf;
bool fm = false, plr = false;
2 changes: 1 addition & 1 deletion src/sdp/media.c
Original file line number Diff line number Diff line change
@@ -258,7 +258,7 @@ struct sdp_media *sdp_media_find(const struct sdp_session *sess,
*/
void sdp_media_align_formats(struct sdp_media *m, bool offer)
{
struct sdp_format *rfmt, *lfmt;
struct sdp_format *rfmt, *lfmt = NULL;
struct le *rle, *lle;

if (!m || m->disabled || !sa_port(&m->raddr) || m->fmt_ignore)
39 changes: 39 additions & 0 deletions src/sys/fs.c
Original file line number Diff line number Diff line change
@@ -155,3 +155,42 @@ bool fs_isfile(const char *file)

return true;
}


/**
* Open file with security enhancements (like fopen_s).
* The file is created with mode 0600 if it does not exist
*
* @param fp FILE pointer for allocation
* @param file Pathname
* @param mode fopen mode
*
* @return 0 if success, otherwise errorcode
*
*/
int fs_fopen(FILE **fp, const char *file, const char *mode)
{
FILE *pfile;
int fd;

if (!fp || !file || !mode)
return EINVAL;

if (fs_isfile(file))
goto fopen;

fd = open(file, O_WRONLY | O_CREAT, S_IWUSR | S_IRUSR);
if (!fd)
return errno;
else
(void)close(fd);

fopen:
pfile = fopen(file, mode);
if (!pfile)
return errno;

*fp = pfile;

return 0;
}
7 changes: 3 additions & 4 deletions src/trace/trace.c
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@
#include <re_list.h>
#include <re_tmr.h>
#include <re_lock.h>
#include <re_sys.h>

#ifdef HAVE_PTHREAD
#include <pthread.h>
@@ -108,11 +109,9 @@ int re_trace_init(const char *json_file)

lock_alloc(&trace.lock);

trace.f = fopen(json_file, "w+");
if (!trace.f) {
err = errno;
err = fs_fopen(&trace.f, json_file, "w+");
if (err)
goto out;
}

(void)re_fprintf(trace.f, "{\t\n\t\"traceEvents\": [\n");
(void)fflush(trace.f);