-fixes strncpy & buf size

This commit is contained in:
satbaby
2012-08-07 18:51:44 +02:00
parent af74eb4f7e
commit 7359504dd7
15 changed files with 48 additions and 44 deletions

View File

@@ -320,7 +320,7 @@ void CRecordInstance::GetPids(CZapitChannel * channel)
for (uint32_t i = 0; i < channel->getAudioChannelCount(); i++) {
CZapitClient::responseGetAPIDs response;
response.pid = channel->getAudioPid(i);
strncpy(response.desc, channel->getAudioChannel(i)->description.c_str(), DESC_MAX_LEN);
strncpy(response.desc, channel->getAudioChannel(i)->description.c_str(), DESC_MAX_LEN - 1);
response.is_ac3 = response.is_aac = 0;
if (channel->getAudioChannel(i)->audioChannelType == CZapitAudioChannel::AC3) {
response.is_ac3 = 1;
@@ -343,12 +343,12 @@ void CRecordInstance::ProcessAPIDnames()
has_unresolved_ctags= true;
if ( strlen( allpids.APIDs[count].desc ) == 3 )
strncpy( allpids.APIDs[count].desc, getISO639Description( allpids.APIDs[count].desc ),DESC_MAX_LEN );
strncpy( allpids.APIDs[count].desc, getISO639Description( allpids.APIDs[count].desc ),DESC_MAX_LEN -1 );
if ( allpids.APIDs[count].is_ac3 && !strstr(allpids.APIDs[count].desc, " (AC3)"))
strncat(allpids.APIDs[count].desc, " (AC3)", DESC_MAX_LEN - strlen(allpids.APIDs[count].desc));
strncat(allpids.APIDs[count].desc, " (AC3)", DESC_MAX_LEN - strlen(allpids.APIDs[count].desc) -1);
else if (allpids.APIDs[count].is_aac && !strstr(allpids.APIDs[count].desc, " (AAC)"))
strncat(allpids.APIDs[count].desc, " (AAC)", DESC_MAX_LEN - strlen(allpids.APIDs[count].desc));
strncat(allpids.APIDs[count].desc, " (AAC)", DESC_MAX_LEN - strlen(allpids.APIDs[count].desc) -1);
}
if(has_unresolved_ctags && (epgid != 0)) {
@@ -358,11 +358,11 @@ void CRecordInstance::ProcessAPIDnames()
for(unsigned int j=0; j< allpids.APIDs.size(); j++) {
if(allpids.APIDs[j].component_tag == tags[i].componentTag) {
if(!tags[i].component.empty()) {
strncpy(allpids.APIDs[j].desc, tags[i].component.c_str(), DESC_MAX_LEN);
strncpy(allpids.APIDs[j].desc, tags[i].component.c_str(), DESC_MAX_LEN -1);
if (allpids.APIDs[j].is_ac3 && !strstr(allpids.APIDs[j].desc, " (AC3)"))
strncat(allpids.APIDs[j].desc, " (AC3)", DESC_MAX_LEN - strlen(allpids.APIDs[j].desc));
strncat(allpids.APIDs[j].desc, " (AC3)", DESC_MAX_LEN - strlen(allpids.APIDs[j].desc)-1);
else if (allpids.APIDs[j].is_aac && !strstr(allpids.APIDs[j].desc, " (AAC)"))
strncat(allpids.APIDs[j].desc, " (AAC)", DESC_MAX_LEN - strlen(allpids.APIDs[j].desc));
strncat(allpids.APIDs[j].desc, " (AAC)", DESC_MAX_LEN - strlen(allpids.APIDs[j].desc)-1);
}
allpids.APIDs[j].component_tag = -1;
break;
@@ -598,16 +598,16 @@ record_error_msg_t CRecordInstance::MakeFileName(CZapitChannel * channel)
if (errno == ENOENT) {
res = safe_mkdir(filename);
if (res == 0)
strncat(filename,"/",FILENAMEBUFFERSIZE - strlen(filename));
strncat(filename,"/",FILENAMEBUFFERSIZE - strlen(filename) -1);
else
perror("[vcrcontrol] mkdir");
} else
perror("[vcrcontrol] stat");
} else
// directory exists
strncat(filename,"/",FILENAMEBUFFERSIZE - strlen(filename));
strncat(filename,"/",FILENAMEBUFFERSIZE - strlen(filename)-1);
} else
strncat(filename, "_",FILENAMEBUFFERSIZE - strlen(filename));
strncat(filename, "_",FILENAMEBUFFERSIZE - strlen(filename)-1);
}
pos = strlen(filename);
@@ -631,7 +631,7 @@ record_error_msg_t CRecordInstance::MakeFileName(CZapitChannel * channel)
pos += strftime(&(filename[pos]), sizeof(filename) - pos - 1, "%Y%m%d_%H%M%S", localtime(&t));
if(autoshift)
strncat(filename, "_temp",FILENAMEBUFFERSIZE - strlen(filename));
strncat(filename, "_temp",FILENAMEBUFFERSIZE - strlen(filename)-1);
return RECORD_OK;
}