From af92796e0308b31c9a6167e1c7bde6510ca409d7 Mon Sep 17 00:00:00 2001 From: Richard Jones Date: Tue, 7 Apr 2009 10:42:15 +0100 Subject: [PATCH] Fix incorrect realloc size which was causing 'ls' command to fail on large directories. --- src/generator.ml | 5 ++++- src/guestfs-actions.c | 18 ++++++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/generator.ml b/src/generator.ml index d598975..5aaea82 100755 --- a/src/generator.ml +++ b/src/generator.ml @@ -733,7 +733,10 @@ and generate_client_actions () = pr " return rv.ret.%s; /* caller will free */\n" n | RStringList n -> pr " /* caller will free this, but we need to add a NULL entry */\n"; - pr " rv.ret.%s.%s_val = safe_realloc (g, rv.ret.%s.%s_val, rv.ret.%s.%s_len + 1);\n" n n n n n n; + pr " rv.ret.%s.%s_val =" n n; + pr " safe_realloc (g, rv.ret.%s.%s_val,\n" n n; + pr " sizeof (char *) * (rv.ret.%s.%s_len + 1));\n" + n n; pr " rv.ret.%s.%s_val[rv.ret.%s.%s_len] = NULL;\n" n n n n; pr " return rv.ret.%s.%s_val;\n" n n | RPVList n -> diff --git a/src/guestfs-actions.c b/src/guestfs-actions.c index 3446a2d..44d7e1e 100644 --- a/src/guestfs-actions.c +++ b/src/guestfs-actions.c @@ -444,7 +444,8 @@ char **guestfs_ls (guestfs_h *g, } /* caller will free this, but we need to add a NULL entry */ - rv.ret.listing.listing_val = safe_realloc (g, rv.ret.listing.listing_val, rv.ret.listing.listing_len + 1); + rv.ret.listing.listing_val = safe_realloc (g, rv.ret.listing.listing_val, + sizeof (char *) * (rv.ret.listing.listing_len + 1)); rv.ret.listing.listing_val[rv.ret.listing.listing_len] = NULL; return rv.ret.listing.listing_val; } @@ -517,7 +518,8 @@ char **guestfs_list_devices (guestfs_h *g) } /* caller will free this, but we need to add a NULL entry */ - rv.ret.devices.devices_val = safe_realloc (g, rv.ret.devices.devices_val, rv.ret.devices.devices_len + 1); + rv.ret.devices.devices_val = safe_realloc (g, rv.ret.devices.devices_val, + sizeof (char *) * (rv.ret.devices.devices_len + 1)); rv.ret.devices.devices_val[rv.ret.devices.devices_len] = NULL; return rv.ret.devices.devices_val; } @@ -590,7 +592,8 @@ char **guestfs_list_partitions (guestfs_h *g) } /* caller will free this, but we need to add a NULL entry */ - rv.ret.partitions.partitions_val = safe_realloc (g, rv.ret.partitions.partitions_val, rv.ret.partitions.partitions_len + 1); + rv.ret.partitions.partitions_val = safe_realloc (g, rv.ret.partitions.partitions_val, + sizeof (char *) * (rv.ret.partitions.partitions_len + 1)); rv.ret.partitions.partitions_val[rv.ret.partitions.partitions_len] = NULL; return rv.ret.partitions.partitions_val; } @@ -663,7 +666,8 @@ char **guestfs_pvs (guestfs_h *g) } /* caller will free this, but we need to add a NULL entry */ - rv.ret.physvols.physvols_val = safe_realloc (g, rv.ret.physvols.physvols_val, rv.ret.physvols.physvols_len + 1); + rv.ret.physvols.physvols_val = safe_realloc (g, rv.ret.physvols.physvols_val, + sizeof (char *) * (rv.ret.physvols.physvols_len + 1)); rv.ret.physvols.physvols_val[rv.ret.physvols.physvols_len] = NULL; return rv.ret.physvols.physvols_val; } @@ -736,7 +740,8 @@ char **guestfs_vgs (guestfs_h *g) } /* caller will free this, but we need to add a NULL entry */ - rv.ret.volgroups.volgroups_val = safe_realloc (g, rv.ret.volgroups.volgroups_val, rv.ret.volgroups.volgroups_len + 1); + rv.ret.volgroups.volgroups_val = safe_realloc (g, rv.ret.volgroups.volgroups_val, + sizeof (char *) * (rv.ret.volgroups.volgroups_len + 1)); rv.ret.volgroups.volgroups_val[rv.ret.volgroups.volgroups_len] = NULL; return rv.ret.volgroups.volgroups_val; } @@ -809,7 +814,8 @@ char **guestfs_lvs (guestfs_h *g) } /* caller will free this, but we need to add a NULL entry */ - rv.ret.logvols.logvols_val = safe_realloc (g, rv.ret.logvols.logvols_val, rv.ret.logvols.logvols_len + 1); + rv.ret.logvols.logvols_val = safe_realloc (g, rv.ret.logvols.logvols_val, + sizeof (char *) * (rv.ret.logvols.logvols_len + 1)); rv.ret.logvols.logvols_val[rv.ret.logvols.logvols_len] = NULL; return rv.ret.logvols.logvols_val; } -- 1.8.3.1