From ce82a87d04e54288137bdeed6c53b378e5350577 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Mon, 18 Jan 2010 09:26:39 +0100 Subject: [PATCH] Keep serial from overruning with bad data --- bacula/src/lib/serial.c | 34 +++++++++++++++++++++------------- bacula/src/lib/serial.h | 11 +++++------ 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/bacula/src/lib/serial.c b/bacula/src/lib/serial.c index 6b803f16db..2de4edaf30 100644 --- a/bacula/src/lib/serial.c +++ b/bacula/src/lib/serial.c @@ -2,14 +2,11 @@ Serialisation Support Functions John Walker - - - Version $Id$ */ /* Bacula® - The Network Backup Solution - Copyright (C) 2000-2006 Free Software Foundation Europe e.V. + Copyright (C) 2000-2010 Free Software Foundation Europe e.V. The main author of Bacula is Kern Sibbald, with contributions from many others, a complete list can be found in the file AUTHORS. @@ -173,12 +170,17 @@ void serial_float64(uint8_t * * const ptr, const float64_t v) *ptr += sizeof(float64_t); } -void serial_string(uint8_t * * const ptr, const char * const str) +void serial_string(uint8_t * * const ptr, const char * const str, int max) { - int len = strlen(str) + 1; - - memcpy(*ptr, str, len); - *ptr += len; + int i; + char *dest = (char *)*ptr; + char *src = (char *)str; + for (i=0; i