Module: xenomai-2.6
Branch: master
Commit: 0d0db4dc7e9eb1e7d003b703a3219845b6ecbb14
URL:    
http://git.xenomai.org/?p=xenomai-2.6.git;a=commit;h=0d0db4dc7e9eb1e7d003b703a3219845b6ecbb14

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

nucleus/timer: prevent buffer overflow

---

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

diff --git a/ksrc/nucleus/timer.c b/ksrc/nucleus/timer.c
index c010482..0365759 100644
--- a/ksrc/nucleus/timer.c
+++ b/ksrc/nucleus/timer.c
@@ -1074,6 +1074,7 @@ EXPORT_SYMBOL_GPL(xntimer_freeze);
 char *xntimer_format_time(xnticks_t value, int periodic, char *buf, size_t 
bufsz)
 {
        unsigned long ms, us, ns;
+       int len = (int)bufsz;
        char *p = buf;
        xnticks_t s;
 
@@ -1092,13 +1093,17 @@ char *xntimer_format_time(xnticks_t value, int 
periodic, char *buf, size_t bufsz
        ms = us / 1000;
        us %= 1000;
 
-       if (s)
+       if (s) {
                p += snprintf(p, bufsz, "%Lus", s);
+               len = bufsz - (p - buf);
+       }
 
-       if (ms || (s && us))
+       if (len > 1 && (ms || (s && us))) {
                p += snprintf(p, bufsz - (p - buf), "%lums", ms);
+               len = bufsz - (p - buf);
+       }
 
-       if (us)
+       if (len > 1 && 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