Permalink
Browse files

fixes to C code

  • Loading branch information...
1 parent 21becf3 commit 4c71ae92c682c6c1068463d8ce70410879bd6678 @rusvika rusvika committed Jun 21, 2011
@@ -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
@@ -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);
}
}
}
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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);
}
/*
Oops, something went wrong.

0 comments on commit 4c71ae9

Please sign in to comment.