Skip to content

Commit

Permalink
fixes the builds for liboleg and the frontend
Browse files Browse the repository at this point in the history
- ol_database: fixes length for config fields

Newer versions of gcc are very strict on the destination buffer length
in calls to strncpy. This commit ensures that the struct fields on
ol_database are long enough to account for the null terminator. This
commit also fixes the test functions to derive the analysis buffer from
the actual length of the db struct fields, ensuring we don't get
compiler warnings about strncpy.

- frontend: cleans up go package and adds a go.mod
- frontend: moves go main to ./cmd/olegdb and goleg package to
  ./pkg/goleg
- frontend: bumps go compiler version to 1.14
  • Loading branch information
kyleterry committed Apr 24, 2020
1 parent 39e9ffd commit 72915f0
Show file tree
Hide file tree
Showing 14 changed files with 48 additions and 36 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
*.swo
*.swp
olegdb
*.o
*.dump
data
Expand Down
42 changes: 24 additions & 18 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
language: c
compiler:
- gcc
- clang
script:
- make liboleg oleg_test
- sudo make install
- export LD_LIBRARY_PATH=./build/lib:$LD_LIBRARY_PATH
- ./build/bin/oleg_test
- LD_LIBRARY_PATH=./build/lib:/usr/local/lib:/usr/lib:$LD_LIBRARY_PATH go test ./...
before_install:
- sudo apt-get update
- sudo apt-get install golang
dist: bionic
language: go
go:
- 1.14.x

notifications:
email:
on_success: never
on_failure: change
recipients:
- "qpfiffer@gmail.com"
email:
on_success: change
on_failure: change
recipients:
- "qpfiffer@gmail.com"
- "kyle@kyleterry.com"

jobs:
include:
- stage: test
script:
- make liboleg oleg_test test
- name: build
script:
- mkdir -p build
- sudo make libinstall
- go test ./...
- make olegdb

env:
global:
- secure: "GbSMNCqnGnjiuDqJJ55/EaNifx9L7t6JQVPw6illEnGZXL3T5RiC7alrpOQl2qGJG/gwRudMpFmEyvEqs0Rlpgx3x1DvcLCMlC2Rjd/2YklD0KVW0D91Mrrkk7ERzQTO8MXB2AUTxjSAwsZtewybebQhoqr7frulM4TclDZ/Cq4="
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ uninstall:

olegdb: liboleg $(LIB_OUT) $(BIN_DIR) $(BIN_OUT)
$(BIN_OUT):
go build -o $(BIN_OUT) ./frontend/
go build -o $(BIN_OUT) ./cmd/olegdb

install: goinstall

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Dependencies
============

* A healthy fear of the end
* Go (>= 1.1)
* Go (>= 1.14)

Installation
============
Expand Down
3 changes: 2 additions & 1 deletion frontend/dispatcher.go → cmd/olegdb/dispatcher.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package main

import (
"./goleg"
"io/ioutil"
"net/http"
"strings"

"github.com/infoforcefeed/olegdb/pkg/goleg"
)

type Operation struct {
Expand Down
3 changes: 2 additions & 1 deletion frontend/main.go → cmd/olegdb/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"./goleg"
"encoding/json"
"flag"
"fmt"
Expand All @@ -10,6 +9,8 @@ import (
"net/http"
"os"
"os/signal"

"github.com/infoforcefeed/olegdb/pkg/goleg"
)

type Config struct {
Expand Down
2 changes: 1 addition & 1 deletion frontend/operations.go → cmd/olegdb/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const (
OpCursorPrev = "._prev"
OpPrefixMatch = "._match"
OpBulkUnjar = "_bulk_unjar"
OpSquish = "_squish"
OpSquish = "_squish"
)

func httpGet(w http.ResponseWriter, op Operation) *HTTPError {
Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/infoforcefeed/olegdb

go 1.14
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github.com/infoforcefeed/olegdb v0.0.0-20190920231543-39e9ffd04c30 h1:O+Siihon2HK9O8K3siG/42HU2UvnxCu69mq3ktlIQCQ=
github.com/infoforcefeed/olegdb v0.0.0-20190920231543-39e9ffd04c30/go.mod h1:H5+5XDNE+DncxwND9HIRshDQ5JP8rkoHkNBkbpDD/GM=
6 changes: 3 additions & 3 deletions include/oleg.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ typedef struct ol_database {
void (*enable)(int, int*);
void (*disable)(int, int*);
bool (*is_enabled)(const int, const int*);
char name[DB_NAME_SIZE];
char path[PATH_LENGTH];
char aol_file[AOL_FILENAME_ALLOC];
char name[DB_NAME_SIZE+1];
char path[PATH_LENGTH+1];
char aol_file[AOL_FILENAME_ALLOC+1];
FILE *aolfd;
int feature_set;
short int state;
Expand Down
2 changes: 1 addition & 1 deletion frontend/goleg/goleg_test.go → pkg/goleg/goleg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func TestBulkUnjarOnlyReturnsKeysWeGiveIt(t *testing.T) {

for i, value := range values {
if subset[i][3] != string(value)[5] {
t.Fatalf("Expected %s, got %s", subset[i][3], string(value)[5])
t.Fatalf("Expected %b, got %b", subset[i][3], string(value)[5])
}
}
}
File renamed without changes.
File renamed without changes.
16 changes: 8 additions & 8 deletions src/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ static int _test_db_close(ol_database *db) {
char values_filename[DB_NAME_SIZE] = { 0 };
db->get_db_file_name(db, VALUES_FILENAME, values_filename);

char aol_filename[DB_NAME_SIZE] = { 0 };
strncpy(aol_filename, db->aol_file, DB_NAME_SIZE);
char aol_filename[sizeof(db->aol_file) + 1] = { 0 };
strncpy(aol_filename, db->aol_file, sizeof(aol_filename));
int should_delete_aol = db->is_enabled(OL_F_APPENDONLY, &db->feature_set);

char DB_PATH[DB_NAME_SIZE] = {0};
strncpy(DB_PATH, db->path, DB_NAME_SIZE);
char DB_PATH[sizeof(db->path) + 1] = { 0 };
strncpy(DB_PATH, db->path, sizeof(DB_PATH));

int ret = ol_close(db);

Expand Down Expand Up @@ -670,8 +670,8 @@ int _test_aol(const ol_feature_flags features, ol_database **db) {
return 4;
}

char DB_PATH[DB_NAME_SIZE + 1] = {0};
strncpy(DB_PATH, (*db)->path, DB_NAME_SIZE);
char DB_PATH[sizeof((*db)->path) + 1] = {0};
strncpy(DB_PATH, (*db)->path, sizeof(DB_PATH));

/* We don't want to use test_db_close here because we want to retrieve
* values again. */
Expand Down Expand Up @@ -714,8 +714,8 @@ int test_aol_and_compaction(const ol_feature_flags features) {
ol_log_msg(LOG_INFO, "Squishing database.");
ol_squish(db);

char DB_PATH[DB_NAME_SIZE + 1] = {0};
strncpy(DB_PATH, db->path, DB_NAME_SIZE);
char DB_PATH[sizeof(db->path)+1] = {0};
strncpy(DB_PATH, db->path, sizeof(DB_PATH));

ol_close(db);

Expand Down

0 comments on commit 72915f0

Please sign in to comment.