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

Fix management #336

Closed
wants to merge 3 commits into from
Closed

Fix management #336

wants to merge 3 commits into from

Conversation

fluca1978
Copy link
Collaborator

No description provided.

@jesperpedersen
Copy link
Collaborator

src/libpgagroal/configuration.c: In function ‘to_string’:
src/libpgagroal/configuration.c:3816:42: warning: ‘%s’ directive output may be truncated writing between 1 and 128 bytes into a region of size 127 [-Wformat-truncation=]
 3816 |          snprintf(where, MISC_LENGTH, "\"%s\"", value);
      |                                          ^~
src/libpgagroal/configuration.c:3816:10: note: ‘snprintf’ output between 4 and 131 bytes into a destination of size 128
 3816 |          snprintf(where, MISC_LENGTH, "\"%s\"", value);
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/libpgagroal/configuration.c:3812:41: warning: ‘%s’ directive output may be truncated writing between 1 and 128 bytes into a region of size 127 [-Wformat-truncation=]
 3812 |          snprintf(where, MISC_LENGTH, "'%s'", value);
      |                                         ^~
src/libpgagroal/configuration.c:3812:10: note: ‘snprintf’ output between 4 and 131 bytes into a destination of size 128
 3812 |          snprintf(where, MISC_LENGTH, "'%s'", value);
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/libpgagroal/configuration.c:3821:39: warning: ‘snprintf’ output may be truncated before the last format character [-Wformat-truncation=]
 3821 |       snprintf(where, MISC_LENGTH, "%s", value);
      |                                       ^
src/libpgagroal/configuration.c:3821:7: note: ‘snprintf’ output between 1 and 129 bytes into a destination of size 128
 3821 |       snprintf(where, MISC_LENGTH, "%s", value);
      |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Can you fix these in this PR as well ?

@fluca1978
Copy link
Collaborator Author

fluca1978 commented Dec 13, 2022 via email

@jesperpedersen
Copy link
Collaborator

GCC 12

src/libpgagroal/configuration.c: In function ‘to_string’:
src/libpgagroal/configuration.c:3816:46: warning: ‘%s’ directive output may be truncated writing between 1 and 128 bytes into a region of size 124 [-Wformat-truncation=]
 3816 |          snprintf(where, MISC_LENGTH - 3, "\"%s\"", value);
      |                                              ^~
src/libpgagroal/configuration.c:3816:10: note: ‘snprintf’ output between 4 and 131 bytes into a destination of size 125
 3816 |          snprintf(where, MISC_LENGTH - 3, "\"%s\"", value);
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/libpgagroal/configuration.c:3812:45: warning: ‘%s’ directive output may be truncated writing between 1 and 128 bytes into a region of size 124 [-Wformat-truncation=]
 3812 |          snprintf(where, MISC_LENGTH - 3, "'%s'", value);
      |                                             ^~
src/libpgagroal/configuration.c:3812:10: note: ‘snprintf’ output between 4 and 131 bytes into a destination of size 125
 3812 |          snprintf(where, MISC_LENGTH - 3, "'%s'", value);
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/libpgagroal/configuration.c:3821:41: warning: ‘%s’ directive output may be truncated writing up to 128 bytes into a region of size 127 [-Wformat-truncation=]
 3821 |       snprintf(where, MISC_LENGTH - 1, "%s", value);
      |                                         ^~
src/libpgagroal/configuration.c:3821:7: note: ‘snprintf’ output between 1 and 129 bytes into a destination of size 127
 3821 |       snprintf(where, MISC_LENGTH - 1, "%s", value);
      |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

clang 15

src/libpgagroal/configuration.c:3578:7: error: statement requires expression of integer type ('atomic_schar' (aka '_Atomic(signed char)') invalid)
      switch (state)
      ^       ~~~~~

@jesperpedersen
Copy link
Collaborator

You could use pgagroal_append() as well...

@brettgoss
Copy link

@jesperpedersen I'm getting those make errors as well on the latest master after you introduced 61d60f2. I don't think they're specific to this branch.

There doesn't seem to be an existing issue for this that I could find, but dropping 61d60f2 allows me to build pgagroal again.

@jesperpedersen
Copy link
Collaborator

@brettgoss Yeah, they are on master with new functionality in the up-coming 1.6 release. They will be fixed before the release = for now it is a pointer to @fluca1978 with his work

@jesperpedersen
Copy link
Collaborator

We may have to compile with both gcc and clang in order to catch as many errors as we can...

@jesperpedersen jesperpedersen added the enhancement Improvement to an existing feature label Dec 13, 2022
@fluca1978
Copy link
Collaborator Author

We could apply, in the meantime, 7b6f7ee to master since it should fix the compiler errors.

@jesperpedersen
Copy link
Collaborator

It reported issues as well - see #336 (comment)

fluca1978 added a commit to fluca1978/pgagroal that referenced this pull request Dec 14, 2022
As reported in CI test failures
<agroal#336 (comment)>
and
<agroal#336 (comment)>
the system does not compile under GCC 12 with `-Werror` option.

This commit fixes the string length problem reported by gcc.

Close agroal#337
…g key

This commit fixes the problem that arise when the user specifies
a global key (i.e., one that does not exist in the section
[pgagroal]) to the subcommand `config-get`.
If the key is not known, an error is thrown.

Close agroal#334
This commit introduces a few constants to indicate if the
communication over the management socket has failed due to a
connection error or because the data received is not valid.
So far, only `config-get` returns a different value to indicate
invalid data over the socket, but other commands can take advanatge of
this too.

The `pgagroal-cli` main loop has been refactored to distinguish the
new cases, and now it prints the "connection error" message only when
the low level function reports such an error.

All the functions now return a specific value among those defined.

Close agroal#335
fluca1978 added a commit to fluca1978/pgagroal that referenced this pull request Dec 14, 2022
As reported in CI test failures
<agroal#336 (comment)>
and
<agroal#336 (comment)>
the system does not compile under GCC 12 with `-Werror` option.

This commit fixes the string length problem reported by gcc.

Close agroal#337
@jesperpedersen
Copy link
Collaborator

Personally, I would nuke all s[n]print usage and use pgagroal_append instead...

As reported in CI test failures
<agroal#336 (comment)>
and
<agroal#336 (comment)>
the system does not compile under GCC 12 with `-Werror` option.

This commit fixes the string length problem reported by gcc.
The `to_string` internal method used to get a stringify value
of a configuration parameter has changed so that now accepts a buffer
size. Such size indicates the max length of the destinatiojn buffer
and allows the function to do some more checks about what to copy onto
the buffer.

Close agroal#337
@fluca1978
Copy link
Collaborator Author

@jesperpedersen I'm not able to find any pgagroal_append function, there is static append function into the prometheus stuff, I suspect you are referring to that.
In the meanwhile I managed to change the to_string function adding a size parameter so that it is now possible to manage and prevent overflows. I've also finally found a way to compile with gcc12, so we are now fine with this PR.

jesperpedersen pushed a commit that referenced this pull request Dec 15, 2022
As reported in CI test failures
<#336 (comment)>
and
<#336 (comment)>
the system does not compile under GCC 12 with `-Werror` option.

This commit fixes the string length problem reported by gcc.
The `to_string` internal method used to get a stringify value
of a configuration parameter has changed so that now accepts a buffer
size. Such size indicates the max length of the destinatiojn buffer
and allows the function to do some more checks about what to copy onto
the buffer.

Close #337
@jesperpedersen
Copy link
Collaborator

I fixed the atomic part, squashed and merged.

Thanks for your contribution !

@jesperpedersen
Copy link
Collaborator

I made append public, and use it to fix the process title warning.

CI is happy now with both gcc and clang

@vikingUnet
Copy link

Hello!
The same error:

/root/pgagroal/src/admin.c:535:39: error: ‘__builtin___snprintf_chk’ output may be truncated before the last format character [-Werror=format-truncation=]
  535 |    snprintf(line, sizeof(line), "%s:%s", username, encoded);
      |                                       ^
In file included from /usr/include/stdio.h:867,
                 from /usr/include/openssl/crypto.h:20,
                 from /usr/include/openssl/comp.h:16,
                 from /usr/include/openssl/ssl.h:17,
                 from /root/pgagroal/src/include/pgagroal.h:45,
                 from /root/pgagroal/src/admin.c:30:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:67:10: note: ‘__builtin___snprintf_chk’ output 2 or more bytes (assuming 129) into a destination of size 128
   67 |   return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   68 |        __bos (__s), __fmt, __va_arg_pack ());
      |        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/root/pgagroal/src/admin.c: In function ‘update_user’:
/root/pgagroal/src/admin.c:704:45: error: ‘__builtin___snprintf_chk’ output may be truncated before the last format character [-Werror=format-truncation=]
  704 |          snprintf(line, sizeof(line), "%s:%s", username, encoded);
      |                                             ^
In file included from /usr/include/stdio.h:867,
                 from /usr/include/openssl/crypto.h:20,
                 from /usr/include/openssl/comp.h:16,
                 from /usr/include/openssl/ssl.h:17,
                 from /root/pgagroal/src/include/pgagroal.h:45,
                 from /root/pgagroal/src/admin.c:30:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:67:10: note: ‘__builtin___snprintf_chk’ output 2 or more bytes (assuming 129) into a destination of size 128
   67 |   return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   68 |        __bos (__s), __fmt, __va_arg_pack ());
      |        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
make[2]: *** [src/CMakeFiles/pgagroal-admin-bin.dir/build.make:63: src/CMakeFiles/pgagroal-admin-bin.dir/admin.c.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:148: src/CMakeFiles/pgagroal-admin-bin.dir/all] Error 2
make: *** [Makefile:152: all] Error 2

@jesperpedersen
Copy link
Collaborator

@vikingUnet What is your compiler version ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvement to an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants