瀏覽代碼

Fix #29

Limit all xstrlcpy() calls by dest length.
Escape filenames in system(3) calls.
master
Arun Prakash Jana 8 年之前
父節點
當前提交
d1924756c7
沒有發現已知的金鑰在資料庫的簽署中 GPG 金鑰 ID: A75979F35C080412
共有 1 個檔案被更改,包括 18 行新增18 行删除
  1. +18
    -18
      nnn.c

+ 18
- 18
nnn.c 查看文件

@@ -1102,9 +1102,9 @@ show_stats(char* fpath, char* fname, struct stat *sb)
if (S_ISREG(sb->st_mode)) {
/* Show file(1) output */
strcpy(buf, "file -b \"");
xstrlcpy(buf + strlen(buf), fpath, strlen(fpath) + 1);
xstrlcpy(buf + strlen(buf), fpath, sizeof(buf) - strlen(buf));
strcat(buf, "\" 2>&1");
p = get_output(buf, PATH_MAX + 16);
p = get_output(buf, sizeof(buf));
if (p) {
dprintf(fd, "\n\n ");
while (*p) {
@@ -1139,12 +1139,12 @@ show_mediainfo(const char* fpath, int full)
if (get_output(buf, MAX_CMD_LEN) == NULL)
return -1;

strcpy(buf, "mediainfo \"");
xstrlcpy(buf + strlen(buf), fpath, strlen(fpath) + 1);
strcpy(buf, "mediainfo \'");
xstrlcpy(buf + strlen(buf), fpath, sizeof(buf) - strlen(buf));
if (full)
strcat(buf, "\" -f ");
strcat(buf, "\' -f ");
else
strcat(buf, "\" ");
strcat(buf, "\' ");
sprintf(buf + strlen(buf), "2>&1 | %s", xgetenv("PAGER", "less"));

return system(buf);
@@ -1569,9 +1569,9 @@ nochange:

/* If NNN_OPENER is set, use it */
if (opener) {
sprintf(cmd, "%s \"", opener);
xstrlcpy(cmd + strlen(cmd), newpath, strlen(newpath) + 1);
strcat(cmd, "\" > /dev/null 2>&1");
sprintf(cmd, "%s \'", opener);
xstrlcpy(cmd + strlen(cmd), newpath, sizeof(cmd) - strlen(cmd));
strcat(cmd, "\' > /dev/null 2>&1");
r = system(cmd);
continue;
}
@@ -1579,9 +1579,9 @@ nochange:
/* Play with nlay if identified */
mime = getmime(dents[cur].name);
if (mime) {
strcpy(cmd, "nlay \"");
xstrlcpy(cmd + strlen(cmd), newpath, strlen(newpath) + 1);
sprintf(cmd + strlen(cmd), "\" %s", mime);
strcpy(cmd, "nlay \'");
xstrlcpy(cmd + strlen(cmd), newpath, sizeof(cmd) - strlen(cmd));
sprintf(cmd + strlen(cmd), "\' %s", mime);
exitcurses();
r = system(cmd);
initcurses();
@@ -1590,9 +1590,9 @@ nochange:

/* If nlay doesn't handle it, open plain text
files with vi, then try NNN_FALLBACK_OPENER */
strcpy(cmd, "file -bi \"");
xstrlcpy(cmd + strlen(cmd), newpath, strlen(newpath) + 1);
strcat(cmd, "\"");
strcpy(cmd, "file -bi \'");
xstrlcpy(cmd + strlen(cmd), newpath, sizeof(cmd) - strlen(cmd));
strcat(cmd, "\'");
if (get_output(cmd, MAX_CMD_LEN) == NULL)
continue;

@@ -1603,9 +1603,9 @@ nochange:
initcurses();
continue;
} else if (fb_opener) {
sprintf(cmd, "%s \"", fb_opener);
xstrlcpy(cmd + strlen(cmd), newpath, strlen(newpath) + 1);
strcat(cmd, "\" > /dev/null 2>&1");
sprintf(cmd, "%s \'", fb_opener);
xstrlcpy(cmd + strlen(cmd), newpath, sizeof(cmd) - strlen(cmd));
strcat(cmd, "\' > /dev/null 2>&1");
r = system(cmd);
continue;
}


Loading…
取消
儲存