pgagroal icon indicating copy to clipboard operation
pgagroal copied to clipboard

Cannot compile after vault implementation has been merged

Open fluca1978 opened this issue 10 months ago • 4 comments

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 avatar Apr 04 '24 09:04 fluca1978

@ashu3103 can you check this?

fluca1978 avatar Apr 04 '24 09:04 fluca1978

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

jesperpedersen avatar Apr 04 '24 10:04 jesperpedersen

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

ashu3103 avatar Apr 04 '24 11:04 ashu3103

@fluca1978 Close ?

jesperpedersen avatar May 06 '24 16:05 jesperpedersen

Compile for me, I'm closing the issue.

fluca1978 avatar May 13 '24 09:05 fluca1978