Skip to content

Commit 4b5b8bf

Browse files
committed
Merge tag '1.12.0' into ubuntu-ppa
2 parents 7e5cbbf + a2894be commit 4b5b8bf

File tree

16 files changed

+231
-47
lines changed

16 files changed

+231
-47
lines changed

.github/workflows/codeql-analysis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
- name: Initialize CodeQL
3535
uses: github/codeql-action/init@v3
3636

37-
- run: sudo apt install libipc-run3-perl libipc-system-simple-perl libfile-slurp-perl libfile-which-perl pandoc
37+
- run: sudo apt install libipc-run3-perl pandoc
3838
- run: |
3939
./bootstrap
4040
./configure

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,4 @@ Makefile
4444
Makefile.in
4545
Testing/
4646
install_manifest.txt
47+
build/

CMakeLists.txt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
cmake_minimum_required (VERSION 3.9)
1+
cmake_minimum_required (VERSION 3.9...3.30)
22

33
project(maxminddb
44
LANGUAGES C
5-
VERSION 1.11.0
5+
VERSION 1.12.0
66
)
77
set(MAXMINDDB_SOVERSION 0.0.7)
88
set(CMAKE_C_STANDARD 99)
@@ -13,6 +13,7 @@ if (WIN32)
1313
endif()
1414
option(BUILD_SHARED_LIBS "Build shared libraries (.dll/.so) instead of static ones (.lib/.a)" OFF)
1515
option(BUILD_TESTING "Build test programs" ON)
16+
option(BUILD_FUZZING "Build with fuzzer" OFF)
1617
option(MAXMINDDB_BUILD_BINARIES "Build binaries" ON)
1718
option(MAXMINDDB_INSTALL "Generate the install target" ON)
1819

@@ -154,3 +155,14 @@ if (MAXMINDDB_INSTALL)
154155
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/src/libmaxminddb.pc
155156
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
156157
endif()
158+
159+
# uninstall target
160+
if(NOT TARGET uninstall)
161+
configure_file(
162+
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
163+
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
164+
IMMEDIATE @ONLY)
165+
166+
add_custom_target(uninstall
167+
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
168+
endif()

Changes.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
## 1.12.0 - 2025-01-07
2+
3+
* Fixed memory leaks in `MMDB_open()`. These could happen with invalid
4+
databases or in error situations such as failing to allocate memory. As
5+
part of the fix, `MMDB_get_entry_data_list()` now frees memory it
6+
allocates on additional errors. Previously it failed to clean up when
7+
certain errors occurred. Pull request by pkillarjun. GitHub #356.
8+
* There is now a build target to fuzz the library. Pull request by
9+
pkillarjun. GitHub #357.
10+
* Updated `cmake_minimum_required` to a version range to quiet deprecation
11+
warnings on new CMake versions. Reported by gmou3. GitHub #359.
12+
* The script for generating man pages no longer uses `autodie`. This
13+
eliminates the dependency on `IPC::System::Simple`. Reported by gmou3.
14+
GitHub #359.
15+
* An uninstall target is now included for CMake. Pull request by gmou3.
16+
GitHub #362.
17+
118
## 1.11.0 - 2024-08-21
219

320
* When building with CMake, the man pages will now be generated and

NOTICE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright 2013-2024 MaxMind, Inc.
1+
Copyright 2013-2025 MaxMind, Inc.
22

33
Licensed under the Apache License, Version 2.0 (the "License");
44
you may not use this file except in compliance with the License.

README.fuzzing.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Fuzzing libmaxminddb
2+
3+
These tests are only meant to be run on GNU/Linux.
4+
5+
## Build maxminddb fuzzer using libFuzzer.
6+
7+
### Export flags for fuzzing.
8+
9+
Note that in `CFLAGS` and `CXXFLAGS`, any type of sanitizers can be added.
10+
11+
- [AddressSanitizer](https://clang.llvm.org/docs/AddressSanitizer.html),
12+
[ThreadSanitizer](https://clang.llvm.org/docs/ThreadSanitizer.html),
13+
[MemorySanitizer](https://clang.llvm.org/docs/MemorySanitizer.html),
14+
[UndefinedBehaviorSanitizer](https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html),
15+
[LeakSanitizer](https://clang.llvm.org/docs/LeakSanitizer.html).
16+
17+
```shell
18+
$ export CC=clang
19+
$ export CXX=clang++
20+
$ export CFLAGS="-g -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -fsanitize=address,undefined -fsanitize=fuzzer-no-link"
21+
$ export CXXFLAGS="-g -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -fsanitize=address,undefined -fsanitize=fuzzer-no-link"
22+
$ export LIB_FUZZING_ENGINE="-fsanitize=fuzzer"
23+
```
24+
25+
### Build maxminddb for fuzzing.
26+
27+
```shell
28+
$ mkdir -p build && cd build
29+
$ cmake -DBUILD_FUZZING=ON ../.
30+
$ cmake --build . -j$(nproc)
31+
```
32+
33+
### Running fuzzer.
34+
35+
```shell
36+
$ mkdir -p fuzz_mmdb_seed fuzz_mmdb_seed_corpus
37+
$ find ../t/maxmind-db/test-data/ -type f -size -4k -exec cp {} ./fuzz_mmdb_seed_corpus/ \;
38+
$ ./t/fuzz_mmdb fuzz_mmdb_seed/ fuzz_mmdb_seed_corpus/
39+
```
40+
41+
Here is more information about [LibFuzzer](https://llvm.org/docs/LibFuzzer.html).

README.md

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,13 @@ structure.
3030

3131
To install this code, run the following commands:
3232

33-
$ ./configure
34-
$ make
35-
$ make check
36-
$ sudo make install
37-
$ sudo ldconfig
33+
```bash
34+
./configure
35+
make
36+
make check
37+
sudo make install
38+
sudo ldconfig
39+
```
3840

3941
You can skip the `make check` step but it's always good to know that tests are
4042
passing on your platform.
@@ -47,8 +49,10 @@ you may need to add the `lib` directory in your `prefix` to your library path.
4749
On most Linux distributions when using the default prefix (`/usr/local`), you
4850
can do this by running the following commands:
4951

50-
$ sudo sh -c "echo /usr/local/lib >> /etc/ld.so.conf.d/local.conf"
51-
$ ldconfig
52+
```bash
53+
sudo sh -c "echo /usr/local/lib >> /etc/ld.so.conf.d/local.conf"
54+
ldconfig
55+
```
5256

5357
## From a GitHub "Source Code" Archive / Git Repo Clone (Achtung!)
5458

@@ -65,7 +69,9 @@ in addition to `make` and a compiler.
6569

6670
You can clone this repository and build it by running:
6771

68-
$ git clone --recursive https://github.com/maxmind/libmaxminddb
72+
```bash
73+
git clone --recursive https://github.com/maxmind/libmaxminddb
74+
```
6975

7076
After cloning, run `./bootstrap` from the `libmaxminddb` directory and then
7177
follow the instructions for installing from a named release tarball as
@@ -76,39 +82,57 @@ described above.
7682
We provide a CMake build script. This is primarily targeted at Windows users,
7783
but it can be used in other circumstances where the Autotools script does not
7884
work.
79-
80-
$ mkdir build && cd build
81-
$ cmake ..
82-
$ cmake --build .
83-
$ ctest -V .
84-
$ cmake --build . --target install
85+
86+
```bash
87+
cmake -B build
88+
cd build/
89+
cmake --build .
90+
ctest -V .
91+
cmake --build . --target install
92+
```
8593

8694
When building with Visual Studio, you may build a multithreaded (MT/MTd)
8795
runtime library, using the `MSVC_STATIC_RUNTIME` setting:
8896

89-
$ cmake -DMSVC_STATIC_RUNTIME=ON -DBUILD_SHARED_LIBS=OFF ..
97+
```bash
98+
cmake -DMSVC_STATIC_RUNTIME=ON -DBUILD_SHARED_LIBS=OFF ..
99+
```
100+
101+
We also include a CMake `uninstall` target:
102+
103+
```bash
104+
cmake --build . --target uninstall
105+
```
90106

91107
## On Ubuntu via PPA
92108

93109
MaxMind provides a PPA for recent version of Ubuntu. To add the PPA to your
94110
APT sources, run:
95111

96-
$ sudo add-apt-repository ppa:maxmind/ppa
112+
```bash
113+
sudo add-apt-repository ppa:maxmind/ppa
114+
```
97115

98116
Then install the packages by running:
99117

100-
$ sudo apt update
101-
$ sudo apt install libmaxminddb0 libmaxminddb-dev mmdb-bin
118+
```bash
119+
sudo apt update
120+
sudo apt install libmaxminddb0 libmaxminddb-dev mmdb-bin
121+
```
102122

103123
## On macOS via Homebrew or MacPorts
104124

105125
You can install libmaxminddb on macOS using [Homebrew](https://brew.sh):
106126

107-
$ brew install libmaxminddb
127+
```bash
128+
brew install libmaxminddb
129+
```
108130

109131
Or with [MacPorts](https://ports.macports.org/port/libmaxminddb):
110132

111-
$ sudo port install libmaxminddb
133+
```bash
134+
sudo port install libmaxminddb
135+
```
112136

113137
# Requirements
114138

@@ -126,7 +150,7 @@ Use `make safedist` to check the resulting tarball.
126150

127151
# Copyright and License
128152

129-
Copyright 2013-2024 MaxMind, Inc.
153+
Copyright 2013-2025 MaxMind, Inc.
130154

131155
Licensed under the Apache License, Version 2.0 (the "License");
132156
you may not use this file except in compliance with the License.

cmake_uninstall.cmake.in

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
if(NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt")
2+
message(FATAL_ERROR "Cannot find install manifest: @CMAKE_BINARY_DIR@/install_manifest.txt")
3+
endif()
4+
5+
file(READ "@CMAKE_BINARY_DIR@/install_manifest.txt" files)
6+
string(REGEX REPLACE "\n" ";" files "${files}")
7+
foreach(file ${files})
8+
message(STATUS "Uninstalling $ENV{DESTDIR}${file}")
9+
if(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
10+
execute_process(
11+
COMMAND "@CMAKE_COMMAND@" -E remove "$ENV{DESTDIR}${file}"
12+
OUTPUT_VARIABLE rm_out
13+
RESULT_VARIABLE rm_retval
14+
)
15+
if(NOT "${rm_retval}" STREQUAL 0)
16+
message(FATAL_ERROR "Problem when removing $ENV{DESTDIR}${file}")
17+
endif()
18+
else(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
19+
message(STATUS "File $ENV{DESTDIR}${file} does not exist.")
20+
endif()
21+
endforeach()

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Process this file with autoconf to produce a configure script.
33

44
AC_PREREQ([2.63])
5-
AC_INIT([libmaxminddb], [1.11.0], [[email protected]])
5+
AC_INIT([libmaxminddb], [1.12.0], [[email protected]])
66
AC_CONFIG_SRCDIR([include/maxminddb.h])
77
AC_CONFIG_HEADERS([config.h include/maxminddb_config.h])
88

dev-bin/make-man-pages.pl

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,18 @@
22

33
use strict;
44
use warnings;
5-
use autodie qw( :all );
65

76
use FindBin qw( $Bin );
87

98
use File::Path qw( mkpath );
10-
use File::Slurp qw( edit_file read_file );
11-
use File::Which qw( which );
129

1310
sub main {
1411
my $target = shift || "$Bin/..";
1512

1613
my @translators = qw ( lowdown pandoc );
1714
my $translator;
1815
foreach my $p (@translators) {
19-
if ( defined which($p) ) {
16+
if ( _which($p) ) {
2017
$translator = $p;
2118
last;
2219
}
@@ -33,6 +30,14 @@ sub main {
3330
_make_man( $translator, $target, 'mmdblookup', 1 );
3431
}
3532

33+
sub _which {
34+
my $program = shift;
35+
for my $path ( split /:/, $ENV{PATH} ) {
36+
return 1 if -x "$path/$program";
37+
}
38+
return 0;
39+
}
40+
3641
sub _make_man {
3742
my $translator = shift;
3843
my $target = shift;
@@ -54,7 +59,7 @@ sub _make_man {
5459
'-M', "section:$section",
5560
$input,
5661
'-o', $output,
57-
);
62+
) == 0 or die "Failed to run pandoc: $?";
5863
_pandoc_postprocess($output);
5964
}
6065
elsif ( $translator eq 'lowdown' ) {
@@ -67,18 +72,27 @@ sub _make_man {
6772
'-M', "section:$section",
6873
$input,
6974
'-o', $output,
70-
);
75+
) == 0 or die "Failed to run lowdown: $?";
7176
}
7277
}
7378

7479
sub _make_lib_man_links {
7580
my $target = shift;
7681

77-
my $header = read_file("$Bin/../include/maxminddb.h");
82+
open my $header_fh, '<', "$Bin/../include/maxminddb.h"
83+
or die "Failed to open header file: $!";
84+
my $header = do { local $/; <$header_fh> };
85+
86+
die "Error reading file header file: $!" unless defined $header;
87+
88+
close $header_fh or die "Failed to close header file: $!";
89+
7890
for my $proto ( $header =~ /^ *extern.+?(MMDB_\w+)\(/gsm ) {
79-
open my $fh, '>', "$target/man/man3/$proto.3";
80-
print {$fh} ".so man3/libmaxminddb.3\n";
81-
close $fh;
91+
open my $fh, '>', "$target/man/man3/$proto.3"
92+
or die "Failed to open file: $!";
93+
print {$fh} ".so man3/libmaxminddb.3\n"
94+
or die "Failed to write to file: $!";
95+
close $fh or die "Failed to close file: $!";
8296
}
8397
}
8498

@@ -87,13 +101,20 @@ sub _make_lib_man_links {
87101
sub _pandoc_postprocess {
88102
my $file = shift;
89103

90-
edit_file(
91-
sub {
92-
s/^\.IP\n\.nf/.IP "" 4\n.nf/gm;
93-
s/(Automatically generated by Pandoc)(.+)$/$1/m;
94-
},
95-
$file
96-
);
104+
open my $fh, '<', $file or die "Failed to open man file for reading: $!";
105+
my @lines = <$fh>;
106+
die "Error when reading man page: $!" if $!;
107+
108+
close $fh or die "Failed to close file: $!";
109+
110+
for my $line (@lines) {
111+
$line =~ s/^\.IP\n\.nf/.IP "" 4\n.nf/gm;
112+
$line =~ s/(Automatically generated by Pandoc)(.+)$/$1/m;
113+
}
114+
115+
open $fh, '>', $file or die "Failed to open file for writing: $!";
116+
print $fh @lines or die "Failed to write to file: $!";
117+
close $fh or die "Failed to close file: $!";
97118
}
98119

99120
main(shift);

0 commit comments

Comments
 (0)