Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fixes to C code

  • Loading branch information...
commit 4c71ae92c682c6c1068463d8ce70410879bd6678 1 parent 21becf3
@rusvika rusvika authored
View
4 clc/modules/bootstrap/src/main/native/eucalyptus-bootstrap.c
@@ -619,6 +619,8 @@ char* java_library_path(euca_opts *args) {
etc_dir);
wb += snprintf(jar_list + wb, JAVA_PATH_LEN - wb, "%s", script_dir);
DIR* lib_dir_p = opendir(lib_dir);
+ if(!lib_dir_p)
+ __die(1, "Can't open library directory %s", lib_dir);
struct direct *dir_ent;
while ((dir_ent = readdir(lib_dir_p)) != 0) {
if (strcmp(dir_ent->d_name, ".") != 0 && strcmp(dir_ent->d_name, "..")
@@ -648,7 +650,7 @@ char* java_library_path(euca_opts *args) {
wb += snprintf(jar_list + wb, JAVA_PATH_LEN - wb, ":%s", jar);
}
}
- closedir(lib_dir_p);
+ closedir(lib_dir_p);
return jar_list;
}
View
87 cluster/handlers.c
@@ -1385,7 +1385,7 @@ int refresh_resources(ncMetadata *ccMeta, int timeout, int dolock) {
char *mac;
rc = ip2mac(vnetconfig, resourceCacheStage->resources[i].ip, &mac);
if (!rc) {
- strncpy(resourceCacheStage->resources[i].mac, mac, 24);
+ safe_strncpy(resourceCacheStage->resources[i].mac, mac, 24);
free(mac);
logprintfl(EUCADEBUG, "refresh_resources(): discovered MAC '%s' for host %s(%s)\n", resourceCacheStage->resources[i].mac, resourceCacheStage->resources[i].hostname, resourceCacheStage->resources[i].ip);
}
@@ -1514,14 +1514,14 @@ int refresh_instances(ncMetadata *ccMeta, int timeout, int dolock) {
// instance info that the CC maintains
myInstance->ncHostIdx = i;
- strncpy(myInstance->serviceTag, resourceCacheStage->resources[i].ncURL, 64);
+ safe_strncpy(myInstance->serviceTag, resourceCacheStage->resources[i].ncURL, 64);
{
char *ip=NULL;
if (!strcmp(myInstance->ccnet.publicIp, "0.0.0.0")) {
if (!strcmp(vnetconfig->mode, "SYSTEM") || !strcmp(vnetconfig->mode, "STATIC") || !strcmp(vnetconfig->mode, "STATIC-DYNMAC") ) {
rc = mac2ip(vnetconfig, myInstance->ccnet.privateMac, &ip);
if (!rc) {
- strncpy(myInstance->ccnet.publicIp, ip, 24);
+ safe_strncpy(myInstance->ccnet.publicIp, ip, 24);
}
}
}
@@ -1532,7 +1532,7 @@ int refresh_instances(ncMetadata *ccMeta, int timeout, int dolock) {
if (!strcmp(myInstance->ccnet.privateIp, "0.0.0.0")) {
rc = mac2ip(vnetconfig, myInstance->ccnet.privateMac, &ip);
if (!rc) {
- strncpy(myInstance->ccnet.privateIp, ip, 24);
+ safe_strncpy(myInstance->ccnet.privateIp, ip, 24);
}
}
@@ -1765,20 +1765,20 @@ void print_netConfig(char *prestr, netConfig *in) {
int ccInstance_to_ncInstance(ccInstance *dst, ncInstance *src) {
int i;
- strncpy(dst->uuid, src->uuid, 48);
- strncpy(dst->instanceId, src->instanceId, 16);
- strncpy(dst->reservationId, src->reservationId, 16);
- strncpy(dst->accountId, src->userId, 48);
- strncpy(dst->amiId, src->imageId, 16);
- strncpy(dst->kernelId, src->kernelId, 16);
- strncpy(dst->ramdiskId, src->ramdiskId, 16);
- strncpy(dst->keyName, src->keyName, 1024);
- strncpy(dst->launchIndex, src->launchIndex, 64);
- strncpy(dst->platform, src->platform, 64);
- strncpy(dst->bundleTaskStateName, src->bundleTaskStateName, 64);
- strncpy(dst->createImageTaskStateName, src->createImageTaskStateName, 64);
- strncpy(dst->userData, src->userData, 4096);
- strncpy(dst->state, src->stateName, 16);
+ safe_strncpy(dst->uuid, src->uuid, 48);
+ safe_strncpy(dst->instanceId, src->instanceId, 16);
+ safe_strncpy(dst->reservationId, src->reservationId, 16);
+ safe_strncpy(dst->accountId, src->userId, 48);
+ safe_strncpy(dst->amiId, src->imageId, 16);
+ safe_strncpy(dst->kernelId, src->kernelId, 16);
+ safe_strncpy(dst->ramdiskId, src->ramdiskId, 16);
+ safe_strncpy(dst->keyName, src->keyName, 1024);
+ safe_strncpy(dst->launchIndex, src->launchIndex, 64);
+ safe_strncpy(dst->platform, src->platform, 64);
+ safe_strncpy(dst->bundleTaskStateName, src->bundleTaskStateName, 64);
+ safe_strncpy(dst->createImageTaskStateName, src->createImageTaskStateName, 64);
+ safe_strncpy(dst->userData, src->userData, 4096);
+ safe_strncpy(dst->state, src->stateName, 16);
dst->ts = src->launchTime;
memcpy(&(dst->ncnet), &(src->ncnet), sizeof(netConfig));
@@ -3667,8 +3667,8 @@ int init_config(void) {
sem_mywait(CONFIG);
// set up the current config
- strncpy(config->eucahome, eucahome, MAX_PATH);
- strncpy(config->policyFile, policyFile, MAX_PATH);
+ safe_strncpy(config->eucahome, eucahome, MAX_PATH);
+ safe_strncpy(config->policyFile, policyFile, MAX_PATH);
// snprintf(config->proxyPath, MAX_PATH, "%s/var/lib/eucalyptus/dynserv/data", config->eucahome);
snprintf(config->proxyPath, MAX_PATH, "%s", proxyPath);
config->use_proxy = use_proxy;
@@ -3932,6 +3932,7 @@ int reconfigureNetworkFromCLC() {
fd = safe_mkstemp(chainmapfile);
if (fd < 0) {
logprintfl(EUCAERROR, "reconfigureNetworkFromCLC(): cannot open chainmapfile '%s'\n", chainmapfile);
+ if (cloudIp) free(cloudIp);
unlink(clcnetfile);
return(1);
}
@@ -4093,11 +4094,11 @@ void shawn() {
int allocate_ccResource(ccResource *out, char *ncURL, char *ncService, int ncPort, char *hostname, char *mac, char *ip, int maxMemory, int availMemory, int maxDisk, int availDisk, int maxCores, int availCores, int state, int laststate, time_t stateChange, time_t idleStart) {
if (out != NULL) {
- if (ncURL) strncpy(out->ncURL, ncURL, 128);
- if (ncService) strncpy(out->ncService, ncService, 128);
- if (hostname) strncpy(out->hostname, hostname, 128);
- if (mac) strncpy(out->mac, mac, 24);
- if (ip) strncpy(out->ip, ip, 24);
+ if (ncURL) safe_strncpy(out->ncURL, ncURL, 128);
+ if (ncService) safe_strncpy(out->ncService, ncService, 128);
+ if (hostname) safe_strncpy(out->hostname, hostname, 128);
+ if (mac) safe_strncpy(out->mac, mac, 24);
+ if (ip) safe_strncpy(out->ip, ip, 24);
out->ncPort = ncPort;
out->maxMemory = maxMemory;
@@ -4156,32 +4157,32 @@ int free_instanceNetwork(char *mac, int vlan, int force, int dolock) {
int allocate_ccInstance(ccInstance *out, char *id, char *amiId, char *kernelId, char *ramdiskId, char *amiURL, char *kernelURL, char *ramdiskURL, char *accountId, char *state, char *ccState, time_t ts, char *reservationId, netConfig *ccnet, netConfig *ncnet, virtualMachine *ccvm, int ncHostIdx, char *keyName, char *serviceTag, char *userData, char *launchIndex, char *platform, char *bundleTaskStateName, char groupNames[][32], ncVolume *volumes, int volumesSize) {
if (out != NULL) {
bzero(out, sizeof(ccInstance));
- if (id) strncpy(out->instanceId, id, 16);
- if (amiId) strncpy(out->amiId, amiId, 16);
- if (kernelId) strncpy(out->kernelId, kernelId, 16);
- if (ramdiskId) strncpy(out->ramdiskId, ramdiskId, 16);
+ if (id) safe_strncpy(out->instanceId, id, 16);
+ if (amiId) safe_strncpy(out->amiId, amiId, 16);
+ if (kernelId) safe_strncpy(out->kernelId, kernelId, 16);
+ if (ramdiskId) safe_strncpy(out->ramdiskId, ramdiskId, 16);
- if (amiURL) strncpy(out->amiURL, amiURL, 512);
- if (kernelURL) strncpy(out->kernelURL, kernelURL, 512);
- if (ramdiskURL) strncpy(out->ramdiskURL, ramdiskURL, 512);
+ if (amiURL) safe_strncpy(out->amiURL, amiURL, 512);
+ if (kernelURL) safe_strncpy(out->kernelURL, kernelURL, 512);
+ if (ramdiskURL) safe_strncpy(out->ramdiskURL, ramdiskURL, 512);
- if (state) strncpy(out->state, state, 16);
- if (state) strncpy(out->ccState, ccState, 16);
- if (accountId) strncpy(out->accountId, accountId, 48);
- if (reservationId) strncpy(out->reservationId, reservationId, 16);
- if (keyName) strncpy(out->keyName, keyName, 1024);
+ if (state) safe_strncpy(out->state, state, 16);
+ if (state) safe_strncpy(out->ccState, ccState, 16);
+ if (accountId) safe_strncpy(out->accountId, accountId, 48);
+ if (reservationId) safe_strncpy(out->reservationId, reservationId, 16);
+ if (keyName) safe_strncpy(out->keyName, keyName, 1024);
out->ts = ts;
out->ncHostIdx = ncHostIdx;
- if (serviceTag) strncpy(out->serviceTag, serviceTag, 64);
- if (userData) strncpy(out->userData, userData, 4096);
- if (launchIndex) strncpy(out->launchIndex, launchIndex, 64);
- if (platform) strncpy(out->platform, platform, 64);
- if (bundleTaskStateName) strncpy(out->bundleTaskStateName, bundleTaskStateName, 64);
+ if (serviceTag) safe_strncpy(out->serviceTag, serviceTag, 64);
+ if (userData) safe_strncpy(out->userData, userData, 4096);
+ if (launchIndex) safe_strncpy(out->launchIndex, launchIndex, 64);
+ if (platform) safe_strncpy(out->platform, platform, 64);
+ if (bundleTaskStateName) safe_strncpy(out->bundleTaskStateName, bundleTaskStateName, 64);
if (groupNames) {
int i;
for (i=0; i<64; i++) {
if (groupNames[i]) {
- strncpy(out->groupNames[i], groupNames[i], 32);
+ safe_strncpy(out->groupNames[i], groupNames[i], 32);
}
}
}
View
1  cluster/server-marshal-state.c
@@ -122,6 +122,7 @@ adb_DescribeServicesResponse_t *DescribeServicesMarshal(adb_DescribeServices_t *
adb_describeServicesResponseType_add_serviceStatuses(adbresp, env, stt);
}
if(outStatuses) free(outStatuses);
+ if(serviceIds) free(serviceIds);
adb_describeServicesResponseType_set_return(adbresp, env, status);
if (status == AXIS2_FALSE) {
View
15 gatherlog/handlers.c
@@ -210,22 +210,26 @@ int doGetLogs(char *service, char **outCCLog, char **outNCLog, char **outHTTPDLo
} else {
close(filedes[1]);
- rc = read(filedes[0], buf, bufsize);
+ bzero(buf, bufsize);
+ rc = read(filedes[0], buf, bufsize - 1);
if (rc && buf[0] != '\0') {
*outCCLog = strdup(buf);
}
- rc = read(filedes[0], buf, bufsize);
+ bzero(buf, bufsize);
+ rc = read(filedes[0], buf, bufsize - 1);
if (rc && buf[0] != '\0') {
*outNCLog = strdup(buf);
}
- rc = read(filedes[0], buf, bufsize);
+ bzero(buf, bufsize);
+ rc = read(filedes[0], buf, bufsize - 1);
if (rc && buf[0] != '\0') {
*outHTTPDLog = strdup(buf);
}
- rc = read(filedes[0], buf, bufsize);
+ bzero(buf, bufsize);
+ rc = read(filedes[0], buf, bufsize - 1);
if (rc && buf[0] != '\0') {
*outAxis2Log = strdup(buf);
}
@@ -288,7 +292,8 @@ int doGetKeys(char *service, char **outCCCert, char **outNCCert) {
if (fd >= 0) {
bzero(buf, bufsize);
lseek(fd, -1 * bufsize, SEEK_END);
- rc = read(fd, buf, bufsize);
+ // make sure that buf is NULL terminated
+ rc = read(fd, buf, bufsize - 1);
if (rc > 0) {
*outNCCert = base64_enc((unsigned char *)buf, strlen(buf));
}
View
30 net/vnetwork.c
@@ -97,7 +97,7 @@ int vnetInit(vnetConfig *vnetconfig, char *mode, char *eucahome, char *path, int
bzero(vnetconfig, sizeof(vnetConfig));
// always need 'mode' set
if (mode) {
- strncpy(vnetconfig->mode, mode, 32);
+ safe_strncpy(vnetconfig->mode, mode, 32);
} else {
logprintfl(EUCAERROR, "vnetInit(): VNET_MODE is not set\n");
return(1);
@@ -182,18 +182,18 @@ int vnetInit(vnetConfig *vnetconfig, char *mode, char *eucahome, char *path, int
return(1);
}
- if (macPrefix) strncpy(vnetconfig->macPrefix, macPrefix, 5);
- if (path) strncpy(vnetconfig->path, path, MAX_PATH);
- if (eucahome) strncpy(vnetconfig->eucahome, eucahome, MAX_PATH);
- if (pubInterface) strncpy(vnetconfig->pubInterface, pubInterface, 32);
- if (bridgedev) strncpy(vnetconfig->bridgedev, bridgedev, 32);
- if (daemon) strncpy(vnetconfig->dhcpdaemon, daemon, MAX_PATH);
- if (privInterface) strncpy(vnetconfig->privInterface, privInterface, 32);
- if (dhcpuser) strncpy(vnetconfig->dhcpuser, dhcpuser, 32);
+ if (macPrefix) safe_strncpy(vnetconfig->macPrefix, macPrefix, 5);
+ if (path) safe_strncpy(vnetconfig->path, path, MAX_PATH);
+ if (eucahome) safe_strncpy(vnetconfig->eucahome, eucahome, MAX_PATH);
+ if (pubInterface) safe_strncpy(vnetconfig->pubInterface, pubInterface, 32);
+ if (bridgedev) safe_strncpy(vnetconfig->bridgedev, bridgedev, 32);
+ if (daemon) safe_strncpy(vnetconfig->dhcpdaemon, daemon, MAX_PATH);
+ if (privInterface) safe_strncpy(vnetconfig->privInterface, privInterface, 32);
+ if (dhcpuser) safe_strncpy(vnetconfig->dhcpuser, dhcpuser, 32);
if (domainname) {
- strncpy(vnetconfig->euca_domainname, domainname, 256);
+ safe_strncpy(vnetconfig->euca_domainname, domainname, 256);
} else {
- strncpy(vnetconfig->euca_domainname, "eucalyptus", strlen("eucalyptus"));
+ strncpy(vnetconfig->euca_domainname, "eucalyptus", strlen("eucalyptus") + 1);
}
if (localIp) {
@@ -1017,9 +1017,9 @@ int vnetSetVlan(vnetConfig *vnetconfig, int vlan, char *uuid, char *user, char *
if (param_check("vnetSetVlan", vnetconfig, vlan, user, network)) return(1);
- strncpy(vnetconfig->users[vlan].userName, user, 48);
- strncpy(vnetconfig->users[vlan].netName, network, 32);
- if (uuid) strncpy(vnetconfig->users[vlan].uuid, uuid, 48);
+ safe_strncpy(vnetconfig->users[vlan].userName, user, 48);
+ safe_strncpy(vnetconfig->users[vlan].netName, network, 32);
+ if (uuid) safe_strncpy(vnetconfig->users[vlan].uuid, uuid, 48);
return(0);
}
@@ -1282,7 +1282,7 @@ int vnetAddDev(vnetConfig *vnetconfig, char *dev) {
}
}
if (foundone >= 0) {
- strncpy(vnetconfig->etherdevs[foundone], dev, 16);
+ safe_strncpy(vnetconfig->etherdevs[foundone], dev, 16);
}
return(0);
}
View
16 node/client-marshal-adb.c
@@ -167,9 +167,9 @@ static ncInstance * copy_instance_from_adb (adb_instanceType_t * instance, axuti
if (netconf != NULL) {
ncnet.vlan = adb_netConfigType_get_vlan(netconf, env);
ncnet.networkIndex = adb_netConfigType_get_networkIndex(netconf, env);
- strncpy(ncnet.privateMac, adb_netConfigType_get_privateMacAddress(netconf, env), 24);
- strncpy(ncnet.privateIp, adb_netConfigType_get_privateIp(netconf, env), 24);
- strncpy(ncnet.publicIp, adb_netConfigType_get_publicIp(netconf, env), 24);
+ safe_strncpy(ncnet.privateMac, adb_netConfigType_get_privateMacAddress(netconf, env), 24);
+ safe_strncpy(ncnet.privateIp, adb_netConfigType_get_privateIp(netconf, env), 24);
+ safe_strncpy(ncnet.publicIp, adb_netConfigType_get_publicIp(netconf, env), 24);
}
int groupNamesSize = adb_instanceType_sizeof_groupNames (instance, env);
@@ -198,7 +198,7 @@ static ncInstance * copy_instance_from_adb (adb_instanceType_t * instance, axuti
groupNames, groupNamesSize
);
- strncpy(outInst->bundleTaskStateName, (char *)adb_instanceType_get_bundleTaskStateName(instance, env), CHAR_BUFFER_SIZE);
+ safe_strncpy(outInst->bundleTaskStateName, (char *)adb_instanceType_get_bundleTaskStateName(instance, env), CHAR_BUFFER_SIZE);
outInst->blkbytes = adb_instanceType_get_blkbytes(instance, env);
outInst->netbytes = adb_instanceType_get_netbytes(instance, env);
@@ -212,10 +212,10 @@ static ncInstance * copy_instance_from_adb (adb_instanceType_t * instance, axuti
if (outInst->volumesSize > 0) {
for (i=0; i<EUCA_MAX_VOLUMES && i<outInst->volumesSize; i++) {
adb_volumeType_t * volume = adb_instanceType_get_volumes_at (instance, env, i);
- strncpy (outInst->volumes[i].volumeId, adb_volumeType_get_volumeId (volume, env), CHAR_BUFFER_SIZE);
- strncpy (outInst->volumes[i].remoteDev, adb_volumeType_get_remoteDev (volume, env), CHAR_BUFFER_SIZE);
- strncpy (outInst->volumes[i].localDev, adb_volumeType_get_localDev (volume, env), CHAR_BUFFER_SIZE);
- strncpy (outInst->volumes[i].stateName, adb_volumeType_get_state (volume, env), CHAR_BUFFER_SIZE);
+ safe_strncpy (outInst->volumes[i].volumeId, adb_volumeType_get_volumeId (volume, env), CHAR_BUFFER_SIZE);
+ safe_strncpy (outInst->volumes[i].remoteDev, adb_volumeType_get_remoteDev (volume, env), CHAR_BUFFER_SIZE);
+ safe_strncpy (outInst->volumes[i].localDev, adb_volumeType_get_localDev (volume, env), CHAR_BUFFER_SIZE);
+ safe_strncpy (outInst->volumes[i].stateName, adb_volumeType_get_state (volume, env), CHAR_BUFFER_SIZE);
}
}
View
14 node/handlers.c
@@ -253,7 +253,7 @@ void change_state( ncInstance *instance,
return;
}
- strncpy(instance->stateName, instance_state_names[instance->stateCode], CHAR_BUFFER_SIZE);
+ safe_strncpy(instance->stateName, instance_state_names[instance->stateCode], CHAR_BUFFER_SIZE);
if (old_state != state) {
logprintfl (EUCADEBUG, "[%s] state change for instance: %s -> %s (%s)\n",
instance->instanceId,
@@ -390,7 +390,7 @@ refresh_instance_info( struct nc_state_t *nc,
if (!rc) {
if(ip) {
logprintfl (EUCAINFO, "[%s] discovered public IP %s for instance\n", instance->instanceId, ip);
- strncpy(instance->ncnet.publicIp, ip, 24);
+ safe_strncpy(instance->ncnet.publicIp, ip, 24);
free(ip);
}
}
@@ -401,7 +401,7 @@ refresh_instance_info( struct nc_state_t *nc,
if (!rc) {
if(ip) {
logprintfl (EUCAINFO, "[%s] discovered private IP %s for instance\n", instance->instanceId, ip);
- strncpy(instance->ncnet.privateIp, ip, 24);
+ safe_strncpy(instance->ncnet.privateIp, ip, 24);
free(ip);
}
}
@@ -552,7 +552,8 @@ void *startup_thread (void * arg)
goto free;
}
- strncpy (instance->params.guestNicDeviceName, brname, sizeof (instance->params.guestNicDeviceName));
+ safe_strncpy (instance->params.guestNicDeviceName, brname, sizeof (instance->params.guestNicDeviceName));
+
if (nc_state.config_use_virtio_net) {
instance->params.nicType = NIC_TYPE_VIRTIO;
} else {
@@ -564,7 +565,8 @@ void *startup_thread (void * arg)
}
logprintfl (EUCAINFO, "[%s] started network\n", instance->instanceId);
- strncpy (instance->hypervisorType, nc_state.H->name, sizeof (instance->hypervisorType)); // set the hypervisor type
+ safe_strncpy (instance->hypervisorType, nc_state.H->name, sizeof (instance->hypervisorType)); // set the hypervisor type
+
instance->hypervisorCapability = nc_state.capability; // set the cap (xen/hw/hw+xen)
instance->combinePartitions = nc_state.convert_to_disk;
instance->do_inject_key = nc_state.do_inject_key;
@@ -751,7 +753,7 @@ static int init (void)
nc_state.home[0] = '\0';
do_warn = 1;
} else {
- strncpy(nc_state.home, tmp, MAX_PATH);
+ strncpy(nc_state.home, tmp, MAX_PATH - 1);
}
/* set the minimum log for now */
View
4 node/handlers_default.c
@@ -529,7 +529,7 @@ doDetachVolume( struct nc_state_t *nc,
static void change_createImage_state (ncInstance * instance, createImage_progress state)
{
instance->createImageTaskState = state;
- strncpy (instance->createImageTaskStateName, createImage_progress_names [state], CHAR_BUFFER_SIZE);
+ safe_strncpy (instance->createImageTaskStateName, createImage_progress_names [state], CHAR_BUFFER_SIZE);
}
// helper for cleaning up
@@ -681,7 +681,7 @@ doCreateImage( struct nc_state_t *nc,
static void change_bundling_state (ncInstance * instance, bundling_progress state)
{
instance->bundleTaskState = state;
- strncpy (instance->bundleTaskStateName, bundling_progress_names [state], CHAR_BUFFER_SIZE);
+ safe_strncpy (instance->bundleTaskStateName, bundling_progress_names [state], CHAR_BUFFER_SIZE);
}
/*
View
2  storage/Wclient.c
@@ -172,7 +172,7 @@ int main (int argc, char * argv[])
result = walrus_image_by_manifest_url (request, tmp_name, do_compress);
}
} else {
- strncpy (request, manifest, STRSIZE);
+ safe_strncpy (request, manifest, STRSIZE);
if ( strcmp(command, "GetObject")==0 ) {
result = walrus_object_by_path (request, tmp_name, do_compress);
} else {
View
12 storage/backing.c
@@ -104,7 +104,7 @@ int init_backing_store (const char * conf_instances_path, unsigned int conf_work
logprintfl (EUCAERROR, "error: INSTANCE_PATH not specified\n");
return ERROR;
}
- strncpy (instances_path, conf_instances_path, sizeof (instances_path));
+ safe_strncpy (instances_path, conf_instances_path, sizeof (instances_path));
if (check_directory (instances_path)) {
logprintfl (EUCAERROR, "error: INSTANCE_PATH (%s) does not exist!\n", instances_path);
return ERROR;
@@ -142,10 +142,10 @@ int init_backing_store (const char * conf_instances_path, unsigned int conf_work
static void update_vbr_with_backing_info (virtualBootRecord * vbr, blockblob * bb, int allow_block_dev)
{
if (allow_block_dev && strlen (blockblob_get_dev (bb))) {
- strncpy (vbr->backingPath, blockblob_get_dev (bb), sizeof (vbr->backingPath));
+ safe_strncpy (vbr->backingPath, blockblob_get_dev (bb), sizeof (vbr->backingPath));
vbr->backingType = SOURCE_TYPE_BLOCK;
} else {
- strncpy (vbr->backingPath, blockblob_get_file (bb), sizeof (vbr->backingPath));
+ safe_strncpy (vbr->backingPath, blockblob_get_file (bb), sizeof (vbr->backingPath));
vbr->backingType = SOURCE_TYPE_FILE;
}
}
@@ -409,7 +409,7 @@ static int create_vbr_backing (ncInstance * instance, virtualBootRecord * vbr, i
goto i_error;
}
// update VBR with device location
- strncpy (vbr->backingPath, dev, sizeof (vbr->backingPath));
+ safe_strncpy (vbr->backingPath, dev, sizeof (vbr->backingPath));
vbr->backingType = SOURCE_TYPE_BLOCK;
ret = OK;
@@ -822,7 +822,7 @@ ncInstance * load_instance_struct (const char * instanceId)
logprintfl (EUCADEBUG, "load_instance_struct: out of memory for instance struct\n");
return NULL;
}
- strncpy (instance->instanceId, instanceId, sizeof (instance->instanceId));
+ safe_strncpy (instance->instanceId, instanceId, sizeof (instance->instanceId));
// we don't know userId, so we'll look for instanceId in every user's
// directory (we're assuming that instanceIds are unique in the system)
@@ -841,7 +841,7 @@ ncInstance * load_instance_struct (const char * instanceId)
snprintf(tmp_path, sizeof (tmp_path), "%s/%s/%s", user_paths, dir_entry->d_name, instance->instanceId);
if (stat(tmp_path, &mystat)==0) {
- strncpy (instance->userId, dir_entry->d_name, sizeof (instance->userId));
+ safe_strncpy (instance->userId, dir_entry->d_name, sizeof (instance->userId));
break; // found it
}
}
View
35 storage/blobstore.c
@@ -452,7 +452,7 @@ static int open_and_lock (const char * path,
ERR (BLOBSTORE_ERROR_NOMEM, NULL);
return -1;
}
- strncpy (path_lock->path, path, sizeof(path_lock->path));
+ safe_strncpy (path_lock->path, path, sizeof(path_lock->path));
pthread_rwlock_init (&(path_lock->lock), NULL);
pthread_mutex_init (&(path_lock->mutex), NULL);
* next_ptr = path_lock; // add at the end of LL
@@ -621,7 +621,7 @@ static int read_store_metadata (blobstore * bs)
char * val;
if ((val = get_val (buf, "id"))==NULL)
return -1;
- strncpy (bs->id, val, sizeof (bs->id));
+ safe_strncpy (bs->id, val, sizeof (bs->id));
free (val);
if ((val = get_val (buf, "limit"))==NULL) return -1;
@@ -716,7 +716,7 @@ blobstore * blobstore_open ( const char * path,
ERR (BLOBSTORE_ERROR_NOMEM, NULL);
goto out;
}
- strncpy (bs->path, path, sizeof(bs->path)); // TODO: canonicalize path
+ safe_strncpy (bs->path, path, sizeof(bs->path)); // TODO: canonicalize path
char meta_path [PATH_MAX];
snprintf (meta_path, sizeof(meta_path), "%s/%s", bs->path, BLOBSTORE_METADATA_FILE);
@@ -850,12 +850,12 @@ static int set_blockblob_metadata_path (blockblob_path_t path_t, const blobstore
char name [32];
switch (path_t) {
- case BLOCKBLOB_PATH_BLOCKS: strncpy (name, blobstore_metadata_suffixes[BLOCKBLOB_PATH_BLOCKS], sizeof (name)); break;
- case BLOCKBLOB_PATH_DM: strncpy (name, blobstore_metadata_suffixes[BLOCKBLOB_PATH_DM], sizeof (name)); break;
- case BLOCKBLOB_PATH_DEPS: strncpy (name, blobstore_metadata_suffixes[BLOCKBLOB_PATH_DEPS], sizeof (name)); break;
- case BLOCKBLOB_PATH_LOOPBACK: strncpy (name, blobstore_metadata_suffixes[BLOCKBLOB_PATH_LOOPBACK], sizeof (name)); break;
- case BLOCKBLOB_PATH_SIG: strncpy (name, blobstore_metadata_suffixes[BLOCKBLOB_PATH_SIG], sizeof (name)); break;
- case BLOCKBLOB_PATH_REFS: strncpy (name, blobstore_metadata_suffixes[BLOCKBLOB_PATH_REFS], sizeof (name)); break;
+ case BLOCKBLOB_PATH_BLOCKS: safe_strncpy (name, blobstore_metadata_suffixes[BLOCKBLOB_PATH_BLOCKS], sizeof (name)); break;
+ case BLOCKBLOB_PATH_DM: safe_strncpy (name, blobstore_metadata_suffixes[BLOCKBLOB_PATH_DM], sizeof (name)); break;
+ case BLOCKBLOB_PATH_DEPS: safe_strncpy (name, blobstore_metadata_suffixes[BLOCKBLOB_PATH_DEPS], sizeof (name)); break;
+ case BLOCKBLOB_PATH_LOOPBACK: safe_strncpy (name, blobstore_metadata_suffixes[BLOCKBLOB_PATH_LOOPBACK], sizeof (name)); break;
+ case BLOCKBLOB_PATH_SIG: safe_strncpy (name, blobstore_metadata_suffixes[BLOCKBLOB_PATH_SIG], sizeof (name)); break;
+ case BLOCKBLOB_PATH_REFS: safe_strncpy (name, blobstore_metadata_suffixes[BLOCKBLOB_PATH_REFS], sizeof (name)); break;
default:
ERR (BLOBSTORE_ERROR_INVAL, "invalid path_t");
return -1;
@@ -1202,7 +1202,7 @@ static void set_device_path (blockblob * bb)
if (dm_devs_size>0) { // .dm is there => set device_path to the device-mapper path
snprintf (bb->device_path, sizeof(bb->device_path), DM_FORMAT, dm_devs [dm_devs_size-1]); // main device is the last one
- strncpy (bb->dm_name, dm_devs [dm_devs_size-1], sizeof (bb->dm_name));
+ safe_strncpy (bb->dm_name, dm_devs [dm_devs_size-1], sizeof (bb->dm_name));
for (int i=0; i<dm_devs_size; i++) {
free (dm_devs [i]);
}
@@ -1212,7 +1212,7 @@ static void set_device_path (blockblob * bb)
_err_off(); // do not care if loopback file does not exist
read_blockblob_metadata_path (BLOCKBLOB_PATH_LOOPBACK, bb->store, bb->id, lo_dev, sizeof (lo_dev));
_err_on();
- strncpy (bb->device_path, lo_dev, sizeof (bb->device_path));
+ safe_strncpy (bb->device_path, lo_dev, sizeof (bb->device_path));
}
}
@@ -1263,8 +1263,8 @@ static blockblob ** walk_bs (blobstore * bs, const char * dir_path, blockblob **
tail_bb = & (bb->next);
// fill out the struct
bb->store = bs;
- strncpy (bb->id, blob_id, sizeof(bb->id));
- strncpy (bb->blocks_path, entry_path, sizeof(bb->blocks_path));
+ safe_strncpy (bb->id, blob_id, sizeof(bb->id));
+ safe_strncpy (bb->blocks_path, entry_path, sizeof(bb->blocks_path));
set_device_path (bb); // read .dm and .loopback and set bb->device_path accordingly
bb->size_bytes = sb.st_size;
bb->last_accessed = sb.st_atime;
@@ -1311,6 +1311,9 @@ static long long purge_blockblobs_lru ( blobstore * bs, blockblob * bb_list, lon
int i;
blockblob ** bb_array = (blockblob **) calloc (list_length, sizeof (blockblob *));
+ if(!bb_array)
+ return purged;
+
for (i=0, bb = bb_list; bb; bb = bb->next, i++) {
bb_array [i] = bb;
}
@@ -1377,7 +1380,7 @@ int blobstore_search ( blobstore * bs, const char * regex, blockblob_meta ** res
goto free;
}
- strncpy (bm->id, abb->id, sizeof (bm->id));
+ safe_strncpy (bm->id, abb->id, sizeof (bm->id));
bm->size_bytes = abb->size_bytes;
bm->in_use = abb->in_use;
bm->last_accessed = abb->last_accessed;
@@ -1482,7 +1485,7 @@ blockblob * blockblob_open ( blobstore * bs,
bb->store = bs;
if (id) {
- strncpy (bb->id, id, sizeof(bb->id));
+ safe_strncpy (bb->id, id, sizeof(bb->id));
} else {
gen_id (bb->id, sizeof(bb->id));
}
@@ -2274,7 +2277,7 @@ int blockblob_clone ( blockblob * bb, // destination blob, which blocks may be u
}
if (mapped_or_snapshotted) { // we must use the device mapper
- strncpy (bb->dm_name, dm_base, sizeof(bb->dm_name));
+ safe_strncpy (bb->dm_name, dm_base, sizeof(bb->dm_name));
dev_names [devices] = strdup (dm_base);
dm_tables [devices] = main_dm_table;
devices++;
View
11 storage/cache.c
@@ -70,7 +70,7 @@ int set_cache_dir (const char * path)
logprintfl (EUCAERROR, "failed to set cache directory to '%s'\n", path);
return 1;
}
- strncpy (cache_path, path, EUCA_MAX_PATH);
+ safe_strncpy (cache_path, path, EUCA_MAX_PATH);
return 0;
}
@@ -383,7 +383,8 @@ int set_work_dir (const char * path)
logprintfl (EUCAERROR, "failed to set work directory to '%s'\n", path);
return 1;
}
- strncpy (work_path, path, EUCA_MAX_PATH);
+ safe_strncpy (work_path, path, EUCA_MAX_PATH);
+
return 0;
}
@@ -458,7 +459,7 @@ disk_item * alloc_disk_item (const char * id, const long long content_size, cons
logprintfl (EUCAERROR, "error: out of memory in alloc_disk_item()\n");
return di;
}
- strncpy (di->id, id, EUCA_MAX_PATH);
+ safe_strncpy (di->id, id, EUCA_MAX_PATH);
if (cache_item) {
snprintf (di->base, EUCA_MAX_PATH, "%s/%s", get_cache_dir(), di->id);
snprintf (di->path, EUCA_MAX_PATH, "%s/content", di->base);
@@ -694,7 +695,7 @@ output_file * preprocess_output_path (const char * id, artifacts_spec * spec, bo
}
o->do_work = use_work;
o->do_cache = use_cache;
- strncpy (o->id, id, sizeof (o->id));
+ safe_strncpy (o->id, id, sizeof (o->id));
// is there a valid work copy already?
o->work_copy = find_disk_item (id, FALSE);
@@ -807,7 +808,7 @@ output_file * preprocess_output_path (const char * id, artifacts_spec * spec, bo
}
if (result_path) {
- strncpy (o->path, result_path, sizeof (o->path));
+ safe_strncpy (o->path, result_path, sizeof (o->path));
}
cleanup:
View
6 storage/diskfile.c
@@ -47,7 +47,7 @@ diskfile * df_create (const char * path, const long long limit_bytes, boolean ze
return NULL;
}
- strncpy (df->path, path, sizeof (df->path));
+ safe_strncpy (df->path, path, sizeof (df->path));
df->limit_bytes = round_down_sec (limit_bytes); // ensure we do not exceed the limit
df->size_sectors = df->limit_bytes/SECTOR_SIZE;
@@ -84,7 +84,7 @@ diskfile * df_open (const char * path)
return NULL;
}
- strncpy (df->path, path, sizeof (df->path));
+ safe_strncpy (df->path, path, sizeof (df->path));
df->size_sectors = df->limit_bytes/SECTOR_SIZE;
// discover the partitions, if any
@@ -293,7 +293,7 @@ int df_mount (diskfile * df, const int part, const char * path)
return ERROR;
}
- strncpy (p->mntpt, path, sizeof (p->mntpt));
+ safe_strncpy (p->mntpt, path, sizeof (p->mntpt));
if (diskutil_mount (p->lodev, p->mntpt)!=OK) {
logprintfl (EUCAERROR, "error: failed to mount '%s' on '%s'\n", p->lodev, path);
ret = ERROR;
View
13 storage/diskutil.c
@@ -792,6 +792,13 @@ static char * pruntf (boolean log_error, char *format, ...)
}
output = malloc(sizeof(char) * outsize);
+
+ while(output != NULL && (bytes = fread(output+(outsize-1025), 1, 1024, IF)) > 0) {
+ output[(outsize-1025)+bytes] = '\0';
+ outsize += 1024;
+ output = realloc(output, outsize);
+ }
+
if (output == NULL) {
logprintfl (EUCAERROR, "error: failed to allocate mem for output\n");
va_end(ap);
@@ -799,11 +806,6 @@ static char * pruntf (boolean log_error, char *format, ...)
return(NULL);
}
- while((bytes = fread(output+(outsize-1025), 1, 1024, IF)) > 0) {
- output[(outsize-1025)+bytes] = '\0';
- outsize += 1024;
- output = realloc(output, outsize);
- }
rc = pclose(IF);
if (rc) {
if (log_error) {
@@ -814,6 +816,7 @@ static char * pruntf (boolean log_error, char *format, ...)
output = NULL;
}
va_end(ap);
+
return (output);
}
View
15 storage/img.c
@@ -43,7 +43,7 @@ int parse_img_spec (img_loc * loc, const char * str)
if (!strncmp (low, "http://", 7) || !strncmp (low, "https://", 8)) {
if (strstr (str, "services/Walrus")) {
loc->type=WALRUS;
- strncpy (loc->url, str, sizeof(loc->url));
+ safe_strncpy (loc->url, str, sizeof(loc->url));
} else if (strstr (str, "dcPath=")) {
// EXAMPLE: https://192.168.7.236/folder/i-4DD50852?dcPath=ha-datacenter&dsName=S1
@@ -69,7 +69,7 @@ int parse_img_spec (img_loc * loc, const char * str)
loc->type=VSPHERE;
char path [SIZE];
- strncpy (loc->url, str, sizeof (loc->url));
+ safe_strncpy (loc->url, str, sizeof (loc->url));
strnsub (loc->host, str, pmatch[1].rm_so, pmatch[1].rm_eo, sizeof (loc->host));
strnsub (path, str, pmatch[2].rm_so, pmatch[2].rm_eo, sizeof (loc->path));
strnsub (loc->vsphere_dc, str, pmatch[3].rm_so, pmatch[3].rm_eo, sizeof (loc->vsphere_dc));
@@ -97,7 +97,7 @@ int parse_img_spec (img_loc * loc, const char * str)
strncat (loc->file, pt, sizeof(loc->file));
}
if (loc->dir[0]=='\0') {
- strncpy (loc->path, loc->file, sizeof(loc->path));
+ safe_strncpy (loc->path, loc->file, sizeof(loc->path));
} else {
snprintf (loc->path, sizeof(loc->path), "%s/%s", loc->dir, loc->file);
}
@@ -137,7 +137,7 @@ int parse_img_spec (img_loc * loc, const char * str)
char port [_SIZE]; bzero (port, sizeof (port));
strnsub (s, str, pmatch[1].rm_so, pmatch[1].rm_eo, sizeof (s));
if (s[0]=='s' ) loc->type = HTTPS;
- strncpy (loc->url, str, sizeof (loc->url));
+ safe_strncpy (loc->url, str, sizeof (loc->url));
strnsub (loc->host, str, pmatch[2].rm_so, pmatch[2].rm_eo, sizeof (loc->host));
strnsub (port, str, pmatch[4].rm_so, pmatch[4].rm_eo, sizeof (port) - 1);
loc->port = atoi (port);
@@ -147,7 +147,7 @@ int parse_img_spec (img_loc * loc, const char * str)
} else {
loc->type=PATH;
- strncpy (loc->path, str, sizeof(loc->path));
+ safe_strncpy (loc->path, str, sizeof(loc->path));
}
return 0;
@@ -157,8 +157,9 @@ int img_init_spec (img_spec * spec, const char * id, const char * loc, const img
{
bzero (spec, sizeof(spec));
- if (id && strlen(id))
- strncpy (spec->id, id, sizeof(spec->id));
+ if (id && strlen(id))
+ strncpy (spec->id, id, sizeof(spec->id) - 1);
+
else
return 0; // if no ID is given, this function just zeroes out the struct
View
6 storage/storage.c
@@ -280,7 +280,7 @@ static void add_to_cache (const char * cached_path, const long long file_size_by
return;
}
- strncpy (e->path, cached_path, BUFSIZE);
+ safe_strncpy (e->path, cached_path, BUFSIZE);
e->size_mb = file_size_mb;
e->next = NULL;
e->prev = NULL;
@@ -456,12 +456,12 @@ static long long init_cache (const char * cache_path)
if ((suffix=strstr (name, "-digest"))==NULL) {
if (strlen (X))
break; /* already saw X => fail */
- strncpy (X, name, BUFSIZE);
+ safe_strncpy (X, name, BUFSIZE);
} else {
if (strlen (X_digest))
break; /* already saw X-digest => fail */
* suffix = '\0';
- strncpy (X_digest, name, BUFSIZE);
+ safe_strncpy (X_digest, name, BUFSIZE);
}
}
closedir(image_dir);
View
53 storage/vbr.c
@@ -124,17 +124,22 @@ int vbr_add_ascii (const char * spec_str, virtualMachine * vm_type)
char * dev_spec = strtok (NULL, ":");
char * loc_spec = strtok (NULL, ":");
if (type_spec==NULL) { logprintfl (EUCAERROR, "error: invalid 'type' specification in VBR '%s'\n", spec_str); goto out_error; }
- strncpy (vbr->typeName, type_spec, sizeof (vbr->typeName));
+ safe_strncpy (vbr->typeName, type_spec, sizeof (vbr->typeName));
+
if (id_spec==NULL) { logprintfl (EUCAERROR, "error: invalid 'id' specification in VBR '%s'\n", spec_str); goto out_error; }
- strncpy (vbr->id, id_spec, sizeof (vbr->id));
+ safe_strncpy (vbr->id, id_spec, sizeof (vbr->id));
+
if (size_spec==NULL) { logprintfl (EUCAERROR, "error: invalid 'size' specification in VBR '%s'\n", spec_str); goto out_error; }
vbr->size = atoi (size_spec);
+
if (format_spec==NULL) { logprintfl (EUCAERROR, "error: invalid 'format' specification in VBR '%s'\n", spec_str); goto out_error; }
- strncpy (vbr->formatName, format_spec, sizeof (vbr->formatName));
+ safe_strncpy (vbr->formatName, format_spec, sizeof (vbr->formatName));
+
if (dev_spec==NULL) { logprintfl (EUCAERROR, "error: invalid 'guestDeviceName' specification in VBR '%s'\n", spec_str); goto out_error; }
- strncpy (vbr->guestDeviceName, dev_spec, sizeof (vbr->guestDeviceName));
+ safe_strncpy (vbr->guestDeviceName, dev_spec, sizeof (vbr->guestDeviceName));
+
if (loc_spec==NULL) { logprintfl (EUCAERROR, "error: invalid 'resourceLocation' specification in VBR '%s'\n", spec_str); goto out_error; }
- strncpy (vbr->resourceLocation, spec_str + (loc_spec - spec_copy), sizeof (vbr->resourceLocation));
+ safe_strncpy (vbr->resourceLocation, spec_str + (loc_spec - spec_copy), sizeof (vbr->resourceLocation));
free (spec_copy);
return 0;
@@ -191,7 +196,7 @@ parse_rec ( // parses the VBR as supplied by a client or user, checks values, an
} else {
vbr->locationType = NC_LOCATION_URL;
}
- strncpy (vbr->preparedResourceLocation, vbr->resourceLocation, sizeof(vbr->preparedResourceLocation));
+ safe_strncpy (vbr->preparedResourceLocation, vbr->resourceLocation, sizeof(vbr->preparedResourceLocation));
} else if (strcasestr (vbr->resourceLocation, "iqn://") == vbr->resourceLocation ||
strchr (vbr->resourceLocation, ',')) { // TODO: remove this transitionary iSCSI crutch?
vbr->locationType = NC_LOCATION_IQN;
@@ -241,7 +246,7 @@ parse_rec ( // parses the VBR as supplied by a client or user, checks values, an
if (strstr (vbr->guestDeviceName, "/dev/") == vbr->guestDeviceName) {
logprintfl (EUCAWARN, "Warning: trimming off invalid prefix '/dev/' from guestDeviceName '%s'\n", vbr->guestDeviceName);
char buf [10];
- strncpy (buf, vbr->guestDeviceName + 5, sizeof (buf));
+ safe_strncpy (buf, vbr->guestDeviceName + 5, sizeof (buf));
strncpy (vbr->guestDeviceName, buf, sizeof (vbr->guestDeviceName));
}
@@ -424,9 +429,9 @@ vbr_legacy ( // constructs VBRs for {image|kernel|ramdisk}x{Id|URL} entries (DEP
{ // create root partition VBR
virtualBootRecord * vbr = &(params->virtualBootRecord[i++]);
- strncpy (vbr->resourceLocation, imageURL, sizeof (vbr->resourceLocation));
+ safe_strncpy (vbr->resourceLocation, imageURL, sizeof (vbr->resourceLocation));
strncpy (vbr->guestDeviceName, "sda1", sizeof (vbr->guestDeviceName));
- strncpy (vbr->id, imageId, sizeof (vbr->id));
+ safe_strncpy (vbr->id, imageId, sizeof (vbr->id));
strncpy (vbr->typeName, "machine", sizeof (vbr->typeName));
vbr->size = -1;
strncpy (vbr->formatName, "none", sizeof (vbr->formatName));
@@ -507,11 +512,11 @@ static void update_vbr_with_backing_info (artifact * a)
assert (a->bb);
if (! a->must_be_file && strlen (blockblob_get_dev (a->bb))) {
- strncpy (vbr->backingPath, blockblob_get_dev (a->bb), sizeof (vbr->backingPath));
+ safe_strncpy (vbr->backingPath, blockblob_get_dev (a->bb), sizeof (vbr->backingPath));
vbr->backingType = SOURCE_TYPE_BLOCK;
} else {
assert (blockblob_get_file (a->bb));
- strncpy (vbr->backingPath, blockblob_get_file (a->bb), sizeof (vbr->backingPath));
+ safe_strncpy (vbr->backingPath, blockblob_get_file (a->bb), sizeof (vbr->backingPath));
vbr->backingType = SOURCE_TYPE_FILE;
}
vbr->size = a->bb->size_bytes;
@@ -1007,13 +1012,13 @@ artifact * art_alloc (const char * id, const char * sig, long long size_bytes, b
static int seq = 0;
a->seq = ++seq; // not thread safe, but seq's are just for debugging
- strncpy (a->instanceId, current_instanceId, sizeof (a->instanceId)); // for logging
+ safe_strncpy (a->instanceId, current_instanceId, sizeof (a->instanceId)); // for logging
logprintfl (EUCADEBUG, "[%s] allocated artifact %03d|%s size=%lld vbr=%u cache=%d file=%d\n", a->instanceId, seq, id, size_bytes, vbr, may_be_cached, must_be_file);
if (id)
- strncpy (a->id, id, sizeof (a->id));
+ safe_strncpy (a->id, id, sizeof (a->id));
if (sig)
- strncpy (a->sig, sig, sizeof (a->sig));
+ safe_strncpy (a->sig, sig, sizeof (a->sig));
a->size_bytes = size_bytes;
a->may_be_cached = may_be_cached;
a->must_be_file = must_be_file;
@@ -1121,9 +1126,9 @@ static artifact * art_alloc_vbr (virtualBootRecord * vbr, boolean do_make_work_c
artifact * a2 = NULL;
char art_id [48];
- strncpy (art_id, a->id, sizeof (art_id));
+ safe_strncpy (art_id, a->id, sizeof (art_id));
char art_sig [ART_SIG_MAX];
- strncpy (art_sig, a->sig, sizeof (art_sig));
+ safe_strncpy (art_sig, a->sig, sizeof (art_sig));
if (sshkey) { // if SSH key is included, recalculate sig and ID
if (strlen(sshkey) > sizeof(a->sshkey)) {
@@ -1297,7 +1302,7 @@ art_alloc_disk ( // allocates a 'keyed' disk artifact and possibly the underlyin
// (same effect as passing it into vbr_alloc_tree)
void art_set_instanceId (const char * instanceId)
{
- strncpy (current_instanceId, instanceId, sizeof (current_instanceId));
+ safe_strncpy (current_instanceId, instanceId, sizeof (current_instanceId));
}
artifact * // returns pointer to the root of artifact tree or NULL on error
@@ -1309,7 +1314,7 @@ vbr_alloc_tree ( // creates a tree of artifacts for a given VBR (caller must fre
const char * instanceId) // ID of the instance (for logging purposes only)
{
if (instanceId)
- strncpy (current_instanceId, instanceId, sizeof (current_instanceId));
+ safe_strncpy (current_instanceId, instanceId, sizeof (current_instanceId));
// sort vbrs into prereq [] and parts[] so they can be approached in the right order
virtualBootRecord * prereq_vbrs [EUCA_MAX_VBRS];
@@ -1488,7 +1493,7 @@ find_or_create_artifact ( // finds and opens or creates artifact's blob either i
if (work_prefix && strlen (work_prefix))
snprintf (id_work, sizeof (id_work), "%s/%s", work_prefix, a->id);
else
- strncpy (id_work, a->id, sizeof (id_work));
+ safe_strncpy (id_work, a->id, sizeof (id_work));
// see if a file and if it exists
if (a->id_is_path) {
@@ -1711,9 +1716,9 @@ static void add_vbr (virtualMachine * vm,
virtualBootRecord * vbr = vm->virtualBootRecord + vm->virtualBootRecordLen++;
vbr->size = size;
if (formatName)
- strncpy (vbr->formatName, formatName, sizeof (vbr->formatName));
+ safe_strncpy (vbr->formatName, formatName, sizeof (vbr->formatName));
if (id)
- strncpy (vbr->id, id, sizeof (vbr->id));
+ safe_strncpy (vbr->id, id, sizeof (vbr->id));
vbr->format = format;
vbr->type = type;
vbr->locationType = locationType;
@@ -1721,7 +1726,7 @@ static void add_vbr (virtualMachine * vm,
vbr->partitionNumber = partitionNumber;
vbr->guestDeviceBus = guestDeviceBus;
if (preparedResourceLocation)
- strncpy (vbr->preparedResourceLocation, preparedResourceLocation, sizeof (vbr->preparedResourceLocation));
+ safe_strncpy (vbr->preparedResourceLocation, preparedResourceLocation, sizeof (vbr->preparedResourceLocation));
}
static int next_instances_slot = 0;
@@ -1736,7 +1741,7 @@ static int provision_vm (const char * id, const char * sshkey, const char * eki,
{
pthread_mutex_lock (&competitors_mutex);
virtualMachine * vm = &(vm_slots [next_instances_slot]); // we don't use vm_slots[] pointers in code
- strncpy (vm_ids [next_instances_slot], id, PATH_MAX);
+ safe_strncpy (vm_ids [next_instances_slot], id, PATH_MAX);
next_instances_slot++;
pthread_mutex_unlock (&competitors_mutex);
@@ -1747,7 +1752,7 @@ static int provision_vm (const char * id, const char * sshkey, const char * eki,
add_vbr (vm, VBR_SIZE, NC_FORMAT_EXT3, "ext3", "none", NC_RESOURCE_EPHEMERAL, NC_LOCATION_NONE, 0, 3, BUS_TYPE_SCSI, NULL);
add_vbr (vm, VBR_SIZE, NC_FORMAT_SWAP, "swap", "none", NC_RESOURCE_SWAP, NC_LOCATION_NONE, 0, 2, BUS_TYPE_SCSI, NULL);
- strncpy (current_instanceId, strstr (id, "/") + 1, sizeof (current_instanceId));
+ safe_strncpy (current_instanceId, strstr (id, "/") + 1, sizeof (current_instanceId));
artifact * sentinel = vbr_alloc_tree (vm, FALSE, do_make_work_copy, sshkey, id);
if (sentinel == NULL) {
printf ("error: vbr_alloc_tree failed id=%s\n", id);
View
4 storage/walrus.c
@@ -117,7 +117,7 @@ static int walrus_request (const char * walrus_op, const char * verb, const char
int code = ERROR;
char url [BUFSIZE];
- strncpy (url, requested_url, BUFSIZE);
+ safe_strncpy (url, requested_url, BUFSIZE);
#if defined(CAN_GZIP)
if (do_compress)
snprintf (url, BUFSIZE, "%s%s", requested_url, "?IsCompressed=true");
@@ -139,7 +139,7 @@ static int walrus_request (const char * walrus_op, const char * verb, const char
return code;
}
- int fd = open (outfile, O_CREAT | O_WRONLY); // we do not truncate the file
+ int fd = open (outfile, O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR); // we do not truncate the file
if (fd==-1 || lseek (fd, 0, SEEK_SET)==-1) {
logprintfl (EUCAERROR, "{%u} walrus_request: failed to open %s for writing\n", (unsigned int)pthread_self(), outfile);
return code;
View
12 util/adb-helpers.h
@@ -82,21 +82,21 @@ static inline void copy_vm_type_from_adb (virtualMachine * params, adb_virtualMa
params->mem = adb_virtualMachineType_get_memory(vm_type, env);
params->cores = adb_virtualMachineType_get_cores(vm_type, env);
params->disk = adb_virtualMachineType_get_disk(vm_type, env);
- strncpy(params->name, adb_virtualMachineType_get_name(vm_type, env), sizeof(params->name));
+ safe_strncpy(params->name, adb_virtualMachineType_get_name(vm_type, env), sizeof(params->name));
params->virtualBootRecordLen = adb_virtualMachineType_sizeof_virtualBootRecord(vm_type, env);
for (i = 0; i<EUCA_MAX_VBRS && i<params->virtualBootRecordLen; i++) {
adb_virtualBootRecordType_t * vbr_type = adb_virtualMachineType_get_virtualBootRecord_at (vm_type, env, i);
- strncpy (params->virtualBootRecord[i].resourceLocation, adb_virtualBootRecordType_get_resourceLocation(vbr_type, env), CHAR_BUFFER_SIZE);
+ safe_strncpy (params->virtualBootRecord[i].resourceLocation, adb_virtualBootRecordType_get_resourceLocation(vbr_type, env), CHAR_BUFFER_SIZE);
logprintfl (EUCADEBUG2, "resource location: %s\n", params->virtualBootRecord[i].resourceLocation);
- strncpy (params->virtualBootRecord[i].guestDeviceName, adb_virtualBootRecordType_get_guestDeviceName(vbr_type, env), SMALL_CHAR_BUFFER_SIZE);
+ safe_strncpy (params->virtualBootRecord[i].guestDeviceName, adb_virtualBootRecordType_get_guestDeviceName(vbr_type, env), SMALL_CHAR_BUFFER_SIZE);
logprintfl (EUCADEBUG2, " guest dev name: %s\n", params->virtualBootRecord[i].guestDeviceName);
params->virtualBootRecord[i].size = adb_virtualBootRecordType_get_size(vbr_type, env);
logprintfl (EUCADEBUG2, " size: %d\n", params->virtualBootRecord[i].size);
- strncpy (params->virtualBootRecord[i].formatName, adb_virtualBootRecordType_get_format(vbr_type, env), SMALL_CHAR_BUFFER_SIZE);
+ safe_strncpy (params->virtualBootRecord[i].formatName, adb_virtualBootRecordType_get_format(vbr_type, env), SMALL_CHAR_BUFFER_SIZE);
logprintfl (EUCADEBUG2, " format: %s\n", params->virtualBootRecord[i].formatName);
- strncpy (params->virtualBootRecord[i].id, adb_virtualBootRecordType_get_id(vbr_type, env), SMALL_CHAR_BUFFER_SIZE);
+ safe_strncpy (params->virtualBootRecord[i].id, adb_virtualBootRecordType_get_id(vbr_type, env), SMALL_CHAR_BUFFER_SIZE);
logprintfl (EUCADEBUG2, " id: %s\n", params->virtualBootRecord[i].id);
- strncpy (params->virtualBootRecord[i].typeName, adb_virtualBootRecordType_get_type(vbr_type, env), SMALL_CHAR_BUFFER_SIZE);
+ safe_strncpy (params->virtualBootRecord[i].typeName, adb_virtualBootRecordType_get_type(vbr_type, env), SMALL_CHAR_BUFFER_SIZE);
logprintfl (EUCADEBUG2, " type: %s\n", params->virtualBootRecord[i].typeName);
}
}
View
44 util/data.c
@@ -88,9 +88,9 @@ int allocate_virtualMachine(virtualMachine *out, const virtualMachine *in)
int allocate_netConfig(netConfig *out, char *pvMac, char *pvIp, char *pbIp, int vlan, int networkIndex) {
if (out != NULL) {
- if (pvMac) strncpy(out->privateMac,pvMac,24);
- if (pvIp) strncpy(out->privateIp,pvIp,24);
- if (pbIp) strncpy(out->publicIp,pbIp,24);
+ if (pvMac) safe_strncpy(out->privateMac,pvMac,24);
+ if (pvIp) safe_strncpy(out->privateIp,pvIp,24);
+ if (pbIp) safe_strncpy(out->publicIp,pbIp,24);
out->networkIndex = networkIndex;
out->vlan = vlan;
}
@@ -133,22 +133,22 @@ ncInstance * allocate_instance (char *uuid,
if (!inst) return(NULL);
if (userData) {
- strncpy(inst->userData, userData, CHAR_BUFFER_SIZE*10);
+ safe_strncpy(inst->userData, userData, CHAR_BUFFER_SIZE*10);
}
if (launchIndex) {
- strncpy(inst->launchIndex, launchIndex, CHAR_BUFFER_SIZE);
+ safe_strncpy(inst->launchIndex, launchIndex, CHAR_BUFFER_SIZE);
}
if (platform) {
- strncpy(inst->platform, platform, CHAR_BUFFER_SIZE);
+ safe_strncpy(inst->platform, platform, CHAR_BUFFER_SIZE);
}
inst->groupNamesSize = groupNamesSize;
if (groupNames && groupNamesSize) {
int i;
for (i=0; groupNames[i] && i<groupNamesSize; i++) {
- strncpy(inst->groupNames[i], groupNames[i], CHAR_BUFFER_SIZE);
+ safe_strncpy(inst->groupNames[i], groupNames[i], CHAR_BUFFER_SIZE);
}
}
inst->volumesSize = 0;
@@ -158,32 +158,32 @@ ncInstance * allocate_instance (char *uuid,
}
if (uuid) {
- strncpy(inst->uuid, uuid, CHAR_BUFFER_SIZE);
+ safe_strncpy(inst->uuid, uuid, CHAR_BUFFER_SIZE);
}
if (instanceId) {
- strncpy(inst->instanceId, instanceId, CHAR_BUFFER_SIZE);
+ safe_strncpy(inst->instanceId, instanceId, CHAR_BUFFER_SIZE);
}
if (keyName) {
- strncpy(inst->keyName, keyName, CHAR_BUFFER_SIZE*4);
+ safe_strncpy(inst->keyName, keyName, CHAR_BUFFER_SIZE*4);
}
if (reservationId) {
- strncpy(inst->reservationId, reservationId, CHAR_BUFFER_SIZE);
+ safe_strncpy(inst->reservationId, reservationId, CHAR_BUFFER_SIZE);
}
if (stateName) {
- strncpy(inst->stateName, stateName, CHAR_BUFFER_SIZE);
+ safe_strncpy(inst->stateName, stateName, CHAR_BUFFER_SIZE);
}
if (userId) {
- strncpy(inst->userId, userId, CHAR_BUFFER_SIZE);
+ safe_strncpy(inst->userId, userId, CHAR_BUFFER_SIZE);
}
if (params) {
memcpy(&(inst->params), params, sizeof(virtualMachine));
}
inst->stateCode = stateCode;
- strncpy (inst->bundleTaskStateName, bundling_progress_names [NOT_BUNDLING], CHAR_BUFFER_SIZE);
+ safe_strncpy (inst->bundleTaskStateName, bundling_progress_names [NOT_BUNDLING], CHAR_BUFFER_SIZE);
inst->expiryTime = expiryTime;
return inst;
}
@@ -213,12 +213,12 @@ ncResource * allocate_resource (char *nodeStatus,
if (!nodeStatus) return NULL;
if (!(res = malloc(sizeof(ncResource)))) return NULL;
bzero(res, sizeof(ncResource));
- strncpy(res->nodeStatus, nodeStatus, CHAR_BUFFER_SIZE);
+ safe_strncpy(res->nodeStatus, nodeStatus, CHAR_BUFFER_SIZE);
if (iqn) {
- strncpy(res->iqn, iqn, CHAR_BUFFER_SIZE);
+ safe_strncpy(res->iqn, iqn, CHAR_BUFFER_SIZE);
}
if (publicSubnets) {
- strncpy(res->publicSubnets, publicSubnets, CHAR_BUFFER_SIZE);
+ safe_strncpy(res->publicSubnets, publicSubnets, CHAR_BUFFER_SIZE);
}
res->memorySizeMax = memorySizeMax;
res->memorySizeAvailable = memorySizeAvailable;
@@ -370,11 +370,11 @@ ncVolume * add_volume (ncInstance * instance, char *volumeId, char *remoteDev, c
if ( ! strncmp (v->volumeId, volumeId, CHAR_BUFFER_SIZE) ) {
return NULL; /* already there */
} else {
- strncpy (v->volumeId, volumeId, CHAR_BUFFER_SIZE);
- strncpy (v->remoteDev, remoteDev, CHAR_BUFFER_SIZE);
- strncpy (v->localDev, localDev , CHAR_BUFFER_SIZE);
- strncpy (v->localDevReal, localDevReal , CHAR_BUFFER_SIZE);
- strncpy (v->stateName, stateName , CHAR_BUFFER_SIZE);
+ safe_strncpy (v->volumeId, volumeId, CHAR_BUFFER_SIZE);
+ safe_strncpy (v->remoteDev, remoteDev, CHAR_BUFFER_SIZE);
+ safe_strncpy (v->localDev, localDev , CHAR_BUFFER_SIZE);
+ safe_strncpy (v->localDevReal, localDevReal , CHAR_BUFFER_SIZE);
+ safe_strncpy (v->stateName, stateName , CHAR_BUFFER_SIZE);
instance->volumesSize++;
}
View
19 util/misc.c
@@ -360,7 +360,11 @@ int check_directory(char *dir) {
if (S_ISLNK(mystat.st_mode)) { // links to dirs are OK
char tmp [4096];
snprintf (tmp, 4096, "%s/", dir);
- lstat (tmp, &mystat);
+
+ rc = lstat (tmp, &mystat);
+ if (rc < 0)
+ return 1;
+
if (S_ISDIR(mystat.st_mode)) {
return 0;
}
@@ -1987,7 +1991,12 @@ int ensure_directories_exist (const char * path, int is_file_path, const char *
return -1;
}
ret = 1; // we created a directory
- diskutil_ch(path_copy, user, group, mode);
+
+ if(diskutil_ch(path_copy, user, group, mode) != OK) {
+ logprintfl (EUCAERROR, "error: failed to change perms on path %s\n", path_copy);
+ free (path_copy);
+ return -1;
+ }
// chmod (path_copy, mode); // ensure perms are right despite mask
}
path_copy[i] = '/'; // restore the slash
@@ -2023,6 +2032,12 @@ int safe_mkstemp(char *template){
return(ret);
}
+char* safe_strncpy(char *s1, const char *s2, size_t len) {
+ char* ret = strncpy(s1, s2, len);
+ s1[len-1] = '\0';
+ return ret;
+}
+
/////////////////////////////////////////////// unit testing code ///////////////////////////////////////////////////
#ifdef _UNIT_TEST
View
1  util/misc.h
@@ -158,6 +158,7 @@ int check_file_newer_than(char *file, time_t mtime);
// safe version of common fuctions
char *safe_mkdtemp(char *);
int safe_mkstemp(char *);
+char* safe_strncpy(char *s1, const char *s2, size_t len);
// argument checker
int param_check(char *func, ...);
Please sign in to comment.
Something went wrong with that request. Please try again.