~ubuntu-branches/ubuntu/utopic/clamav/utopic-security

« back to all changes in this revision

Viewing changes to sigtool/vba.c

  • Committer: Package Import Robot
  • Author(s): Scott Kitterman
  • Date: 2014-02-01 11:06:17 UTC
  • mfrom: (0.35.37 sid)
  • Revision ID: package-import@ubuntu.com-20140201110617-33h2xxk09dep0ui4
Tags: 0.98.1+dfsg-1ubuntu1
* Merge from Debian unstable.  Remaining changes:
  - Drop build-dep on electric-fence (in Universe)
  - Add apparmor profiles for clamd and freshclam along with maintainer
    script changes
  - Add autopkgtest

Show diffs side-by-side

added added

removed removed

Lines of Context:
54
54
 
55
55
cli_ctx *convenience_ctx(int fd) {
56
56
    cli_ctx *ctx;
57
 
    if(!(ctx = malloc(sizeof(*ctx))) ||
58
 
       !(ctx->engine = cl_engine_new()) ||
59
 
       !(ctx->fmap = cli_malloc(sizeof(struct F_MAP *))) ||
60
 
       !(*ctx->fmap = fmap(fd, 0, 0))) {
61
 
        printf("malloc failed\n");
62
 
        return NULL; /* and leak */
 
57
    struct cl_engine *engine;
 
58
 
 
59
    ctx = malloc(sizeof(*ctx));
 
60
    if(!ctx){
 
61
        printf("ctx malloc failed\n");
 
62
        return NULL;
 
63
    }
 
64
 
 
65
    ctx->engine = engine = cl_engine_new();
 
66
    if(!(ctx->engine)){     
 
67
        printf("engine malloc failed\n");
 
68
        free(ctx);
 
69
        return NULL;
 
70
    }   
 
71
 
 
72
    ctx->fmap = cli_malloc(sizeof(struct F_MAP *));
 
73
    if(!(ctx->fmap)){
 
74
        printf("fmap malloc failed\n");
 
75
        free(engine);
 
76
        free(ctx);
 
77
        return NULL;
 
78
    }
 
79
 
 
80
    if(!(*ctx->fmap = fmap(fd, 0, 0))){
 
81
        printf("fmap failed\n");
 
82
        free(ctx->fmap);
 
83
        free(engine);
 
84
        free(ctx);
 
85
        return NULL;
63
86
    }
64
87
    return ctx;
65
88
}
66
89
 
67
 
void destroy_ctx(cli_ctx *ctx) {
68
 
    close((*(ctx->fmap))->fd);
 
90
void destroy_ctx(int desc, cli_ctx *ctx) {
69
91
    funmap(*(ctx->fmap));
 
92
    close(desc);
70
93
    free(ctx->fmap);
71
94
    cl_engine_free((struct cl_engine *)ctx->engine);
72
95
    free(ctx);
983
1006
{
984
1007
    DIR *dd;
985
1008
    struct dirent *dent;
986
 
    struct stat statbuf;
 
1009
    STATBUF statbuf;
987
1010
    char *fname;
988
1011
    const char *tmpdir;
989
1012
    char *dir;
990
1013
    int ret = CL_CLEAN, desc;
991
1014
    cli_ctx *ctx;
992
1015
 
993
 
 
 
1016
    fname = NULL;
994
1017
    if ((dd = opendir (dirname)) != NULL) {
995
1018
        while ((dent = readdir (dd))) {
996
1019
            if (dent->d_ino) {
997
1020
                if (strcmp (dent->d_name, ".") && strcmp (dent->d_name, "..")) {
998
1021
                    /* build the full name */
999
1022
                    fname = (char *) cli_calloc (strlen (dirname) + strlen (dent->d_name) + 2, sizeof (char));
 
1023
                    if(!fname){
 
1024
                        closedir(dd);
 
1025
                        return -1;          
 
1026
                    }   
1000
1027
                    sprintf (fname, "%s"PATHSEP"%s", dirname, dent->d_name);
1001
1028
 
1002
1029
                    /* stat the file */
1003
 
                    if (lstat (fname, &statbuf) != -1) {
 
1030
                    if (LSTAT (fname, &statbuf) != -1) {
1004
1031
                        if (S_ISDIR (statbuf.st_mode) && !S_ISLNK (statbuf.st_mode)) {
1005
1032
                            if (sigtool_scandir (fname, hex_output)) {
1006
1033
                                free (fname);
1016
1043
                                dir = cli_gentemp (tmpdir);
1017
1044
                                if(!dir) {
1018
1045
                                    printf("cli_gentemp() failed\n");
 
1046
                                    free(fname);
1019
1047
                                    closedir (dd);
1020
1048
                                    return -1;
1021
1049
                                }
1022
1050
 
1023
1051
                                if (mkdir (dir, 0700)) {
1024
1052
                                    printf ("Can't create temporary directory %s\n", dir);
 
1053
                                    free(fname);
1025
1054
                                    closedir (dd);
1026
1055
                                    free(dir);
1027
1056
                                    return CL_ETMPDIR;
1029
1058
 
1030
1059
                                if ((desc = open (fname, O_RDONLY|O_BINARY)) == -1) {
1031
1060
                                    printf ("Can't open file %s\n", fname);
 
1061
                                    free(fname);
1032
1062
                                    closedir (dd);
1033
1063
                                    free(dir);
1034
1064
                                    return 1;
1035
1065
                                }
1036
1066
 
1037
1067
                                if(!(ctx = convenience_ctx(desc))) {
 
1068
                                    free(fname);        
1038
1069
                                    close(desc);
1039
1070
                                    closedir(dd);
1040
1071
                                    free(dir);
1042
1073
                                }
1043
1074
                                if ((ret = cli_ole2_extract (dir, ctx, &vba))) {
1044
1075
                                    printf ("ERROR %s\n", cl_strerror (ret));
1045
 
                                    destroy_ctx(ctx);
 
1076
                                    destroy_ctx(desc, ctx);
1046
1077
                                    cli_rmdirs (dir);
1047
1078
                                    free (dir);
1048
1079
                                    closedir (dd);
 
1080
                                    free(fname);
1049
1081
                                    return ret;
1050
1082
                                }
1051
1083
 
1052
1084
                                if(vba)
1053
1085
                                    sigtool_vba_scandir (dir, hex_output, vba);
1054
 
                                destroy_ctx(ctx);
 
1086
                                destroy_ctx(desc, ctx);
1055
1087
                                cli_rmdirs (dir);
1056
1088
                                free (dir);
1057
1089
                            }
1077
1109
    vba_project_t *vba_project;
1078
1110
    DIR *dd;
1079
1111
    struct dirent *dent;
1080
 
    struct stat statbuf;
 
1112
    STATBUF statbuf;
1081
1113
    char *fullname, vbaname[1024], *hash;
1082
1114
    unsigned char *data;
1083
1115
    uint32_t hashcnt;
1171
1203
                    sprintf (fullname, "%s"PATHSEP"%s", dirname, dent->d_name);
1172
1204
 
1173
1205
                    /* stat the file */
1174
 
                    if (lstat (fullname, &statbuf) != -1) {
 
1206
                    if (LSTAT (fullname, &statbuf) != -1) {
1175
1207
                        if (S_ISDIR (statbuf.st_mode) && !S_ISLNK (statbuf.st_mode))
1176
1208
                            sigtool_vba_scandir (fullname, hex_output, U); 
1177
1209
                    }