【问题标题】:Write output of fts(3) to file将 fts(3) 的输出写入文件
【发布时间】:2013-10-29 03:46:43
【问题描述】:

我正在开发一个文件模糊器,它可以改变音乐文件并将它们提供给 iTunes。我已经开发了代码来改变音乐文件,但我想使用多个音乐文件来增加代码覆盖率。所以我想遍历我的 iTunes 库并将文件路径加载到缓冲区或文件中;无论哪种方式都足够了。我在这里有这段代码,它在fprintf 函数上出现了段错误。

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <errno.h>
#include <fts.h>

    int compare (const FTSENT**, const FTSENT**);

int main(void)
{   
FILE * musicPaths;
musicPaths = fopen("Users/NahNig/music_paths", "wb");
char *p1 = "/Users/NahNig/Music/iTunes/iTunes Media/Music";
char *p2 = NULL;
char *path[1];
path[0] = p1;
path[1] = p2;
FTS* file_system = NULL;
FTSENT* child =    NULL;
FTSENT* parent =   NULL;

file_system = fts_open(path, FTS_COMFOLLOW | FTS_NOCHDIR, &compare);

if (NULL != file_system)
{
    while( (parent = fts_read(file_system)) != NULL)
    {
        child = fts_children(file_system,0);

        if (errno != 0)
        {
            perror("fts_children");
        }

        while ((NULL != child)
            && (NULL != child->fts_link))
        {
            child = child->fts_link;
            fprintf(musicPaths, "%s%s\n", child->fts_path, child->fts_name);
            }
        }
        fts_close(file_system);
    }

    return 0;
}


int compare(const FTSENT** one, const FTSENT** two)
{
return (strcmp((*one)->fts_name, (*two)->fts_name));
}

我尝试使用 sscanf 和 fprintf 将子级写入缓冲区并使用 fwrite 尝试写入文件;他们都没有工作。我在 Google 上找到的内容也没有太大帮助,因此我们将不胜感激。

【问题讨论】:

    标签: c macos fuzzing


    【解决方案1】:

    您没有测试来自fopen() 的返回值,它是NULL,因为您错过了来自/Users/NahNig/music_paths 的第一个/。当你使用空指针时,程序会崩溃。

    【讨论】:

      猜你喜欢
      • 2012-10-24
      • 1970-01-01
      • 2013-04-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-24
      相关资源
      最近更新 更多