[Libwebsockets] compile problem and fix (syslog and a typo)

"Andy Green (林安廸)" andy at warmcat.com
Sat Jan 19 13:08:42 CET 2013


On 19/01/13 19:46, the mail apparently from Edwin van den Oetelaar included:
> Hello Andy and other folks,
>
> Today this happened, I noticed a typo and a problem calling syslog()
>
> libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I.. -Wall -std=gnu99
> -pedantic -g -rdynamic -fPIC -Werror -c
> -DINSTALL_DATADIR=\"/usr/local/share\"
> -DLWS_OPENSSL_CLIENT_CERTS=\"/etc/pki/tls/certs/\" -g -O2 -D_DEBUG -MT
> libwebsockets_la-libwebsockets.lo -MD -MP -MF
> .deps/libwebsockets_la-libwebsockets.Tpo -c libwebsockets.c  -fPIC
> -DPIC -o .libs/libwebsockets_la-libwebsockets.o
> cc1: warnings being treated as errors
> libwebsockets.c: In function ‘lwsl_emit_syslog’:
> libwebsockets.c:2207: error: format not a string literal and no format arguments

Oh that was a bad mistake, it can be security problem even.  But when I 
built it, I don't get a warning (which would also be promoted to errors 
here).  Thanks for pointing it out.

http://git.libwebsockets.org/cgi-bin/cgit/libwebsockets/commit/?id=f6eeabc749fbd8f1f2250797410c82134bcf042c

It seems like a continuous stream of little dings coming but this 
strategy of turning on and enforcing max warnings for everyone, and 
forcing fixes for whatever is coming at the user has really improved the 
code quality / portability.

> here is a fix
>
> diff --git a/lib/libwebsockets.c b/lib/libwebsockets.c
> index 6ae44c4..063b673 100644
> --- a/lib/libwebsockets.c
> +++ b/lib/libwebsockets.c
> @@ -1473,7 +1473,7 @@ libwebsocket_create_context(int port, const char *interf,
>                  free(context);
>                  return NULL;
>          }
> -       context->lws_lookup = (struct libwebsocket
> **)malloc(sizeof(struct libwebsocke *) * context->max_fds);
> +       context->lws_lookup = (struct libwebsocket
> **)malloc(sizeof(struct libwebsocket *) * context->max_fds);
>          if (context->lws_lookup == NULL) {

I don't understand how that managed to happen, I built just before 
pushing last time.  But it evidently did happen, thanks for the fix.

-Andy

>                  lwsl_err("Unable to allocate lws_lookup array for %d
> connections\n", context->max_fds);
>                  free(context->fds);
> @@ -2204,7 +2204,7 @@ void lwsl_emit_syslog(int level, const char *line)
>                  syslog_level = LOG_INFO;
>                  break;
>          }
> -       syslog(syslog_level, line);
> +       syslog(syslog_level, "%s", line);
>   }
>
>   void _lws_log(int filter, const char *format, ...)
>
> ===========
> Greetings,
> Edwin van den Oetelaar
>




More information about the Libwebsockets mailing list