Check allocation error and free on error [CID-114]
authorLove Hornquist Astrand <lha@h5l.org>
Thu, 30 Jul 2009 08:32:33 +0000 (10:32 +0200)
committerLove Hornquist Astrand <lha@h5l.org>
Thu, 30 Jul 2009 08:32:33 +0000 (10:32 +0200)
appl/ftp/ftp/security.c

index 77ed2f030b8269e5735e6edfa28f44af89f2e3fa..f186ab8189551d532a207d55def94e822d7cc56f 100644 (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;
     }