Fossil SCM
Potential fix for [746a5106f92287036c12c945d9d7358a1263301e].
Commit
d6a4ab227644cadb977c3e5e0b8d31bbe5c560e4041dd833405d33890fafa276
Parent
926a27c63b03cce…
3 files changed
+21
+13
+9
-4
M
src/th.c
+21
| --- src/th.c | ||
| +++ src/th.c | ||
| @@ -1269,10 +1269,31 @@ | ||
| 1269 | 1269 | return TH_ERROR; |
| 1270 | 1270 | } |
| 1271 | 1271 | |
| 1272 | 1272 | return Th_SetResult(interp, pValue->zData, pValue->nData); |
| 1273 | 1273 | } |
| 1274 | + | |
| 1275 | +/* | |
| 1276 | +** If interp has a variable with the given name, its value is returned | |
| 1277 | +** and its length is returned via *nOut if nOut is not NULL. If | |
| 1278 | +** interp has no such var then NULL is returned without setting any | |
| 1279 | +** error state and *nOut, if not NULL, is set to -1. The returned value | |
| 1280 | +** is owned by the interpreter and may be invalidated the next time | |
| 1281 | +** the interpreter is modified. | |
| 1282 | +*/ | |
| 1283 | +const char * Th_MaybeGetVar(Th_Interp *interp, const char *zVarName, | |
| 1284 | + int *nOut){ | |
| 1285 | + Th_Variable *pValue; | |
| 1286 | + | |
| 1287 | + pValue = thFindValue(interp, zVarName, -1, 0, 0, 1, 0); | |
| 1288 | + if( !pValue || !pValue->zData ){ | |
| 1289 | + if( nOut!=0 ) *nOut = -1; | |
| 1290 | + return NULL; | |
| 1291 | + } | |
| 1292 | + if( nOut!=0 ) *nOut = pValue->nData; | |
| 1293 | + return pValue->zData; | |
| 1294 | +} | |
| 1274 | 1295 | |
| 1275 | 1296 | /* |
| 1276 | 1297 | ** Return true if variable (zVar, nVar) exists. |
| 1277 | 1298 | */ |
| 1278 | 1299 | int Th_ExistsVar(Th_Interp *interp, const char *zVar, int nVar){ |
| 1279 | 1300 |
| --- src/th.c | |
| +++ src/th.c | |
| @@ -1269,10 +1269,31 @@ | |
| 1269 | return TH_ERROR; |
| 1270 | } |
| 1271 | |
| 1272 | return Th_SetResult(interp, pValue->zData, pValue->nData); |
| 1273 | } |
| 1274 | |
| 1275 | /* |
| 1276 | ** Return true if variable (zVar, nVar) exists. |
| 1277 | */ |
| 1278 | int Th_ExistsVar(Th_Interp *interp, const char *zVar, int nVar){ |
| 1279 |
| --- src/th.c | |
| +++ src/th.c | |
| @@ -1269,10 +1269,31 @@ | |
| 1269 | return TH_ERROR; |
| 1270 | } |
| 1271 | |
| 1272 | return Th_SetResult(interp, pValue->zData, pValue->nData); |
| 1273 | } |
| 1274 | |
| 1275 | /* |
| 1276 | ** If interp has a variable with the given name, its value is returned |
| 1277 | ** and its length is returned via *nOut if nOut is not NULL. If |
| 1278 | ** interp has no such var then NULL is returned without setting any |
| 1279 | ** error state and *nOut, if not NULL, is set to -1. The returned value |
| 1280 | ** is owned by the interpreter and may be invalidated the next time |
| 1281 | ** the interpreter is modified. |
| 1282 | */ |
| 1283 | const char * Th_MaybeGetVar(Th_Interp *interp, const char *zVarName, |
| 1284 | int *nOut){ |
| 1285 | Th_Variable *pValue; |
| 1286 | |
| 1287 | pValue = thFindValue(interp, zVarName, -1, 0, 0, 1, 0); |
| 1288 | if( !pValue || !pValue->zData ){ |
| 1289 | if( nOut!=0 ) *nOut = -1; |
| 1290 | return NULL; |
| 1291 | } |
| 1292 | if( nOut!=0 ) *nOut = pValue->nData; |
| 1293 | return pValue->zData; |
| 1294 | } |
| 1295 | |
| 1296 | /* |
| 1297 | ** Return true if variable (zVar, nVar) exists. |
| 1298 | */ |
| 1299 | int Th_ExistsVar(Th_Interp *interp, const char *zVar, int nVar){ |
| 1300 |
M
src/th.h
+13
| --- src/th.h | ||
| +++ src/th.h | ||
| @@ -56,10 +56,23 @@ | ||
| 56 | 56 | int Th_GetVar(Th_Interp *, const char *, int); |
| 57 | 57 | int Th_SetVar(Th_Interp *, const char *, int, const char *, int); |
| 58 | 58 | int Th_LinkVar(Th_Interp *, const char *, int, int, const char *, int); |
| 59 | 59 | int Th_UnsetVar(Th_Interp *, const char *, int); |
| 60 | 60 | |
| 61 | +/* | |
| 62 | +** If interp has a variable with the given name, its value is returned | |
| 63 | +** and its length is returned via *nOut if nOut is not NULL. If | |
| 64 | +** interp has no such var then NULL is returned without setting any | |
| 65 | +** error state and *nOut, if not NULL, is set to 0. The returned value | |
| 66 | +** is owned by the interpreter and may be invalidated the next time | |
| 67 | +** the interpreter is modified. | |
| 68 | +** | |
| 69 | +** zVarName must be NUL-terminated. | |
| 70 | +*/ | |
| 71 | +const char * Th_MaybeGetVar(Th_Interp *interp, const char *zVarName, | |
| 72 | + int *nOut); | |
| 73 | + | |
| 61 | 74 | typedef int (*Th_CommandProc)(Th_Interp *, void *, int, const char **, int *); |
| 62 | 75 | |
| 63 | 76 | /* |
| 64 | 77 | ** Register new commands. |
| 65 | 78 | */ |
| 66 | 79 |
| --- src/th.h | |
| +++ src/th.h | |
| @@ -56,10 +56,23 @@ | |
| 56 | int Th_GetVar(Th_Interp *, const char *, int); |
| 57 | int Th_SetVar(Th_Interp *, const char *, int, const char *, int); |
| 58 | int Th_LinkVar(Th_Interp *, const char *, int, int, const char *, int); |
| 59 | int Th_UnsetVar(Th_Interp *, const char *, int); |
| 60 | |
| 61 | typedef int (*Th_CommandProc)(Th_Interp *, void *, int, const char **, int *); |
| 62 | |
| 63 | /* |
| 64 | ** Register new commands. |
| 65 | */ |
| 66 |
| --- src/th.h | |
| +++ src/th.h | |
| @@ -56,10 +56,23 @@ | |
| 56 | int Th_GetVar(Th_Interp *, const char *, int); |
| 57 | int Th_SetVar(Th_Interp *, const char *, int, const char *, int); |
| 58 | int Th_LinkVar(Th_Interp *, const char *, int, int, const char *, int); |
| 59 | int Th_UnsetVar(Th_Interp *, const char *, int); |
| 60 | |
| 61 | /* |
| 62 | ** If interp has a variable with the given name, its value is returned |
| 63 | ** and its length is returned via *nOut if nOut is not NULL. If |
| 64 | ** interp has no such var then NULL is returned without setting any |
| 65 | ** error state and *nOut, if not NULL, is set to 0. The returned value |
| 66 | ** is owned by the interpreter and may be invalidated the next time |
| 67 | ** the interpreter is modified. |
| 68 | ** |
| 69 | ** zVarName must be NUL-terminated. |
| 70 | */ |
| 71 | const char * Th_MaybeGetVar(Th_Interp *interp, const char *zVarName, |
| 72 | int *nOut); |
| 73 | |
| 74 | typedef int (*Th_CommandProc)(Th_Interp *, void *, int, const char **, int *); |
| 75 | |
| 76 | /* |
| 77 | ** Register new commands. |
| 78 | */ |
| 79 |
+9
-4
| --- src/tkt.c | ||
| +++ src/tkt.c | ||
| @@ -997,11 +997,11 @@ | ||
| 997 | 997 | ** when you press submit - it just prints the ticket artifact at the |
| 998 | 998 | ** top of the screen. |
| 999 | 999 | */ |
| 1000 | 1000 | void tktnew_page(void){ |
| 1001 | 1001 | const char *zScript; |
| 1002 | - char *zEmail = 0, *zNewUuid = 0; | |
| 1002 | + char *zNewUuid = 0; | |
| 1003 | 1003 | int uid; |
| 1004 | 1004 | |
| 1005 | 1005 | login_check_credentials(); |
| 1006 | 1006 | if( !g.perm.NewTkt ){ login_needed(g.anon.NewTkt); return; } |
| 1007 | 1007 | if( P("cancel") ){ |
| @@ -1021,16 +1021,21 @@ | ||
| 1021 | 1021 | if( P("date_override") && g.perm.Setup ){ |
| 1022 | 1022 | @ <input type="hidden" name="date_override" value="%h(P("date_override"))"> |
| 1023 | 1023 | } |
| 1024 | 1024 | zScript = ticket_newpage_code(); |
| 1025 | 1025 | if( g.zLogin && g.zLogin[0] ){ |
| 1026 | - uid = db_int(0, "SELECT uid FROM user WHERE login=%Q", g.zLogin); | |
| 1026 | + int nEmail = 0; | |
| 1027 | + (void)Th_MaybeGetVar(g.interp, "private_contact", &nEmail); | |
| 1028 | + uid = nEmail>0 | |
| 1029 | + ? 0 : db_int(0, "SELECT uid FROM user WHERE login=%Q", g.zLogin); | |
| 1027 | 1030 | if( uid ){ |
| 1028 | - zEmail = db_text(0, "SELECT find_emailaddr(info) FROM user WHERE uid=%d", | |
| 1029 | - uid); | |
| 1031 | + char * zEmail = | |
| 1032 | + db_text(0, "SELECT find_emailaddr(info) FROM user WHERE uid=%d", | |
| 1033 | + uid); | |
| 1030 | 1034 | if( zEmail ){ |
| 1031 | 1035 | Th_Store("private_contact", zEmail); |
| 1036 | + fossil_free(zEmail); | |
| 1032 | 1037 | } |
| 1033 | 1038 | } |
| 1034 | 1039 | } |
| 1035 | 1040 | Th_Store("login", login_name()); |
| 1036 | 1041 | Th_Store("date", db_text(0, "SELECT datetime('now')")); |
| 1037 | 1042 |
| --- src/tkt.c | |
| +++ src/tkt.c | |
| @@ -997,11 +997,11 @@ | |
| 997 | ** when you press submit - it just prints the ticket artifact at the |
| 998 | ** top of the screen. |
| 999 | */ |
| 1000 | void tktnew_page(void){ |
| 1001 | const char *zScript; |
| 1002 | char *zEmail = 0, *zNewUuid = 0; |
| 1003 | int uid; |
| 1004 | |
| 1005 | login_check_credentials(); |
| 1006 | if( !g.perm.NewTkt ){ login_needed(g.anon.NewTkt); return; } |
| 1007 | if( P("cancel") ){ |
| @@ -1021,16 +1021,21 @@ | |
| 1021 | if( P("date_override") && g.perm.Setup ){ |
| 1022 | @ <input type="hidden" name="date_override" value="%h(P("date_override"))"> |
| 1023 | } |
| 1024 | zScript = ticket_newpage_code(); |
| 1025 | if( g.zLogin && g.zLogin[0] ){ |
| 1026 | uid = db_int(0, "SELECT uid FROM user WHERE login=%Q", g.zLogin); |
| 1027 | if( uid ){ |
| 1028 | zEmail = db_text(0, "SELECT find_emailaddr(info) FROM user WHERE uid=%d", |
| 1029 | uid); |
| 1030 | if( zEmail ){ |
| 1031 | Th_Store("private_contact", zEmail); |
| 1032 | } |
| 1033 | } |
| 1034 | } |
| 1035 | Th_Store("login", login_name()); |
| 1036 | Th_Store("date", db_text(0, "SELECT datetime('now')")); |
| 1037 |
| --- src/tkt.c | |
| +++ src/tkt.c | |
| @@ -997,11 +997,11 @@ | |
| 997 | ** when you press submit - it just prints the ticket artifact at the |
| 998 | ** top of the screen. |
| 999 | */ |
| 1000 | void tktnew_page(void){ |
| 1001 | const char *zScript; |
| 1002 | char *zNewUuid = 0; |
| 1003 | int uid; |
| 1004 | |
| 1005 | login_check_credentials(); |
| 1006 | if( !g.perm.NewTkt ){ login_needed(g.anon.NewTkt); return; } |
| 1007 | if( P("cancel") ){ |
| @@ -1021,16 +1021,21 @@ | |
| 1021 | if( P("date_override") && g.perm.Setup ){ |
| 1022 | @ <input type="hidden" name="date_override" value="%h(P("date_override"))"> |
| 1023 | } |
| 1024 | zScript = ticket_newpage_code(); |
| 1025 | if( g.zLogin && g.zLogin[0] ){ |
| 1026 | int nEmail = 0; |
| 1027 | (void)Th_MaybeGetVar(g.interp, "private_contact", &nEmail); |
| 1028 | uid = nEmail>0 |
| 1029 | ? 0 : db_int(0, "SELECT uid FROM user WHERE login=%Q", g.zLogin); |
| 1030 | if( uid ){ |
| 1031 | char * zEmail = |
| 1032 | db_text(0, "SELECT find_emailaddr(info) FROM user WHERE uid=%d", |
| 1033 | uid); |
| 1034 | if( zEmail ){ |
| 1035 | Th_Store("private_contact", zEmail); |
| 1036 | fossil_free(zEmail); |
| 1037 | } |
| 1038 | } |
| 1039 | } |
| 1040 | Th_Store("login", login_name()); |
| 1041 | Th_Store("date", db_text(0, "SELECT datetime('now')")); |
| 1042 |