1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
From 6daceb2f1f4d442ba04752aaa1cf43d554d5f646 Mon Sep 17 00:00:00 2001
From: Lucas De Marchi <lucas.demarchi@profusion.mobi>
Date: Sun, 8 Jan 2012 01:02:29 -0200
Subject: [PATCH] Replace NAME_MAX with PATH_MAX for module aliases
Module aliases can be bigger than NAME_MAX. So, replace with PATH_MAX
that is bigger enough to hold them.
Technically in some places NAME_MAX would be sufficient (those using
module names only), but they use functions that can be called with
alias. So increase the buffers in these cases to PATH_MAX too.
---
libkmod/libkmod-module.c | 10 +++++-----
libkmod/libkmod-util.c | 10 +++++-----
libkmod/libkmod-util.h | 6 +++---
tools/kmod-depmod.c | 4 ++--
4 files changed, 15 insertions(+), 15 deletions(-)
diff --git a/libkmod/libkmod-module.c b/libkmod/libkmod-module.c
index f2359a9..880bac5 100644
--- a/libkmod/libkmod-module.c
+++ b/libkmod/libkmod-module.c
@@ -185,7 +185,7 @@ KMOD_EXPORT int kmod_module_new_from_name(struct kmod_ctx *ctx,
{
struct kmod_module *m;
size_t namelen;
- char name_norm[NAME_MAX];
+ char name_norm[PATH_MAX];
char *namesep;
if (ctx == NULL || name == NULL || mod == NULL)
@@ -237,11 +237,11 @@ int kmod_module_new_from_alias(struct kmod_ctx *ctx, const char *alias,
const char *name, struct kmod_module **mod)
{
int err;
- char key[NAME_MAX];
+ char key[PATH_MAX];
size_t namelen = strlen(name);
size_t aliaslen = strlen(alias);
- if (namelen + aliaslen + 2 > NAME_MAX)
+ if (namelen + aliaslen + 2 > PATH_MAX)
return -ENAMETOOLONG;
memcpy(key, name, namelen);
@@ -283,7 +283,7 @@ KMOD_EXPORT int kmod_module_new_from_path(struct kmod_ctx *ctx,
struct kmod_module *m;
int err;
struct stat st;
- char name[NAME_MAX];
+ char name[PATH_MAX];
char *abspath;
size_t namelen;
@@ -434,7 +434,7 @@ KMOD_EXPORT int kmod_module_new_from_lookup(struct kmod_ctx *ctx,
struct kmod_list **list)
{
int err;
- char alias[NAME_MAX];
+ char alias[PATH_MAX];
if (ctx == NULL || given_alias == NULL)
return -ENOENT;
diff --git a/libkmod/libkmod-util.c b/libkmod/libkmod-util.c
index 75e2fea..344d94a 100644
--- a/libkmod/libkmod-util.c
+++ b/libkmod/libkmod-util.c
@@ -121,11 +121,11 @@ char *underscores(struct kmod_ctx *ctx, char *s)
return s;
}
-inline int alias_normalize(const char *alias, char buf[NAME_MAX], size_t *len)
+inline int alias_normalize(const char *alias, char buf[PATH_MAX], size_t *len)
{
size_t s;
- for (s = 0; s < NAME_MAX - 1; s++) {
+ for (s = 0; s < PATH_MAX - 1; s++) {
const char c = alias[s];
switch (c) {
case '-':
@@ -160,12 +160,12 @@ finish:
return 0;
}
-inline char *modname_normalize(const char *modname, char buf[NAME_MAX],
+inline char *modname_normalize(const char *modname, char buf[PATH_MAX],
size_t *len)
{
size_t s;
- for (s = 0; s < NAME_MAX - 1; s++) {
+ for (s = 0; s < PATH_MAX - 1; s++) {
const char c = modname[s];
if (c == '-')
buf[s] = '_';
@@ -183,7 +183,7 @@ inline char *modname_normalize(const char *modname, char buf[NAME_MAX],
return buf;
}
-char *path_to_modname(const char *path, char buf[NAME_MAX], size_t *len)
+char *path_to_modname(const char *path, char buf[PATH_MAX], size_t *len)
{
char *modname;
diff --git a/libkmod/libkmod-util.h b/libkmod/libkmod-util.h
index 3cd352c..e8ed5ad 100644
--- a/libkmod/libkmod-util.h
+++ b/libkmod/libkmod-util.h
@@ -20,9 +20,9 @@ int read_str_ulong(int fd, unsigned long *value, int base) __must_check __attrib
char *strchr_replace(char *s, int c, char r);
bool path_is_absolute(const char *p) __must_check __attribute__((nonnull(1)));
char *path_make_absolute_cwd(const char *p) __must_check __attribute__((nonnull(1)));
-int alias_normalize(const char *alias, char buf[NAME_MAX], size_t *len) __must_check __attribute__((nonnull(1,2)));
-char *modname_normalize(const char *modname, char buf[NAME_MAX], size_t *len) __attribute__((nonnull(1, 2)));
-char *path_to_modname(const char *path, char buf[NAME_MAX], size_t *len) __attribute__((nonnull(2)));
+int alias_normalize(const char *alias, char buf[PATH_MAX], size_t *len) __must_check __attribute__((nonnull(1,2)));
+char *modname_normalize(const char *modname, char buf[PATH_MAX], size_t *len) __attribute__((nonnull(1, 2)));
+char *path_to_modname(const char *path, char buf[PATH_MAX], size_t *len) __attribute__((nonnull(2)));
unsigned long long ts_usec(const struct timespec *ts);
#endif
diff --git a/tools/kmod-depmod.c b/tools/kmod-depmod.c
index 70c397c..4726522 100644
--- a/tools/kmod-depmod.c
+++ b/tools/kmod-depmod.c
@@ -1249,7 +1249,7 @@ static int depmod_modules_search_file(struct depmod *depmod, size_t baselen, siz
struct kmod_module *kmod;
struct mod *mod;
const char *relpath;
- char modname[NAME_MAX];
+ char modname[PATH_MAX];
const struct kmod_ext *eitr;
size_t modnamelen;
uint8_t matches = 0;
@@ -2101,7 +2101,7 @@ static int output_builtin_bin(struct depmod *depmod, FILE *out)
{
FILE *in;
struct index_node *idx;
- char infile[PATH_MAX], line[PATH_MAX], modname[NAME_MAX];
+ char infile[PATH_MAX], line[PATH_MAX], modname[PATH_MAX];
if (out == stdout)
return 0;
--
1.7.8.1
|