From f56384040472bbb428daea122330746a7ca09569 Mon Sep 17 00:00:00 2001 From: Enrico Scholz Date: Sat, 29 Oct 2005 15:08:38 +0000 Subject: [PATCH] - revert a previous vc_add_dlimit() when vc_set_dlimit() fails - added some basic sanity checks for the parameters given on the CLI [both reported by Kevin Pendleton; https://savannah.nongnu.org/bugs/?func=detailitem&item_id=14026] git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/trunk@2216 94cd875c-1c1d-0410-91d2-eb244daf1a30 --- util-vserver/src/vdlimit.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/util-vserver/src/vdlimit.c b/util-vserver/src/vdlimit.c index b0c8fd8..db8bd88 100644 --- a/util-vserver/src/vdlimit.c +++ b/util-vserver/src/vdlimit.c @@ -85,14 +85,24 @@ showVersion() static void setDlimit(char const *filename, xid_t xid, uint32_t flags, struct vc_ctx_dlimit const *limit) { + bool was_added = false; + if (vc_get_dlimit(filename, xid, flags, 0) == -1) { if (vc_add_dlimit(filename, xid, flags) == -1) { perror(ENSC_WRAPPERS_PREFIX "vc_add_dlimit()"); exit(wrapper_exit_code); } + + was_added = true; } + if (vc_set_dlimit(filename, xid, flags, limit) == -1) { perror(ENSC_WRAPPERS_PREFIX "vc_set_dlimit()"); + + if (was_added && + vc_rem_dlimit(filename, xid, flags)==-1) + perror(ENSC_WRAPPERS_PREFIX "vc_rem_dlimit()"); + exit(wrapper_exit_code); } } @@ -200,6 +210,14 @@ setDLimitField(struct vc_ctx_dlimit *dst, char const *opt) return true; } +bool +isHigherLimit(uint_least32_t lhs, uint_least32_t rhs) +{ + if (lhs==VC_CDLIM_KEEP || rhs==VC_CDLIM_KEEP) return false; + + return lhs > rhs; +} + int main(int argc, char *argv[]) { bool do_set = false; @@ -261,6 +279,10 @@ int main(int argc, char *argv[]) WRITE_MSG(2, "No mount point specified; try '--help' for more information\n"); else if (xid==VC_NOCTX) WRITE_MSG(2, "No xid specified; try '--help' for more information\n"); + else if (isHigherLimit(limit.space_used, limit.space_total)) + WRITE_MSG(2, "invalid parameters: 'space_used' is larger than 'space_total'\n"); + else if (isHigherLimit(limit.inodes_used, limit.inodes_total)) + WRITE_MSG(2, "invalid parameters: 'inodes_used' is larger than 'inodes_total'\n"); else { for (; optind < argc; ++optind) { if (do_set) setDlimit(argv[optind], xid, flags, &limit); -- 1.8.1.5