Skip to content

Sanitize printf format specifiers#21

Open
urbasus wants to merge 2 commits intoopenslp-org:masterfrom
urbasus:printf-sanitize
Open

Sanitize printf format specifiers#21
urbasus wants to merge 2 commits intoopenslp-org:masterfrom
urbasus:printf-sanitize

Conversation

@urbasus
Copy link
Contributor

@urbasus urbasus commented Jan 5, 2026

  • Add have incorrect printf format specifier-parameter pairs generate compile-time warnings for printf-like functions.
    • SLPDLog and SLPDFatal.
  • Fix warnings.

Warnings fixed, x64:

gcc -DHAVE_CONFIG_H -I. -I.. -I../common -I../libslpattr -I. -I../libslp -DETCDIR=\"/usr/local/etc\" -DVARDIR=\"/usr/local/var\"  -DLINUX  -g -O2 -Wall  -O2 -MT slpd_log.o -MD -MP -MF .deps/slpd_log.Tpo -c -o slpd_log.o slpd_log.c
slpd_log.c: In function ‘SLPDLogMessageInternals’:
slpd_log.c:356:26: warning: format ‘%i’ expects argument of type ‘int’, but argument 2 has type ‘size_t’ {aka ‘long unsigned int’} [-Wformat=]
  356 |    SLPDLog("   length = %i\n", message->header.length);
      |                         ~^     ~~~~~~~~~~~~~~~~~~~~~~
      |                          |                    |
      |                          int                  size_t {aka long unsigned int}
      |                         %li
slpd_log.c: In function ‘SLPDLogParseWarning’:
slpd_log.c:584:29: warning: format ‘%i’ expects argument of type ‘int’, but argument 2 has type ‘long int’ [-Wformat=]
  584 |    SLPDLog("message size = %i\n",buf->end - buf->start);
      |                            ~^    ~~~~~~~~~~~~~~~~~~~~~
      |                             |             |
      |                             int           long int
      |                            %li

x86:

gcc -DHAVE_CONFIG_H -I. -I.. -I../common -I../libslpattr -I. -I../libslp -DETCDIR=\"/usr/local/etc\" -DVARDIR=\"/usr/local/var\"  -DLINUX  -m32 -MT slpd_database.o -MD -MP -MF .deps/slpd_database.Tpo -c -o slpd_database.o slpd_database.c
slpd_database.c: In function ‘SLPDDatabaseReg’:
slpd_database.c:432:47: warning: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 3 has type ‘unsigned int’ [-Wformat=]
  432 |          fprintf(stderr, "iface_addr malloc(%lu) failed\n",
      |                                             ~~^
      |                                               |
      |                                               long unsigned int
      |                                             %u
  433 |             slp_max_ifaces * sizeof(struct sockaddr_storage));
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                            |
      |                            unsigned int
slpd_database.c:440:47: warning: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 3 has type ‘unsigned int’ [-Wformat=]
  440 |          fprintf(stderr, "bcast_addr malloc(%lu) failed\n",
      |                                             ~~^
      |                                               |
      |                                               long unsigned int
      |                                             %u
  441 |             slp_max_ifaces * sizeof(struct sockaddr_storage));
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                            |
      |                            unsigned int

@urbasus urbasus changed the title Add GCC/Clang printf sanitization to SLPDLog Sanitize printf format specifiers Jan 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant