agroal / pgagroal

High-performance connection pool for PostgreSQL
https://agroal.github.io/pgagroal/
BSD 3-Clause "New" or "Revised" License
684 stars 61 forks source link

Cannot compile after vault implementation has been merged #436

Closed fluca1978 closed 6 months ago

fluca1978 commented 8 months ago

Related to #407 and commit 5dcfb897d90b78c622a38855ae6ffd5cb2630d9f on Rocky Linux 8 with gcc 11.4.1:

[ 71%] Linking C shared library libpgagroal.so
[ 71%] Built target pgagroal
[ 75%] Building C object src/CMakeFiles/pgagroal-vault-bin.dir/vault.c.o
/home/luca/pgagroal/src/vault.c: In function ‘router.constprop’:
/home/luca/pgagroal/src/vault.c:174:41: error: ‘%s’ directive output may be truncated writing up to 1024 bytes into a region of size 977 [-Werror=format-truncation=]
  174 |       snprintf(response, response_size, "HTTP/1.1 200 OK\r\n"
      |                                         ^~~~~~~~~~~~~~~~~~~~~
......
  178 |                password);
      |                ~~~~~~~~                  
/home/luca/pgagroal/src/vault.c:177:17: note: format string is defined here
  177 |                "%s\r\n",
      |                 ^~
/home/luca/pgagroal/src/vault.c:174:7: note: ‘snprintf’ output between 50 and 1074 bytes into a destination of size 1024
  174 |       snprintf(response, response_size, "HTTP/1.1 200 OK\r\n"
      |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  175 |                "Content-Type: text/plain\r\n"
      |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  176 |                "\r\n\r\n"
      |                ~~~~~~~~~~
  177 |                "%s\r\n",
      |                ~~~~~~~~~
  178 |                password);
      |                ~~~~~~~~~
cc1: all warnings being treated as errors
make[2]: *** [src/CMakeFiles/pgagroal-vault-bin.dir/build.make:76: src/CMakeFiles/pgagroal-vault-bin.dir/vault.c.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:150: src/CMakeFiles/pgagroal-vault-bin.dir/all] Error 2
make: *** [Makefile:156: all] Error 2

Is my compiler too strict?

fluca1978 commented 8 months ago

@ashu3103 can you check this?

jesperpedersen commented 8 months ago

Otherwise, switch it to an output parameter, and use the pgagroal_append() functions...

ashu3103 commented 8 months ago

Related to #407 and commit 5dcfb89 on Rocky Linux 8 with gcc 11.4.1:

[ 71%] Linking C shared library libpgagroal.so
[ 71%] Built target pgagroal
[ 75%] Building C object src/CMakeFiles/pgagroal-vault-bin.dir/vault.c.o
/home/luca/pgagroal/src/vault.c: In function ‘router.constprop’:
/home/luca/pgagroal/src/vault.c:174:41: error: ‘%s’ directive output may be truncated writing up to 1024 bytes into a region of size 977 [-Werror=format-truncation=]
  174 |       snprintf(response, response_size, "HTTP/1.1 200 OK\r\n"
      |                                         ^~~~~~~~~~~~~~~~~~~~~
......
  178 |                password);
      |                ~~~~~~~~                  
/home/luca/pgagroal/src/vault.c:177:17: note: format string is defined here
  177 |                "%s\r\n",
      |                 ^~
/home/luca/pgagroal/src/vault.c:174:7: note: ‘snprintf’ output between 50 and 1074 bytes into a destination of size 1024
  174 |       snprintf(response, response_size, "HTTP/1.1 200 OK\r\n"
      |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  175 |                "Content-Type: text/plain\r\n"
      |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  176 |                "\r\n\r\n"
      |                ~~~~~~~~~~
  177 |                "%s\r\n",
      |                ~~~~~~~~~
  178 |                password);
      |                ~~~~~~~~~
cc1: all warnings being treated as errors
make[2]: *** [src/CMakeFiles/pgagroal-vault-bin.dir/build.make:76: src/CMakeFiles/pgagroal-vault-bin.dir/vault.c.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:150: src/CMakeFiles/pgagroal-vault-bin.dir/all] Error 2
make: *** [Makefile:156: all] Error 2

Is my compiler too strict?

The issue is that I have declared the response of size 1024 bytes and the MAX_PASSWORD_LENGTH is itself 1024 characters, so the compiler is showing the edge case where the password length is 1024 characters long and so the response buffer will contain invalid results.

Will incorporate pgagroal_append() solutions in this

Thanks

jesperpedersen commented 6 months ago

@fluca1978 Close ?

fluca1978 commented 6 months ago

Compile for me, I'm closing the issue.