Skip to content

Commit 0b27ba6

Browse files
committed
fix(sysctl): error out when integer sysctl parse fails
Signed-off-by: Cong Wang <cwang@multikernel.io>
1 parent a89c87c commit 0b27ba6

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

src/userspace_codegen.ml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,7 +1297,10 @@ static inline void __ks_sysctl_%s_write(const char *v) {
12971297
}
12981298
__buf[__n] = 0;
12991299
%s __v = 0;
1300-
sscanf(__buf, "%s", &__v);
1300+
if (sscanf(__buf, "%s", &__v) != 1) {
1301+
fprintf(stderr, "sysctl read %%s: parse failed (unexpected format)\n", __ks_sysctl_%s_path);
1302+
return 0;
1303+
}
13011304
return __v;
13021305
}
13031306

@@ -1314,7 +1317,7 @@ static inline void __ks_sysctl_%s_write(%s v) {
13141317
if (__w < 0)
13151318
fprintf(stderr, "sysctl write %%s: %%s\n", __ks_sysctl_%s_path, strerror(__e));
13161319
}|}
1317-
c_type name name name name c_type fmt name c_type name name fmt name
1320+
c_type name name name name c_type fmt name name c_type name name fmt name
13181321
in
13191322
Some (path_const ^ "\n\n" ^ body)
13201323

0 commit comments

Comments
 (0)