From e964858b3d42538ba339325e8f19d3f3365a244f Mon Sep 17 00:00:00 2001 From: Miles Bader Date: Fri, 19 Jul 1996 20:23:20 +0000 Subject: Deal with NAME_LENGTH being 0. --- libstore/decode.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/libstore/decode.c b/libstore/decode.c index cf169d02..5231b33d 100644 --- a/libstore/decode.c +++ b/libstore/decode.c @@ -58,19 +58,24 @@ store_std_leaf_decode (struct store_enc *enc, || enc->cur_data + name_len + misc_len > enc->data_len) return EINVAL; - if (enc->data[enc->cur_data + name_len - 1] != '\0') + if (name_len > 0 && enc->data[enc->cur_data + name_len - 1] != '\0') return EINVAL; /* Name not terminated. */ misc = malloc (misc_len); if (! misc) return ENOMEM; - name = strdup (enc->data + enc->cur_data); - if (! name) + if (name_len > 0) { - free (misc); - return ENOMEM; + name = strdup (enc->data + enc->cur_data); + if (! name) + { + free (misc); + return ENOMEM; + } } + else + name = 0; /* Read encoded ports (be careful to deallocate this if we barf). */ port = enc->ports[enc->cur_port++]; @@ -113,7 +118,8 @@ store_std_leaf_decode (struct store_enc *enc, { mach_port_deallocate (mach_task_self (), port); free (misc); - free (name); + if (name) + free (name); } else { -- cgit v1.2.3