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

libyajl not found. Build script not searching correct directories. #3334

Closed
RooHTaylor opened this issue Jan 29, 2025 · 2 comments
Closed

libyajl not found. Build script not searching correct directories. #3334

RooHTaylor opened this issue Jan 29, 2025 · 2 comments
Labels
3.x Related to ModSecurity version 3.x

Comments

@RooHTaylor
Copy link
Contributor

RooHTaylor commented Jan 29, 2025

Describe the bug

When trying to ./configure --with-yajl YAJL can never be found. If I specify --with-yajl="/usr/include/yajl" it will find the YAJL headers, but still report that YAJL was not found. If I include multiple paths in --with-yajl="" it continues to find nothing.

I tried to uninstall libyajl-dev from my package manager and manually compile yajl from sources. I experieced the same results with any combination of /usr/local/{include,lib} in the path.

After some digging I found that ./build/yajl.m4 tries to use pkg-config to find YAJL first, and then falls back to directory scanning. However, it appears the list of directories to check is stored in YAJL_POSSIBLE_PATHS while the script is passing YAJL_POSSIBLE_LIB_NAMES to CHECK_FOR_YAJL_AT() on line 65.

# If pkg-config did not find anything useful, go over file lookup.
for x in ${YAJL_POSSIBLE_LIB_NAMES}; do
        CHECK_FOR_YAJL_AT(${x})
        if test -n "${YAJL_VERSION}"; then
            break
    fi
done

Reviewing the definition of CHECK_FOR_YAJL_AT() it expects 'path' as the first argumant, and then loops through the YAJL_POSSIBLE_EXTENSIONS and YAJL_POSSIBLE_LIB_NAMES inside the function to search that path.

AC_DEFUN([CHECK_FOR_YAJL_AT], [
    path=$1
    for y in ${YAJL_POSSIBLE_EXTENSIONS}; do
        for z in ${YAJL_POSSIBLE_LIB_NAMES}; do
...

By modifying the loop defined on line 65 to loop over YAJL_POSSIBLE_PATHS instead of YAJL_POSSIBLE_LIB_NAMES and running ./build.sh again, YAJL is found correctly.

Additionally, if multiple directories are provided, for example --with-yajl="<dir1> <dir2>", they are not all searched. Instead they are treated as a single directory. In the yajl.m4 file on line 73 the script checks for --with-yajl with an argument and passes the argument to CHECK_FOR_YAJL_AT() as a path. Instead, it would be optimal to loop over provided paths and search each one.

Logs and dumps

There was no useful log information. The config.log simply reported that YAJL could not be found and/or that sometimes the headers were found, but that YAJL still was not found. There was no indication that paths were being checked at all.

To Reproduce

Steps to reproduce the behavior:

sudo apt install -y libyajl-dev
git clone --recursive [email protected]:owasp-modsecurity/ModSecurity.git
cd ModSecurity
./build.sh
./configure --with-yajl

You can try any combination of paths in --with-yajl and it fails to find it.

Expected behavior

Obviously the expected behaviour is that YAJL should be found if specifying --with-yajl.

Server (please complete the following information):

  • ModSecurity version: 3.0.13
  • OS (and distro): Debian 12.9
@RooHTaylor RooHTaylor added the 3.x Related to ModSecurity version 3.x label Jan 29, 2025
@airween
Copy link
Member

airween commented Jan 29, 2025

Hi @RooHTaylor,

thanks for reporting this.

When I read your comment my first idea was try to build the library without --with-yajl option - but then I saw you tried that.

Yes, that seems like a bug in build system, and if I'm right you successfully solved that issue - would you mind to send a PR to fix that?

RooHTaylor added a commit to RooHTaylor/ModSecurity that referenced this issue Jan 30, 2025
When searching for YAJL during ./configure, pkg-config is checked first,
and then a list of directories is searched if pkg-config bears no fruit.
The previous version of yajl.m4 was looping over YAJL_POSSIBLE_LIB_NAMES
instead of YAJL_POSSIBLE_PATHS and passing the lib name to the
CHECK_FOR_YAJL_AT() function instead of the path. The would lead to YAJL
never being found if pkg-config could not find it.
airween added a commit that referenced this issue Jan 30, 2025
Fix for issue #3334: build not finding YAJL
@airween
Copy link
Member

airween commented Jan 30, 2025

Closing as completed through #3335 - thanks again @RooHTaylor.

@airween airween closed this as completed Jan 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.x Related to ModSecurity version 3.x
Projects
None yet
Development

No branches or pull requests

2 participants