--- app_voicemail.c.orig 2006-12-20 13:39:53.482379000 +0900 +++ app_voicemail.c 2006-12-20 14:24:39.104113600 +0900 @@ -927,9 +927,15 @@ } if (!strcasecmp(coltitle, "recording")) { off_t offset; - res = SQLGetData(stmt, x + 1, SQL_BINARY, NULL, 0, &colsize); + colsize = 0; + res = SQLGetData(stmt, x + 1, SQL_C_BINARY, (void *) 1, 0, &colsize); + if (res == SQL_ERROR) { + ast_log(LOG_WARNING, "SQL GetData error!\n[%s]\n\n", sql); + SQLFreeHandle (SQL_HANDLE_STMT, stmt); + goto yuck; + } fdlen = colsize; - if (fd > -1) { + if (fd > -1 && fdlen > 0) { char tmp[1]=""; lseek(fd, fdlen - 1, SEEK_SET); if (write(fd, tmp, 1) != 1) { @@ -939,14 +945,13 @@ } /* Read out in small chunks */ for (offset = 0; offset < colsize; offset += CHUNKSIZE) { - /* +1 because SQLGetData likes null-terminating binary data */ - if ((fdm = mmap(NULL, CHUNKSIZE + 1, PROT_READ | PROT_WRITE, MAP_SHARED, fd, offset)) == -1) { + if ((fdm = mmap(NULL, CHUNKSIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, offset)) == -1) { ast_log(LOG_WARNING, "Could not mmap the output file: %s (%d)\n", strerror(errno), errno); SQLFreeHandle(SQL_HANDLE_STMT, stmt); goto yuck; } else { - res = SQLGetData(stmt, x + 1, SQL_BINARY, fdm, CHUNKSIZE + 1, NULL); - munmap(fdm, 0); + res = SQLGetData(stmt, x + 1, SQL_C_BINARY, fdm, CHUNKSIZE, NULL); + munmap(fdm, CHUNKSIZE); if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) { ast_log(LOG_WARNING, "SQL Get Data error!\n[%s]\n\n", sql); unlink(full_fn);