Module: xenomai-forge
Branch: next
Commit: 42f420181fc536966b8436a8326d362efa52e5ad
URL:    
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=42f420181fc536966b8436a8326d362efa52e5ad

Author: Philippe Gerum <r...@xenomai.org>
Date:   Tue Sep 24 13:11:11 2013 +0200

cobalt/timer: prevent buffer overflow

---

 kernel/cobalt/timer.c |   11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/kernel/cobalt/timer.c b/kernel/cobalt/timer.c
index 814ccf3..1139859 100644
--- a/kernel/cobalt/timer.c
+++ b/kernel/cobalt/timer.c
@@ -547,6 +547,7 @@ EXPORT_SYMBOL_GPL(xntimer_get_overruns);
 char *xntimer_format_time(xnticks_t ns, char *buf, size_t bufsz)
 {
        unsigned long ms, us, rem;
+       int len = (int)bufsz;
        char *p = buf;
        xnticks_t sec;
 
@@ -560,13 +561,17 @@ char *xntimer_format_time(xnticks_t ns, char *buf, size_t 
bufsz)
        ms = us / 1000;
        us %= 1000;
 
-       if (sec)
+       if (sec) {
                p += snprintf(p, bufsz, "%Lus", sec);
+               len = bufsz - (p - buf);
+       }
 
-       if (ms || (sec && us))
+       if (len > 0 && (ms || (sec && us))) {
                p += snprintf(p, bufsz - (p - buf), "%lums", ms);
+               len = bufsz - (p - buf);
+       }
 
-       if (us)
+       if (len > 0 && us)
                p += snprintf(p, bufsz - (p - buf), "%luus", us);
 
        return buf;


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://www.xenomai.org/mailman/listinfo/xenomai-git

Reply via email to