]> granicus.if.org Git - postgresql/commitdiff
Protect pg_stat_reset_shared() against NULL input
authorMagnus Hagander <magnus@hagander.net>
Wed, 29 Jun 2011 17:35:11 +0000 (19:35 +0200)
committerMagnus Hagander <magnus@hagander.net>
Wed, 29 Jun 2011 17:36:51 +0000 (19:36 +0200)
Per bug #6082, reported by Steve Haslam

src/backend/utils/adt/pgstatfuncs.c

index 12dbff4c9a943b37875a76a92d36346c21f53372..4d07bdd24bde7e5dbe4bcb26871bf894920b1c33 100644 (file)
@@ -1537,9 +1537,17 @@ pg_stat_reset(PG_FUNCTION_ARGS)
 Datum
 pg_stat_reset_shared(PG_FUNCTION_ARGS)
 {
-       char       *target = text_to_cstring(PG_GETARG_TEXT_PP(0));
-
-       pgstat_reset_shared_counters(target);
+       if (PG_ARGISNULL(0))
+               /*
+                * Same error message as in pgstat_reset_shared_counters(),
+                * to keep translations the same.
+                */
+               ereport(ERROR,
+                               (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+                                errmsg("unrecognized reset target: \"%s\"", "null"),
+                                errhint("Target must be \"bgwriter\".")));
+
+       pgstat_reset_shared_counters(text_to_cstring(PG_GETARG_TEXT_PP(0)));
 
        PG_RETURN_VOID();
 }