NULL check after malloc
This commit is contained in:
parent
469a28c49a
commit
d1509d6096
2
3rdparty/udns/rblcheck.c
vendored
2
3rdparty/udns/rblcheck.c
vendored
@ -339,12 +339,14 @@ int main(int argc, char **argv) {
|
|||||||
char *home = getenv("HOME");
|
char *home = getenv("HOME");
|
||||||
if (!home) home = ".";
|
if (!home) home = ".";
|
||||||
path = malloc(strlen(home) + 1 + sizeof(".rblcheckrc"));
|
path = malloc(strlen(home) + 1 + sizeof(".rblcheckrc"));
|
||||||
|
if (path) {
|
||||||
sprintf(path, "%s/.rblcheckrc", home);
|
sprintf(path, "%s/.rblcheckrc", home);
|
||||||
if (!addzonefile(path))
|
if (!addzonefile(path))
|
||||||
addzonefile("/etc/rblcheckrc");
|
addzonefile("/etc/rblcheckrc");
|
||||||
free(path);
|
free(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (!nzones)
|
if (!nzones)
|
||||||
error(1, "no service (zone) list specified (-s or -S option)");
|
error(1, "no service (zone) list specified (-s or -S option)");
|
||||||
|
|
||||||
|
@ -67,8 +67,10 @@ void BufferedLogCallback::operator()(sgDebugClass c, sgDebugPriority p,
|
|||||||
vector_cstring::value_type msg;
|
vector_cstring::value_type msg;
|
||||||
if (aMessage.size() >= d->m_maxLength) {
|
if (aMessage.size() >= d->m_maxLength) {
|
||||||
msg = (vector_cstring::value_type) malloc(d->m_maxLength);
|
msg = (vector_cstring::value_type) malloc(d->m_maxLength);
|
||||||
|
if (msg) {
|
||||||
strncpy((char*) msg, aMessage.c_str(), d->m_maxLength - 1);
|
strncpy((char*) msg, aMessage.c_str(), d->m_maxLength - 1);
|
||||||
msg[d->m_maxLength - 1] = 0; // add final NULL byte
|
msg[d->m_maxLength - 1] = 0; // add final NULL byte
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
msg = (vector_cstring::value_type) strdup(aMessage.c_str());
|
msg = (vector_cstring::value_type) strdup(aMessage.c_str());
|
||||||
}
|
}
|
||||||
|
@ -239,6 +239,7 @@ IPAddress::IPAddress( const IPAddress& other ) :
|
|||||||
{
|
{
|
||||||
if (other.addr) {
|
if (other.addr) {
|
||||||
addr = (struct sockaddr_in*) malloc(sizeof(struct sockaddr_in));
|
addr = (struct sockaddr_in*) malloc(sizeof(struct sockaddr_in));
|
||||||
|
if (addr)
|
||||||
memcpy(addr, other.addr, sizeof(struct sockaddr_in));
|
memcpy(addr, other.addr, sizeof(struct sockaddr_in));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -252,6 +253,7 @@ const IPAddress& IPAddress::operator=(const IPAddress& other)
|
|||||||
|
|
||||||
if (other.addr) {
|
if (other.addr) {
|
||||||
addr = (struct sockaddr_in*) malloc(sizeof(struct sockaddr_in));
|
addr = (struct sockaddr_in*) malloc(sizeof(struct sockaddr_in));
|
||||||
|
if (addr)
|
||||||
memcpy(addr, other.addr, sizeof(struct sockaddr_in));
|
memcpy(addr, other.addr, sizeof(struct sockaddr_in));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user