[Xenomai-git] Philippe Gerum : cobalt/kernel: generalize use of safe *snprintf()
Module: xenomai-forge Branch: rtdm-api-waitqueues Commit: f8490220177c0c007ae98dac4a956ecd0de89120 URL: http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=f8490220177c0c007ae98dac4a956ecd0de89120 Author: Philippe Gerum Date: Thu Apr 17 11:44:08 2014 +0200 cobalt/kernel: generalize use of safe *snprintf() Make sure to have the destination string null-terminated on character overflow. --- include/cobalt/kernel/Makefile.am |1 + include/cobalt/kernel/Makefile.in |1 + include/cobalt/kernel/ancillaries.h | 42 +++ include/cobalt/kernel/assert.h |1 + include/cobalt/kernel/rtdm/driver.h |1 + kernel/cobalt/assert.c |2 +- kernel/cobalt/clock.c |2 +- kernel/cobalt/heap.c|4 +-- kernel/cobalt/intr.c|2 +- kernel/cobalt/posix/sem.c |2 +- kernel/cobalt/posix/thread.c|2 +- kernel/cobalt/rtdm/proc.c |2 +- kernel/cobalt/sched-quota.c |6 +++-- kernel/cobalt/sched-rt.c|2 +- kernel/cobalt/sched-sporadic.c |4 +-- kernel/cobalt/sched-tp.c|2 +- kernel/cobalt/sched-weak.c |2 +- kernel/cobalt/sched.c |8 +++--- kernel/cobalt/shadow.c |2 +- kernel/cobalt/thread.c |4 +-- kernel/cobalt/timer.c |8 +++--- kernel/drivers/analogy/device.c | 23 ++--- kernel/drivers/analogy/rtdm_interface.c |2 +- kernel/drivers/can/rtcan_dev.c |2 +- kernel/drivers/can/rtcan_module.c | 10 kernel/drivers/ipc/bufp.c |2 +- kernel/drivers/ipc/iddp.c |2 +- kernel/drivers/ipc/xddp.c |2 +- kernel/drivers/serial/16550A.c |2 +- kernel/drivers/serial/mpc52xx_uart.c|2 +- kernel/drivers/serial/rt_imx_uart.c |2 +- kernel/drivers/testing/rtdmtest.c |2 +- kernel/drivers/testing/switchtest.c |4 +-- kernel/drivers/testing/timerbench.c |2 +- 34 files changed, 99 insertions(+), 58 deletions(-) diff --git a/include/cobalt/kernel/Makefile.am b/include/cobalt/kernel/Makefile.am index d2375dc..ad6c7f2 100644 --- a/include/cobalt/kernel/Makefile.am +++ b/include/cobalt/kernel/Makefile.am @@ -1,5 +1,6 @@ noinst_HEADERS = \ + ancillaries.h \ apc.h \ arith.h \ assert.h\ diff --git a/include/cobalt/kernel/Makefile.in b/include/cobalt/kernel/Makefile.in index d3e7fb9..4b6e1da 100644 --- a/include/cobalt/kernel/Makefile.in +++ b/include/cobalt/kernel/Makefile.in @@ -351,6 +351,7 @@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ noinst_HEADERS = \ + ancillaries.h \ apc.h \ arith.h \ assert.h\ diff --git a/include/cobalt/kernel/ancillaries.h b/include/cobalt/kernel/ancillaries.h new file mode 100644 index 000..e1e59f2 --- /dev/null +++ b/include/cobalt/kernel/ancillaries.h @@ -0,0 +1,42 @@ +/** + * @note Copyright (C) 2014 Philippe Gerum . + * + * Xenomai is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2 of the License, + * or (at your option) any later version. + * + * Xenomai is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Xenomai; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ +#ifndef _COBALT_KERNEL_ANCILLARIES_H +#define _COBALT_KERNEL_ANCILLARIES_H + +#include + +#define ksformat(__dst, __len, __fmt, __args...) \ + ({ \ + size_t __ret; \ + __ret = snprintf(__dst, __len, __fmt, ##__args);\ + if (__ret >= __len) \ + __dst[__len-1] = '\0'; \ + __ret; \ + }) + +#define kvsformat(__dst, __len, __fmt, __ap) \ + ({ \ + size_t __ret; \ + __ret = vsnprintf(__dst, __len, __fmt, __ap); \ + if (__ret >= __len)
[Xenomai-git] Philippe Gerum : cobalt/kernel: generalize use of safe *snprintf()
Module: xenomai-forge Branch: next Commit: f8490220177c0c007ae98dac4a956ecd0de89120 URL: http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=f8490220177c0c007ae98dac4a956ecd0de89120 Author: Philippe Gerum Date: Thu Apr 17 11:44:08 2014 +0200 cobalt/kernel: generalize use of safe *snprintf() Make sure to have the destination string null-terminated on character overflow. --- include/cobalt/kernel/Makefile.am |1 + include/cobalt/kernel/Makefile.in |1 + include/cobalt/kernel/ancillaries.h | 42 +++ include/cobalt/kernel/assert.h |1 + include/cobalt/kernel/rtdm/driver.h |1 + kernel/cobalt/assert.c |2 +- kernel/cobalt/clock.c |2 +- kernel/cobalt/heap.c|4 +-- kernel/cobalt/intr.c|2 +- kernel/cobalt/posix/sem.c |2 +- kernel/cobalt/posix/thread.c|2 +- kernel/cobalt/rtdm/proc.c |2 +- kernel/cobalt/sched-quota.c |6 +++-- kernel/cobalt/sched-rt.c|2 +- kernel/cobalt/sched-sporadic.c |4 +-- kernel/cobalt/sched-tp.c|2 +- kernel/cobalt/sched-weak.c |2 +- kernel/cobalt/sched.c |8 +++--- kernel/cobalt/shadow.c |2 +- kernel/cobalt/thread.c |4 +-- kernel/cobalt/timer.c |8 +++--- kernel/drivers/analogy/device.c | 23 ++--- kernel/drivers/analogy/rtdm_interface.c |2 +- kernel/drivers/can/rtcan_dev.c |2 +- kernel/drivers/can/rtcan_module.c | 10 kernel/drivers/ipc/bufp.c |2 +- kernel/drivers/ipc/iddp.c |2 +- kernel/drivers/ipc/xddp.c |2 +- kernel/drivers/serial/16550A.c |2 +- kernel/drivers/serial/mpc52xx_uart.c|2 +- kernel/drivers/serial/rt_imx_uart.c |2 +- kernel/drivers/testing/rtdmtest.c |2 +- kernel/drivers/testing/switchtest.c |4 +-- kernel/drivers/testing/timerbench.c |2 +- 34 files changed, 99 insertions(+), 58 deletions(-) diff --git a/include/cobalt/kernel/Makefile.am b/include/cobalt/kernel/Makefile.am index d2375dc..ad6c7f2 100644 --- a/include/cobalt/kernel/Makefile.am +++ b/include/cobalt/kernel/Makefile.am @@ -1,5 +1,6 @@ noinst_HEADERS = \ + ancillaries.h \ apc.h \ arith.h \ assert.h\ diff --git a/include/cobalt/kernel/Makefile.in b/include/cobalt/kernel/Makefile.in index d3e7fb9..4b6e1da 100644 --- a/include/cobalt/kernel/Makefile.in +++ b/include/cobalt/kernel/Makefile.in @@ -351,6 +351,7 @@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ noinst_HEADERS = \ + ancillaries.h \ apc.h \ arith.h \ assert.h\ diff --git a/include/cobalt/kernel/ancillaries.h b/include/cobalt/kernel/ancillaries.h new file mode 100644 index 000..e1e59f2 --- /dev/null +++ b/include/cobalt/kernel/ancillaries.h @@ -0,0 +1,42 @@ +/** + * @note Copyright (C) 2014 Philippe Gerum . + * + * Xenomai is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2 of the License, + * or (at your option) any later version. + * + * Xenomai is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Xenomai; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ +#ifndef _COBALT_KERNEL_ANCILLARIES_H +#define _COBALT_KERNEL_ANCILLARIES_H + +#include + +#define ksformat(__dst, __len, __fmt, __args...) \ + ({ \ + size_t __ret; \ + __ret = snprintf(__dst, __len, __fmt, ##__args);\ + if (__ret >= __len) \ + __dst[__len-1] = '\0'; \ + __ret; \ + }) + +#define kvsformat(__dst, __len, __fmt, __ap) \ + ({ \ + size_t __ret; \ + __ret = vsnprintf(__dst, __len, __fmt, __ap); \ + if (__ret >= __len) \ +