From 72915f0d484b580464317d62f290cc920814b097 Mon Sep 17 00:00:00 2001 From: Kyle Terry Date: Thu, 23 Apr 2020 21:54:49 -0700 Subject: [PATCH] fixes the builds for liboleg and the frontend - 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 --- .gitignore | 1 - .travis.yml | 42 +++++++++++++++----------- Makefile | 2 +- README.md | 2 +- {frontend => cmd/olegdb}/dispatcher.go | 3 +- {frontend => cmd/olegdb}/main.go | 3 +- {frontend => cmd/olegdb}/operations.go | 2 +- go.mod | 3 ++ go.sum | 2 ++ include/oleg.h | 6 ++-- {frontend => pkg}/goleg/goleg_test.go | 2 +- {frontend => pkg}/goleg/highlevel.go | 0 {frontend => pkg}/goleg/wrapper.go | 0 src/test.c | 16 +++++----- 14 files changed, 48 insertions(+), 36 deletions(-) rename {frontend => cmd/olegdb}/dispatcher.go (98%) rename {frontend => cmd/olegdb}/main.go (98%) rename {frontend => cmd/olegdb}/operations.go (99%) create mode 100644 go.mod create mode 100644 go.sum rename {frontend => pkg}/goleg/goleg_test.go (97%) rename {frontend => pkg}/goleg/highlevel.go (100%) rename {frontend => pkg}/goleg/wrapper.go (100%) diff --git a/.gitignore b/.gitignore index f919558..36c5075 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,5 @@ *.swo *.swp -olegdb *.o *.dump data diff --git a/.travis.yml b/.travis.yml index 9617a07..367e5e8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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=" diff --git a/Makefile b/Makefile index 8c3d119..149efdf 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/README.md b/README.md index bfe161b..4b9b4d4 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ Dependencies ============ * A healthy fear of the end -* Go (>= 1.1) +* Go (>= 1.14) Installation ============ diff --git a/frontend/dispatcher.go b/cmd/olegdb/dispatcher.go similarity index 98% rename from frontend/dispatcher.go rename to cmd/olegdb/dispatcher.go index 560fb6b..8cf2fca 100644 --- a/frontend/dispatcher.go +++ b/cmd/olegdb/dispatcher.go @@ -1,10 +1,11 @@ package main import ( - "./goleg" "io/ioutil" "net/http" "strings" + + "github.com/infoforcefeed/olegdb/pkg/goleg" ) type Operation struct { diff --git a/frontend/main.go b/cmd/olegdb/main.go similarity index 98% rename from frontend/main.go rename to cmd/olegdb/main.go index 3a0c417..db169b0 100644 --- a/frontend/main.go +++ b/cmd/olegdb/main.go @@ -1,7 +1,6 @@ package main import ( - "./goleg" "encoding/json" "flag" "fmt" @@ -10,6 +9,8 @@ import ( "net/http" "os" "os/signal" + + "github.com/infoforcefeed/olegdb/pkg/goleg" ) type Config struct { diff --git a/frontend/operations.go b/cmd/olegdb/operations.go similarity index 99% rename from frontend/operations.go rename to cmd/olegdb/operations.go index 10381f8..ba74465 100644 --- a/frontend/operations.go +++ b/cmd/olegdb/operations.go @@ -23,7 +23,7 @@ const ( OpCursorPrev = "._prev" OpPrefixMatch = "._match" OpBulkUnjar = "_bulk_unjar" - OpSquish = "_squish" + OpSquish = "_squish" ) func httpGet(w http.ResponseWriter, op Operation) *HTTPError { diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..5455f71 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module github.com/infoforcefeed/olegdb + +go 1.14 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..c6aed09 --- /dev/null +++ b/go.sum @@ -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= diff --git a/include/oleg.h b/include/oleg.h index d829af3..ccd7137 100644 --- a/include/oleg.h +++ b/include/oleg.h @@ -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; diff --git a/frontend/goleg/goleg_test.go b/pkg/goleg/goleg_test.go similarity index 97% rename from frontend/goleg/goleg_test.go rename to pkg/goleg/goleg_test.go index 2c24770..43bf698 100644 --- a/frontend/goleg/goleg_test.go +++ b/pkg/goleg/goleg_test.go @@ -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]) } } } diff --git a/frontend/goleg/highlevel.go b/pkg/goleg/highlevel.go similarity index 100% rename from frontend/goleg/highlevel.go rename to pkg/goleg/highlevel.go diff --git a/frontend/goleg/wrapper.go b/pkg/goleg/wrapper.go similarity index 100% rename from frontend/goleg/wrapper.go rename to pkg/goleg/wrapper.go diff --git a/src/test.c b/src/test.c index 748b831..7fea4c1 100644 --- a/src/test.c +++ b/src/test.c @@ -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); @@ -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. */ @@ -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);