Check allocation error and free on error [CID-114]

This commit is contained in:
Love Hornquist Astrand
2009-07-30 10:32:33 +02:00
parent d8db9d5a5a
commit dfffe6d567

View File

@@ -550,14 +550,20 @@ void mec(char *msg, enum protection_level level)
}
buf_size = strlen(msg) + 2;
buf = malloc(buf_size);
if (buf == NULL) {
reply(501, "Failed to allocate %lu", (unsigned long)buf_size);
return;
}
len = base64_decode(msg, buf);
command_prot = level;
if(len == (size_t)-1) {
free(buf);
reply(501, "Failed to base64-decode command");
return;
}
len = (*mech->decode)(app_data, buf, len, level);
if(len == (size_t)-1) {
free(buf);
reply(535, "Failed to decode command");
return;
}